Skip to content

Commit

Permalink
feat(weighted-sum): Add weighted sum fields to billable metric (#192)
Browse files Browse the repository at this point in the history
* feat(weighted-sum): Add weighted sum fields to billable metric

* fix(coupon): Add missing coupons#terminated_at
  • Loading branch information
vincent-pochet authored Sep 21, 2023
1 parent 82186b8 commit 6514944
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lago_python_client/models/billable_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class BillableMetric(BaseModel):
description: Optional[str]
recurring: Optional[bool]
aggregation_type: Optional[str]
weighted_interval: Optional[str]
field_name: Optional[str]
group: Optional[BillableMetricGroup]

Expand All @@ -27,6 +28,7 @@ class BillableMetricResponse(BaseResponseModel):
description: Optional[str]
recurring: Optional[bool]
aggregation_type: Optional[str]
weighted_interval: Optional[str]
field_name: Optional[str]
created_at: str
group: BillableMetricGroup
Expand Down
6 changes: 3 additions & 3 deletions lago_python_client/models/event.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, Union

from pydantic import BaseModel

Expand All @@ -10,7 +10,7 @@ class Event(BaseModel):
external_customer_id: Optional[str]
external_subscription_id: Optional[str]
code: str
timestamp: Optional[int]
timestamp: Optional[Union[int, str]]
properties: Optional[Dict[str, Any]]


Expand All @@ -19,7 +19,7 @@ class BatchEvent(BaseModel):
external_customer_id: Optional[str]
external_subscription_ids: List[str]
code: str
timestamp: Optional[int]
timestamp: Optional[Union[int, str]]
properties: Optional[Dict[str, Any]]


Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/billable_metric.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"code": "bm_code",
"description": "description",
"aggregation_type": "sum_agg",
"weighted_interval": null,
"recurring": false,
"field_name": "amount_sum",
"created_at": "2022-04-29T08:59:51Z",
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/billable_metric_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"code": "bm_code",
"description": "description",
"aggregation_type": "sum_agg",
"weighted_interval": null,
"recurring": false,
"field_name": "amount_sum",
"created_at": "2022-04-29T08:59:51Z",
Expand All @@ -20,6 +21,7 @@
"code": "bm2_code",
"description": "description2",
"aggregation_type": "sum_agg",
"weighted_interval": null,
"recurring": false,
"field_name": "amount_sum",
"created_at": "2022-04-30T08:59:51Z",
Expand Down
3 changes: 2 additions & 1 deletion tests/test_billable_metric_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def billable_metric_object():
aggregation_type='sum_agg',
field_name='amount_sum',
recurring=False,
group=group()
group=group(),
weighted_interval='seconds'
)


Expand Down
11 changes: 11 additions & 0 deletions tests/test_event_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def create_event():
return Event(external_customer_id='5eb02857-a71e-4ea2-bcf9-57d8885990ba', code='123', transaction_id='123')


def create_event_with_string_timestamp():
return Event(external_customer_id='5eb02857-a71e-4ea2-bcf9-57d8885990ba', code='123', transaction_id='123', timestamp='1651240791.123')


def create_batch_event():
return BatchEvent(external_subscription_ids=['88u02857-a71e-4ea2-bcf9-57d8885990ba'], code='123', transaction_id='123')

Expand All @@ -38,6 +42,13 @@ def test_valid_create_events_request(httpx_mock: HTTPXMock):
client.events.create(create_event()) # Any response means success, any exception - failure


def test_valid_create_events_request_with_string_timestamp(httpx_mock: HTTPXMock):
client = Client(api_key='886fe239-927d-4072-ab72-6dd345e8dd0d')

httpx_mock.add_response(method='POST', url='https://api.getlago.com/api/v1/events', content=b'')
client.events.create(create_event_with_string_timestamp()) # Any response means success, any exception - failure


def test_invalid_create_events_request(httpx_mock: HTTPXMock):
client = Client(api_key='invalid')

Expand Down

0 comments on commit 6514944

Please sign in to comment.