From 018bea2bb10216198fe0e7c4e6a23b2a73ecd5cf Mon Sep 17 00:00:00 2001 From: Robert Segal Date: Thu, 25 Sep 2025 12:54:39 -0600 Subject: [PATCH] Added billing journals attachments endpoints --- .../resources/billing/journal_attachments.py | 42 ++++++++++++++++++ mpt_api_client/resources/billing/journals.py | 18 ++++++++ .../billing/test_journal_attachments.py | 44 +++++++++++++++++++ tests/resources/billing/test_journals.py | 30 +++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 mpt_api_client/resources/billing/journal_attachments.py create mode 100644 tests/resources/billing/test_journal_attachments.py diff --git a/mpt_api_client/resources/billing/journal_attachments.py b/mpt_api_client/resources/billing/journal_attachments.py new file mode 100644 index 0000000..6379871 --- /dev/null +++ b/mpt_api_client/resources/billing/journal_attachments.py @@ -0,0 +1,42 @@ +from mpt_api_client.http import AsyncService, Service +from mpt_api_client.http.mixins import ( + AsyncDeleteMixin, + AsyncFileOperationsMixin, + AsyncUpdateMixin, + DeleteMixin, + FileOperationsMixin, + UpdateMixin, +) +from mpt_api_client.models import Model + + +class JournalAttachment(Model): + """Journal Attachment resource.""" + + +class JournalAttachmentsServiceConfig: + """Journal Attachments service configuration.""" + + _endpoint = "/public/v1/billing/journals/{journal_id}/attachments" + _model_class = JournalAttachment + _collection_key = "data" + + +class JournalAttachmentsService( + FileOperationsMixin[JournalAttachment], + DeleteMixin, + UpdateMixin[JournalAttachment], + Service[JournalAttachment], + JournalAttachmentsServiceConfig, +): + """Journal Attachments service.""" + + +class AsyncJournalAttachmentsService( + AsyncFileOperationsMixin[JournalAttachment], + AsyncDeleteMixin, + AsyncUpdateMixin[JournalAttachment], + AsyncService[JournalAttachment], + JournalAttachmentsServiceConfig, +): + """Journal Attachments service.""" diff --git a/mpt_api_client/resources/billing/journals.py b/mpt_api_client/resources/billing/journals.py index e8080bf..0c1b7b5 100644 --- a/mpt_api_client/resources/billing/journals.py +++ b/mpt_api_client/resources/billing/journals.py @@ -7,6 +7,10 @@ UpdateMixin, ) from mpt_api_client.models import Model +from mpt_api_client.resources.billing.journal_attachments import ( + AsyncJournalAttachmentsService, + JournalAttachmentsService, +) from mpt_api_client.resources.billing.mixins import AsyncRegeneratableMixin, RegeneratableMixin @@ -32,6 +36,13 @@ class JournalsService( ): """Journals service.""" + def attachments(self, journal_id: str) -> JournalAttachmentsService: + """Return journal attachments service.""" + return JournalAttachmentsService( + http_client=self.http_client, + endpoint_params={"journal_id": journal_id}, + ) + class AsyncJournalsService( AsyncCreateMixin[Journal], @@ -42,3 +53,10 @@ class AsyncJournalsService( JournalsServiceConfig, ): """Async Journals service.""" + + def attachments(self, journal_id: str) -> AsyncJournalAttachmentsService: + """Return journal attachments service.""" + return AsyncJournalAttachmentsService( + http_client=self.http_client, + endpoint_params={"journal_id": journal_id}, + ) diff --git a/tests/resources/billing/test_journal_attachments.py b/tests/resources/billing/test_journal_attachments.py new file mode 100644 index 0000000..9e272b2 --- /dev/null +++ b/tests/resources/billing/test_journal_attachments.py @@ -0,0 +1,44 @@ +import pytest + +from mpt_api_client.resources.billing.journal_attachments import ( + AsyncJournalAttachmentsService, + JournalAttachmentsService, +) + + +@pytest.fixture +def journal_attachments_service(http_client) -> JournalAttachmentsService: + return JournalAttachmentsService( + http_client=http_client, endpoint_params={"journal_id": "JRN-0000-0001"} + ) + + +@pytest.fixture +def async_journal_attachments_service(async_http_client) -> AsyncJournalAttachmentsService: + return AsyncJournalAttachmentsService( + http_client=async_http_client, endpoint_params={"journal_id": "JRN-0000-0001"} + ) + + +def test_endpoint(journal_attachments_service) -> None: + assert ( + journal_attachments_service.endpoint + == "/public/v1/billing/journals/JRN-0000-0001/attachments" + ) + + +def test_async_endpoint(async_journal_attachments_service) -> None: + assert ( + async_journal_attachments_service.endpoint + == "/public/v1/billing/journals/JRN-0000-0001/attachments" + ) + + +@pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) +def test_methods_present(journal_attachments_service, method: str) -> None: + assert hasattr(journal_attachments_service, method) + + +@pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) +def test_async_methods_present(async_journal_attachments_service, method: str) -> None: + assert hasattr(async_journal_attachments_service, method) diff --git a/tests/resources/billing/test_journals.py b/tests/resources/billing/test_journals.py index cf2b4c7..8018d83 100644 --- a/tests/resources/billing/test_journals.py +++ b/tests/resources/billing/test_journals.py @@ -1,5 +1,9 @@ import pytest +from mpt_api_client.resources.billing.journal_attachments import ( + AsyncJournalAttachmentsService, + JournalAttachmentsService, +) from mpt_api_client.resources.billing.journals import AsyncJournalsService, JournalsService @@ -27,3 +31,29 @@ def test_mixins_present(journals_service, method): ) def test_async_mixins_present(async_journals_service, method): assert hasattr(async_journals_service, method) + + +@pytest.mark.parametrize( + ("service_method", "expected_service_class"), + [ + ("attachments", JournalAttachmentsService), + ], +) +def test_property_services(journals_service, service_method, expected_service_class): + service = getattr(journals_service, service_method)("JRN-0000-0001") + + assert isinstance(service, expected_service_class) + assert service.endpoint_params == {"journal_id": "JRN-0000-0001"} + + +@pytest.mark.parametrize( + ("service_method", "expected_service_class"), + [ + ("attachments", AsyncJournalAttachmentsService), + ], +) +def test_async_property_services(async_journals_service, service_method, expected_service_class): + service = getattr(async_journals_service, service_method)("JRN-0000-0001") + + assert isinstance(service, expected_service_class) + assert service.endpoint_params == {"journal_id": "JRN-0000-0001"}