diff --git a/mpt_api_client/resources/billing/custom_ledger_charges.py b/mpt_api_client/resources/billing/custom_ledger_charges.py new file mode 100644 index 0000000..b7b8ce5 --- /dev/null +++ b/mpt_api_client/resources/billing/custom_ledger_charges.py @@ -0,0 +1,28 @@ +from mpt_api_client.http import AsyncService, Service +from mpt_api_client.models import Model + + +class CustomLedgerCharge(Model): + """Custom Ledger Charge resource.""" + + +class CustomLedgerChargesServiceConfig: + """Custom Ledger Charges service configuration.""" + + _endpoint = "/public/v1/billing/custom-ledgers/{custom_ledger_id}/charges" + _model_class = CustomLedgerCharge + _collection_key = "data" + + +class CustomLedgerChargesService( + Service[CustomLedgerCharge], + CustomLedgerChargesServiceConfig, +): + """Custom Ledger Charges service.""" + + +class AsyncCustomLedgerChargesService( + AsyncService[CustomLedgerCharge], + CustomLedgerChargesServiceConfig, +): + """Async Custom Ledger Charges service.""" diff --git a/mpt_api_client/resources/billing/custom_ledgers.py b/mpt_api_client/resources/billing/custom_ledgers.py index 405ecf6..cd504bb 100644 --- a/mpt_api_client/resources/billing/custom_ledgers.py +++ b/mpt_api_client/resources/billing/custom_ledgers.py @@ -8,6 +8,10 @@ UpdateMixin, ) from mpt_api_client.models import Model +from mpt_api_client.resources.billing.custom_ledger_charges import ( + AsyncCustomLedgerChargesService, + CustomLedgerChargesService, +) from mpt_api_client.resources.billing.mixins import AcceptableMixin, AsyncAcceptableMixin @@ -33,6 +37,13 @@ class CustomLedgersService( ): """Custom Ledgers service.""" + def charges(self, custom_ledger_id: str) -> CustomLedgerChargesService: + """Return custom ledger charges service.""" + return CustomLedgerChargesService( + http_client=self.http_client, + endpoint_params={"custom_ledger_id": custom_ledger_id}, + ) + class AsyncCustomLedgersService( AsyncCreateMixin[CustomLedger], @@ -43,3 +54,10 @@ class AsyncCustomLedgersService( CustomLedgersServiceConfig, ): """Async Custom Ledgers service.""" + + def charges(self, custom_ledger_id: str) -> AsyncCustomLedgerChargesService: + """Return custom ledger charges service.""" + return AsyncCustomLedgerChargesService( + http_client=self.http_client, + endpoint_params={"custom_ledger_id": custom_ledger_id}, + ) diff --git a/tests/resources/billing/test_custom_ledger_charges.py b/tests/resources/billing/test_custom_ledger_charges.py new file mode 100644 index 0000000..1c3a720 --- /dev/null +++ b/tests/resources/billing/test_custom_ledger_charges.py @@ -0,0 +1,42 @@ +import pytest + +from mpt_api_client.resources.billing.custom_ledger_charges import ( + AsyncCustomLedgerChargesService, + CustomLedgerChargesService, +) + + +@pytest.fixture +def custom_ledger_charges_service(http_client): + return CustomLedgerChargesService( + http_client=http_client, endpoint_params={"custom_ledger_id": "LDG-0000-0001"} + ) + + +@pytest.fixture +def async_custom_ledger_charges_service(async_http_client): + return AsyncCustomLedgerChargesService( + http_client=async_http_client, endpoint_params={"custom_ledger_id": "LDG-0000-0001"} + ) + + +def test_endpoint(custom_ledger_charges_service): + assert custom_ledger_charges_service.endpoint == ( + "/public/v1/billing/custom-ledgers/LDG-0000-0001/charges" + ) + + +def test_async_endpoint(async_custom_ledger_charges_service): + assert async_custom_ledger_charges_service.endpoint == ( + "/public/v1/billing/custom-ledgers/LDG-0000-0001/charges" + ) + + +@pytest.mark.parametrize("method", ["get"]) +def test_methods_present(custom_ledger_charges_service, method): + assert hasattr(custom_ledger_charges_service, method) + + +@pytest.mark.parametrize("method", ["get"]) +def test_async_methods_present(async_custom_ledger_charges_service, method): + assert hasattr(async_custom_ledger_charges_service, method) diff --git a/tests/resources/billing/test_custom_ledgers.py b/tests/resources/billing/test_custom_ledgers.py index 0d23212..8348058 100644 --- a/tests/resources/billing/test_custom_ledgers.py +++ b/tests/resources/billing/test_custom_ledgers.py @@ -1,5 +1,9 @@ import pytest +from mpt_api_client.resources.billing.custom_ledger_charges import ( + AsyncCustomLedgerChargesService, + CustomLedgerChargesService, +) from mpt_api_client.resources.billing.custom_ledgers import ( AsyncCustomLedgersService, CustomLedgersService, @@ -24,3 +28,31 @@ def test_mixins_present(custom_ledgers_service, method): @pytest.mark.parametrize("method", ["get", "create", "update", "delete", "accept", "queue"]) def test_async_mixins_present(async_custom_ledgers_service, method): assert hasattr(async_custom_ledgers_service, method) + + +@pytest.mark.parametrize( + ("service_method", "expected_service_class"), + [ + ("charges", CustomLedgerChargesService), + ], +) +def test_property_services(custom_ledgers_service, service_method, expected_service_class): + service = getattr(custom_ledgers_service, service_method)("LDG-0000-0001") + + assert isinstance(service, expected_service_class) + assert service.endpoint_params == {"custom_ledger_id": "LDG-0000-0001"} + + +@pytest.mark.parametrize( + ("service_method", "expected_service_class"), + [ + ("charges", AsyncCustomLedgerChargesService), + ], +) +def test_async_property_services( + async_custom_ledgers_service, service_method, expected_service_class +): + service = getattr(async_custom_ledgers_service, service_method)("LDG-0000-0001") + + assert isinstance(service, expected_service_class) + assert service.endpoint_params == {"custom_ledger_id": "LDG-0000-0001"}