diff --git a/lago_python_client/client.py b/lago_python_client/client.py index a35544fd..43151cf4 100644 --- a/lago_python_client/client.py +++ b/lago_python_client/client.py @@ -13,7 +13,7 @@ from .invoiced_usages.clients import InvoicedUsageClient from .mrrs.clients import MrrClient from .organizations.clients import OrganizationClient -from .outstanding_invoices.clients import OutstandingInvoiceClient +from .invoice_collections.clients import InvoiceCollectionClient from .plans.clients import PlanClient from .subscriptions.clients import SubscriptionClient from .taxes.clients import TaxClient @@ -96,8 +96,8 @@ def organizations(self) -> OrganizationClient: return OrganizationClient(self.base_api_url, self.api_key) @callable_cached_property - def outstanding_invoices(self) -> OutstandingInvoiceClient: - return OutstandingInvoiceClient(self.base_api_url, self.api_key) + def invoice_collections(self) -> InvoiceCollectionClient: + return InvoiceCollectionClient(self.base_api_url, self.api_key) @callable_cached_property def plans(self) -> PlanClient: diff --git a/lago_python_client/outstanding_invoices/__init__.py b/lago_python_client/invoice_collections/__init__.py similarity index 100% rename from lago_python_client/outstanding_invoices/__init__.py rename to lago_python_client/invoice_collections/__init__.py diff --git a/lago_python_client/outstanding_invoices/clients.py b/lago_python_client/invoice_collections/clients.py similarity index 70% rename from lago_python_client/outstanding_invoices/clients.py rename to lago_python_client/invoice_collections/clients.py index 6326378a..dc974d6f 100644 --- a/lago_python_client/outstanding_invoices/clients.py +++ b/lago_python_client/invoice_collections/clients.py @@ -3,7 +3,7 @@ from ..base_client import BaseClient from ..mixins import FindAllCommandMixin -from ..models.outstanding_invoice import OutstandingInvoiceResponse +from ..models.invoice_collection import InvoiceCollectionResponse from ..services.request import make_headers, make_url, send_get_request from ..services.response import get_response_data, prepare_index_response, Response @@ -13,19 +13,19 @@ from typing import Mapping -class OutstandingInvoiceClient( - FindAllCommandMixin[OutstandingInvoiceResponse], +class InvoiceCollectionClient( + FindAllCommandMixin[InvoiceCollectionResponse], BaseClient, ): - API_RESOURCE: ClassVar[str] = 'outstanding_invoices' - RESPONSE_MODEL: ClassVar[Type[OutstandingInvoiceResponse]] = OutstandingInvoiceResponse - ROOT_NAME: ClassVar[str] = 'outstanding_invoice' + API_RESOURCE: ClassVar[str] = 'invoice_collections' + RESPONSE_MODEL: ClassVar[Type[InvoiceCollectionResponse]] = InvoiceCollectionResponse + ROOT_NAME: ClassVar[str] = 'invoice_collection' def find_all(self, options: Mapping[str, Union[int, str]] = {}) -> Mapping[str, Any]: api_response: Response = send_get_request( url=make_url( origin=self.base_url, - path_parts=('analytics', self.API_RESOURCE), + path_parts=('analytics', 'invoice_collection'), query_pairs=options, ), headers=make_headers(api_key=self.api_key), diff --git a/lago_python_client/models/outstanding_invoice.py b/lago_python_client/models/invoice_collection.py similarity index 58% rename from lago_python_client/models/outstanding_invoice.py rename to lago_python_client/models/invoice_collection.py index c07d47fe..eb50be07 100644 --- a/lago_python_client/models/outstanding_invoice.py +++ b/lago_python_client/models/invoice_collection.py @@ -3,7 +3,7 @@ from ..base_model import BaseModel, BaseResponseModel -class OutstandingInvoiceResponse(BaseResponseModel): +class InvoiceCollectionResponse(BaseResponseModel): amount_cents: int currency: Optional[str] month: str @@ -11,5 +11,5 @@ class OutstandingInvoiceResponse(BaseResponseModel): payment_status: Optional[str] -class OutstandingInvoicesResponse(BaseResponseModel): - __root__: List[OutstandingInvoiceResponse] +class InvoiceCollectionsResponse(BaseResponseModel): + __root__: List[InvoiceCollectionResponse] diff --git a/tests/fixtures/outstanding_invoice_index.json b/tests/fixtures/invoice_collection_index.json similarity index 92% rename from tests/fixtures/outstanding_invoice_index.json rename to tests/fixtures/invoice_collection_index.json index 7b6566b1..4c00f6bb 100644 --- a/tests/fixtures/outstanding_invoice_index.json +++ b/tests/fixtures/invoice_collection_index.json @@ -1,5 +1,5 @@ { - "outstanding_invoices": [ + "invoice_collections": [ { "month": "2023-11-01T00:00:00.000Z", "amount_cents": 100, diff --git a/tests/test_invoice_collection_client.py b/tests/test_invoice_collection_client.py new file mode 100644 index 00000000..b218b2a5 --- /dev/null +++ b/tests/test_invoice_collection_client.py @@ -0,0 +1,29 @@ +import os + +import pytest +from pytest_httpx import HTTPXMock + +from lago_python_client.client import Client +from lago_python_client.exceptions import LagoApiError +from lago_python_client.models.invoice_collection import InvoiceCollectionResponse + + +def mock_collection_response(): + current_dir = os.path.dirname(os.path.abspath(__file__)) + data_path = os.path.join(current_dir, 'fixtures/invoice_collection_index.json') + + with open(data_path, 'rb') as invoice_collections_response: + return invoice_collections_response.read() + + +def test_valid_find_all_invoice_collections_request(httpx_mock: HTTPXMock): + client = Client(api_key='886fe239-927d-4072-ab72-6dd345e8dd0d') + + httpx_mock.add_response(method='GET', url='https://api.getlago.com/api/v1/analytics/invoice_collection', content=mock_collection_response()) + response = client.invoice_collections.find_all() + + assert response['invoice_collections'][0].currency == 'EUR' + assert response['invoice_collections'][0].amount_cents == 100 + assert response['invoice_collections'][0].month == '2023-11-01T00:00:00.000Z' + assert response['invoice_collections'][0].invoices_count == 10 + assert response['invoice_collections'][0].payment_status == 'pending' diff --git a/tests/test_outstanding_invoices_client.py b/tests/test_outstanding_invoices_client.py deleted file mode 100644 index 102fc740..00000000 --- a/tests/test_outstanding_invoices_client.py +++ /dev/null @@ -1,29 +0,0 @@ -import os - -import pytest -from pytest_httpx import HTTPXMock - -from lago_python_client.client import Client -from lago_python_client.exceptions import LagoApiError -from lago_python_client.models.outstanding_invoice import OutstandingInvoiceResponse - - -def mock_collection_response(): - current_dir = os.path.dirname(os.path.abspath(__file__)) - data_path = os.path.join(current_dir, 'fixtures/outstanding_invoice_index.json') - - with open(data_path, 'rb') as outstanding_invoices_response: - return outstanding_invoices_response.read() - - -def test_valid_find_all_outstanding_invoices_request(httpx_mock: HTTPXMock): - client = Client(api_key='886fe239-927d-4072-ab72-6dd345e8dd0d') - - httpx_mock.add_response(method='GET', url='https://api.getlago.com/api/v1/analytics/outstanding_invoices', content=mock_collection_response()) - response = client.outstanding_invoices.find_all() - - assert response['outstanding_invoices'][0].currency == 'EUR' - assert response['outstanding_invoices'][0].amount_cents == 100 - assert response['outstanding_invoices'][0].month == '2023-11-01T00:00:00.000Z' - assert response['outstanding_invoices'][0].invoices_count == 10 - assert response['outstanding_invoices'][0].payment_status == 'pending'