diff --git a/mpt_api_client/resources/billing/credit_memo_attachments.py b/mpt_api_client/resources/billing/credit_memo_attachments.py new file mode 100644 index 0000000..0db2b29 --- /dev/null +++ b/mpt_api_client/resources/billing/credit_memo_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 CreditMemoAttachment(Model): + """Credit Memo Attachment resource.""" + + +class CreditMemoAttachmentsServiceConfig: + """Credit Memo Attachments service configuration.""" + + _endpoint = "/public/v1/billing/credit-memos/{credit_memo_id}/attachments" + _model_class = CreditMemoAttachment + _collection_key = "data" + + +class CreditMemoAttachmentsService( + FileOperationsMixin[CreditMemoAttachment], + DeleteMixin, + UpdateMixin[CreditMemoAttachment], + Service[CreditMemoAttachment], + CreditMemoAttachmentsServiceConfig, +): + """Credit Memo Attachments service.""" + + +class AsyncCreditMemoAttachmentsService( + AsyncFileOperationsMixin[CreditMemoAttachment], + AsyncDeleteMixin, + AsyncUpdateMixin[CreditMemoAttachment], + AsyncService[CreditMemoAttachment], + CreditMemoAttachmentsServiceConfig, +): + """Credit Memo Attachments service.""" diff --git a/mpt_api_client/resources/billing/credit_memos.py b/mpt_api_client/resources/billing/credit_memos.py index 4c7ca38..524d8d7 100644 --- a/mpt_api_client/resources/billing/credit_memos.py +++ b/mpt_api_client/resources/billing/credit_memos.py @@ -6,6 +6,10 @@ UpdateMixin, ) from mpt_api_client.models import Model +from mpt_api_client.resources.billing.credit_memo_attachments import ( + AsyncCreditMemoAttachmentsService, + CreditMemoAttachmentsService, +) class CreditMemo(Model): @@ -28,6 +32,13 @@ class CreditMemosService( ): """Credit Memos service.""" + def attachments(self, credit_memo_id: str) -> CreditMemoAttachmentsService: + """Return credit memo attachments service.""" + return CreditMemoAttachmentsService( + http_client=self.http_client, + endpoint_params={"credit_memo_id": credit_memo_id}, + ) + class AsyncCreditMemosService( AsyncCreateMixin[CreditMemo], @@ -36,3 +47,10 @@ class AsyncCreditMemosService( CreditMemosServiceConfig, ): """Async Credit Memos service.""" + + def attachments(self, credit_memo_id: str) -> AsyncCreditMemoAttachmentsService: + """Return credit memo attachments service.""" + return AsyncCreditMemoAttachmentsService( + http_client=self.http_client, + endpoint_params={"credit_memo_id": credit_memo_id}, + ) diff --git a/tests/resources/billing/test_credit_memo_attachments.py b/tests/resources/billing/test_credit_memo_attachments.py new file mode 100644 index 0000000..afc00fa --- /dev/null +++ b/tests/resources/billing/test_credit_memo_attachments.py @@ -0,0 +1,44 @@ +import pytest + +from mpt_api_client.resources.billing.credit_memo_attachments import ( + AsyncCreditMemoAttachmentsService, + CreditMemoAttachmentsService, +) + + +@pytest.fixture +def credit_memo_attachments_service(http_client): + return CreditMemoAttachmentsService( + http_client=http_client, endpoint_params={"credit_memo_id": "CRM-0000-0001"} + ) + + +@pytest.fixture +def async_credit_memo_attachments_service(async_http_client): + return AsyncCreditMemoAttachmentsService( + http_client=async_http_client, endpoint_params={"credit_memo_id": "CRM-0000-0001"} + ) + + +def test_endpoint(credit_memo_attachments_service): + assert ( + credit_memo_attachments_service.endpoint + == "/public/v1/billing/credit-memos/CRM-0000-0001/attachments" + ) + + +def test_async_endpoint(async_credit_memo_attachments_service): + assert ( + async_credit_memo_attachments_service.endpoint + == "/public/v1/billing/credit-memos/CRM-0000-0001/attachments" + ) + + +@pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) +def test_methods_present(credit_memo_attachments_service, method: str): + assert hasattr(credit_memo_attachments_service, method) + + +@pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) +def test_async_methods_present(async_credit_memo_attachments_service, method: str): + assert hasattr(async_credit_memo_attachments_service, method) diff --git a/tests/resources/billing/test_credit_memos.py b/tests/resources/billing/test_credit_memos.py index 8f7d524..b67b876 100644 --- a/tests/resources/billing/test_credit_memos.py +++ b/tests/resources/billing/test_credit_memos.py @@ -1,5 +1,9 @@ import pytest +from mpt_api_client.resources.billing.credit_memo_attachments import ( + AsyncCreditMemoAttachmentsService, + CreditMemoAttachmentsService, +) from mpt_api_client.resources.billing.credit_memos import ( AsyncCreditMemosService, CreditMemosService, @@ -30,3 +34,31 @@ def test_mixins_present(credit_memos_service, method): ) def test_async_mixins_present(async_credit_memos_service, method): assert hasattr(async_credit_memos_service, method) + + +@pytest.mark.parametrize( + ("service_method", "expected_service_class"), + [ + ("attachments", CreditMemoAttachmentsService), + ], +) +def test_property_services(credit_memos_service, service_method, expected_service_class): + service = getattr(credit_memos_service, service_method)("CRM-0000-0001") + + assert isinstance(service, expected_service_class) + assert service.endpoint_params == {"credit_memo_id": "CRM-0000-0001"} + + +@pytest.mark.parametrize( + ("service_method", "expected_service_class"), + [ + ("attachments", AsyncCreditMemoAttachmentsService), + ], +) +def test_async_property_services( + async_credit_memos_service, service_method, expected_service_class +): + service = getattr(async_credit_memos_service, service_method)("CRM-0000-0001") + + assert isinstance(service, expected_service_class) + assert service.endpoint_params == {"credit_memo_id": "CRM-0000-0001"}