Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions mpt_api_client/resources/billing/credit_memo_attachments.py
Original file line number Diff line number Diff line change
@@ -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."""
18 changes: 18 additions & 0 deletions mpt_api_client/resources/billing/credit_memos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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],
Expand All @@ -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},
)
44 changes: 44 additions & 0 deletions tests/resources/billing/test_credit_memo_attachments.py
Original file line number Diff line number Diff line change
@@ -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)
32 changes: 32 additions & 0 deletions tests/resources/billing/test_credit_memos.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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"}