From 6514944290d1c7b425767e5a8d38caf91e566ebe Mon Sep 17 00:00:00 2001 From: Vincent Pochet Date: Thu, 21 Sep 2023 09:27:14 +0200 Subject: [PATCH] feat(weighted-sum): Add weighted sum fields to billable metric (#192) * feat(weighted-sum): Add weighted sum fields to billable metric * fix(coupon): Add missing coupons#terminated_at --- lago_python_client/models/billable_metric.py | 2 ++ lago_python_client/models/event.py | 6 +++--- tests/fixtures/billable_metric.json | 1 + tests/fixtures/billable_metric_index.json | 2 ++ tests/test_billable_metric_client.py | 3 ++- tests/test_event_client.py | 11 +++++++++++ 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lago_python_client/models/billable_metric.py b/lago_python_client/models/billable_metric.py index dd801077..657210d7 100644 --- a/lago_python_client/models/billable_metric.py +++ b/lago_python_client/models/billable_metric.py @@ -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] @@ -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 diff --git a/lago_python_client/models/event.py b/lago_python_client/models/event.py index a418db17..7287743e 100644 --- a/lago_python_client/models/event.py +++ b/lago_python_client/models/event.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Optional +from typing import Any, Dict, List, Optional, Union from pydantic import BaseModel @@ -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]] @@ -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]] diff --git a/tests/fixtures/billable_metric.json b/tests/fixtures/billable_metric.json index f2a9ccd7..eb32d129 100644 --- a/tests/fixtures/billable_metric.json +++ b/tests/fixtures/billable_metric.json @@ -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", diff --git a/tests/fixtures/billable_metric_index.json b/tests/fixtures/billable_metric_index.json index 9e308db4..617b8fa9 100644 --- a/tests/fixtures/billable_metric_index.json +++ b/tests/fixtures/billable_metric_index.json @@ -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", @@ -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", diff --git a/tests/test_billable_metric_client.py b/tests/test_billable_metric_client.py index dc998854..3a4e238e 100644 --- a/tests/test_billable_metric_client.py +++ b/tests/test_billable_metric_client.py @@ -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' ) diff --git a/tests/test_event_client.py b/tests/test_event_client.py index 019f17a9..29144797 100644 --- a/tests/test_event_client.py +++ b/tests/test_event_client.py @@ -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') @@ -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')