Skip to content

Commit 14db8e2

Browse files
authored
[MPT-13833] Added billing credit memo attachments (#62)
Added billing credit memo attachments https://softwareone.atlassian.net/browse/MPT-13833
2 parents 2f888d9 + 8857d4f commit 14db8e2

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from mpt_api_client.http import AsyncService, Service
2+
from mpt_api_client.http.mixins import (
3+
AsyncDeleteMixin,
4+
AsyncFileOperationsMixin,
5+
AsyncUpdateMixin,
6+
DeleteMixin,
7+
FileOperationsMixin,
8+
UpdateMixin,
9+
)
10+
from mpt_api_client.models import Model
11+
12+
13+
class CreditMemoAttachment(Model):
14+
"""Credit Memo Attachment resource."""
15+
16+
17+
class CreditMemoAttachmentsServiceConfig:
18+
"""Credit Memo Attachments service configuration."""
19+
20+
_endpoint = "/public/v1/billing/credit-memos/{credit_memo_id}/attachments"
21+
_model_class = CreditMemoAttachment
22+
_collection_key = "data"
23+
24+
25+
class CreditMemoAttachmentsService(
26+
FileOperationsMixin[CreditMemoAttachment],
27+
DeleteMixin,
28+
UpdateMixin[CreditMemoAttachment],
29+
Service[CreditMemoAttachment],
30+
CreditMemoAttachmentsServiceConfig,
31+
):
32+
"""Credit Memo Attachments service."""
33+
34+
35+
class AsyncCreditMemoAttachmentsService(
36+
AsyncFileOperationsMixin[CreditMemoAttachment],
37+
AsyncDeleteMixin,
38+
AsyncUpdateMixin[CreditMemoAttachment],
39+
AsyncService[CreditMemoAttachment],
40+
CreditMemoAttachmentsServiceConfig,
41+
):
42+
"""Credit Memo Attachments service."""

mpt_api_client/resources/billing/credit_memos.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
UpdateMixin,
77
)
88
from mpt_api_client.models import Model
9+
from mpt_api_client.resources.billing.credit_memo_attachments import (
10+
AsyncCreditMemoAttachmentsService,
11+
CreditMemoAttachmentsService,
12+
)
913

1014

1115
class CreditMemo(Model):
@@ -28,6 +32,13 @@ class CreditMemosService(
2832
):
2933
"""Credit Memos service."""
3034

35+
def attachments(self, credit_memo_id: str) -> CreditMemoAttachmentsService:
36+
"""Return credit memo attachments service."""
37+
return CreditMemoAttachmentsService(
38+
http_client=self.http_client,
39+
endpoint_params={"credit_memo_id": credit_memo_id},
40+
)
41+
3142

3243
class AsyncCreditMemosService(
3344
AsyncCreateMixin[CreditMemo],
@@ -36,3 +47,10 @@ class AsyncCreditMemosService(
3647
CreditMemosServiceConfig,
3748
):
3849
"""Async Credit Memos service."""
50+
51+
def attachments(self, credit_memo_id: str) -> AsyncCreditMemoAttachmentsService:
52+
"""Return credit memo attachments service."""
53+
return AsyncCreditMemoAttachmentsService(
54+
http_client=self.http_client,
55+
endpoint_params={"credit_memo_id": credit_memo_id},
56+
)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.billing.credit_memo_attachments import (
4+
AsyncCreditMemoAttachmentsService,
5+
CreditMemoAttachmentsService,
6+
)
7+
8+
9+
@pytest.fixture
10+
def credit_memo_attachments_service(http_client):
11+
return CreditMemoAttachmentsService(
12+
http_client=http_client, endpoint_params={"credit_memo_id": "CRM-0000-0001"}
13+
)
14+
15+
16+
@pytest.fixture
17+
def async_credit_memo_attachments_service(async_http_client):
18+
return AsyncCreditMemoAttachmentsService(
19+
http_client=async_http_client, endpoint_params={"credit_memo_id": "CRM-0000-0001"}
20+
)
21+
22+
23+
def test_endpoint(credit_memo_attachments_service):
24+
assert (
25+
credit_memo_attachments_service.endpoint
26+
== "/public/v1/billing/credit-memos/CRM-0000-0001/attachments"
27+
)
28+
29+
30+
def test_async_endpoint(async_credit_memo_attachments_service):
31+
assert (
32+
async_credit_memo_attachments_service.endpoint
33+
== "/public/v1/billing/credit-memos/CRM-0000-0001/attachments"
34+
)
35+
36+
37+
@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
38+
def test_methods_present(credit_memo_attachments_service, method: str):
39+
assert hasattr(credit_memo_attachments_service, method)
40+
41+
42+
@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
43+
def test_async_methods_present(async_credit_memo_attachments_service, method: str):
44+
assert hasattr(async_credit_memo_attachments_service, method)

tests/resources/billing/test_credit_memos.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import pytest
22

3+
from mpt_api_client.resources.billing.credit_memo_attachments import (
4+
AsyncCreditMemoAttachmentsService,
5+
CreditMemoAttachmentsService,
6+
)
37
from mpt_api_client.resources.billing.credit_memos import (
48
AsyncCreditMemosService,
59
CreditMemosService,
@@ -30,3 +34,31 @@ def test_mixins_present(credit_memos_service, method):
3034
)
3135
def test_async_mixins_present(async_credit_memos_service, method):
3236
assert hasattr(async_credit_memos_service, method)
37+
38+
39+
@pytest.mark.parametrize(
40+
("service_method", "expected_service_class"),
41+
[
42+
("attachments", CreditMemoAttachmentsService),
43+
],
44+
)
45+
def test_property_services(credit_memos_service, service_method, expected_service_class):
46+
service = getattr(credit_memos_service, service_method)("CRM-0000-0001")
47+
48+
assert isinstance(service, expected_service_class)
49+
assert service.endpoint_params == {"credit_memo_id": "CRM-0000-0001"}
50+
51+
52+
@pytest.mark.parametrize(
53+
("service_method", "expected_service_class"),
54+
[
55+
("attachments", AsyncCreditMemoAttachmentsService),
56+
],
57+
)
58+
def test_async_property_services(
59+
async_credit_memos_service, service_method, expected_service_class
60+
):
61+
service = getattr(async_credit_memos_service, service_method)("CRM-0000-0001")
62+
63+
assert isinstance(service, expected_service_class)
64+
assert service.endpoint_params == {"credit_memo_id": "CRM-0000-0001"}

0 commit comments

Comments
 (0)