Skip to content

Commit

Permalink
misc(analytics): Rename outstanding invoices to invoice collection (#214
Browse files Browse the repository at this point in the history
)
ivannovosad authored Nov 28, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent f0b6e86 commit 9232a90
Showing 7 changed files with 43 additions and 43 deletions.
6 changes: 3 additions & 3 deletions lago_python_client/client.py
Original file line number Diff line number Diff line change
@@ -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:
Original file line number Diff line number Diff line change
@@ -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),
Original file line number Diff line number Diff line change
@@ -3,13 +3,13 @@
from ..base_model import BaseModel, BaseResponseModel


class OutstandingInvoiceResponse(BaseResponseModel):
class InvoiceCollectionResponse(BaseResponseModel):
amount_cents: int
currency: Optional[str]
month: str
invoices_count: int
payment_status: Optional[str]


class OutstandingInvoicesResponse(BaseResponseModel):
__root__: List[OutstandingInvoiceResponse]
class InvoiceCollectionsResponse(BaseResponseModel):
__root__: List[InvoiceCollectionResponse]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"outstanding_invoices": [
"invoice_collections": [
{
"month": "2023-11-01T00:00:00.000Z",
"amount_cents": 100,
29 changes: 29 additions & 0 deletions tests/test_invoice_collection_client.py
Original file line number Diff line number Diff line change
@@ -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'
29 changes: 0 additions & 29 deletions tests/test_outstanding_invoices_client.py

This file was deleted.

0 comments on commit 9232a90

Please sign in to comment.