From b60c7bb06a02d45f037c3e646c857c66219da038 Mon Sep 17 00:00:00 2001 From: Robert Segal Date: Mon, 29 Sep 2025 10:44:01 -0600 Subject: [PATCH] Added billing journal upload endpoint --- .../resources/billing/journal_upload.py | 31 ++++++++++++++ mpt_api_client/resources/billing/journals.py | 16 ++++++++ setup.cfg | 2 +- .../resources/billing/test_journal_upload.py | 40 +++++++++++++++++++ tests/resources/billing/test_journals.py | 6 +++ 5 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 mpt_api_client/resources/billing/journal_upload.py create mode 100644 tests/resources/billing/test_journal_upload.py diff --git a/mpt_api_client/resources/billing/journal_upload.py b/mpt_api_client/resources/billing/journal_upload.py new file mode 100644 index 00000000..3ca82890 --- /dev/null +++ b/mpt_api_client/resources/billing/journal_upload.py @@ -0,0 +1,31 @@ +from mpt_api_client.http import AsyncService, Service +from mpt_api_client.http.mixins import AsyncFileOperationsMixin, FileOperationsMixin +from mpt_api_client.models import Model + + +class JournalUpload(Model): + """Journal Upload resource.""" + + +class JournalUploadServiceConfig: + """Journal Upload service configuration.""" + + _endpoint = "/public/v1/billing/journals/{journal_id}/upload" + _model_class = JournalUpload + _collection_key = "data" + + +class JournalUploadService( + FileOperationsMixin[JournalUpload], + Service[JournalUpload], + JournalUploadServiceConfig, +): + """Journal Upload service.""" + + +class AsyncJournalUploadService( + AsyncFileOperationsMixin[JournalUpload], + AsyncService[JournalUpload], + JournalUploadServiceConfig, +): + """Journal Upload service.""" diff --git a/mpt_api_client/resources/billing/journals.py b/mpt_api_client/resources/billing/journals.py index 58b9d1a6..8fad57ba 100644 --- a/mpt_api_client/resources/billing/journals.py +++ b/mpt_api_client/resources/billing/journals.py @@ -19,6 +19,10 @@ AsyncJournalSellersService, JournalSellersService, ) +from mpt_api_client.resources.billing.journal_upload import ( + AsyncJournalUploadService, + JournalUploadService, +) from mpt_api_client.resources.billing.mixins import AsyncRegeneratableMixin, RegeneratableMixin @@ -63,6 +67,12 @@ def charges(self, journal_id: str) -> JournalChargesService: http_client=self.http_client, endpoint_params={"journal_id": journal_id} ) + def upload(self, journal_id: str) -> JournalUploadService: + """Return journal upload service.""" + return JournalUploadService( + http_client=self.http_client, endpoint_params={"journal_id": journal_id} + ) + class AsyncJournalsService( AsyncCreateMixin[Journal], @@ -92,3 +102,9 @@ def charges(self, journal_id: str) -> AsyncJournalChargesService: return AsyncJournalChargesService( http_client=self.http_client, endpoint_params={"journal_id": journal_id} ) + + def upload(self, journal_id: str) -> AsyncJournalUploadService: + """Return journal upload service.""" + return AsyncJournalUploadService( + http_client=self.http_client, endpoint_params={"journal_id": journal_id} + ) diff --git a/setup.cfg b/setup.cfg index a7b61283..8fecc790 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,7 +32,7 @@ extend-ignore = per-file-ignores = - mpt_api_client/resources/billing/*.py: WPS215 WPS202 WPS214 + mpt_api_client/resources/billing/*.py: WPS215 WPS202 WPS214 WPS204 mpt_api_client/resources/catalog/*.py: WPS110 WPS215 WPS214 mpt_api_client/resources/commerce/*.py: WPS215 mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214 diff --git a/tests/resources/billing/test_journal_upload.py b/tests/resources/billing/test_journal_upload.py new file mode 100644 index 00000000..fc0d3d85 --- /dev/null +++ b/tests/resources/billing/test_journal_upload.py @@ -0,0 +1,40 @@ +import pytest + +from mpt_api_client.resources.billing.journal_upload import ( + AsyncJournalUploadService, + JournalUploadService, +) + + +@pytest.fixture +def journal_upload_service(http_client): + return JournalUploadService( + http_client=http_client, endpoint_params={"journal_id": "JRN-0000-0001"} + ) + + +@pytest.fixture +def async_journal_upload_service(async_http_client): + return AsyncJournalUploadService( + http_client=async_http_client, endpoint_params={"journal_id": "JRN-0000-0001"} + ) + + +def test_endpoint(journal_upload_service) -> None: + assert journal_upload_service.endpoint == "/public/v1/billing/journals/JRN-0000-0001/upload" + + +def test_async_endpoint(async_journal_upload_service) -> None: + assert ( + async_journal_upload_service.endpoint == "/public/v1/billing/journals/JRN-0000-0001/upload" + ) + + +@pytest.mark.parametrize("method", ["create"]) +def test_methods_present(journal_upload_service, method: str) -> None: + assert hasattr(journal_upload_service, method) + + +@pytest.mark.parametrize("method", ["create"]) +def test_async_methods_present(async_journal_upload_service, method: str) -> None: + assert hasattr(async_journal_upload_service, method) diff --git a/tests/resources/billing/test_journals.py b/tests/resources/billing/test_journals.py index 17ce3648..658784ce 100644 --- a/tests/resources/billing/test_journals.py +++ b/tests/resources/billing/test_journals.py @@ -12,6 +12,10 @@ AsyncJournalSellersService, JournalSellersService, ) +from mpt_api_client.resources.billing.journal_upload import ( + AsyncJournalUploadService, + JournalUploadService, +) from mpt_api_client.resources.billing.journals import AsyncJournalsService, JournalsService @@ -47,6 +51,7 @@ def test_async_mixins_present(async_journals_service, method): ("attachments", JournalAttachmentsService), ("sellers", JournalSellersService), ("charges", JournalChargesService), + ("upload", JournalUploadService), ], ) def test_property_services(journals_service, service_method, expected_service_class): @@ -62,6 +67,7 @@ def test_property_services(journals_service, service_method, expected_service_cl ("attachments", AsyncJournalAttachmentsService), ("sellers", AsyncJournalSellersService), ("charges", AsyncJournalChargesService), + ("upload", AsyncJournalUploadService), ], ) def test_async_property_services(async_journals_service, service_method, expected_service_class):