Skip to content

Commit 3657841

Browse files
author
Robert Segal
committed
Added missing billing statement attachments endpoints
1 parent 91901a2 commit 3657841

File tree

4 files changed

+158
-2
lines changed

4 files changed

+158
-2
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from mpt_api_client.http import AsyncService, Service
2+
from mpt_api_client.http.mixins import (
3+
AsyncCollectionMixin,
4+
AsyncCreateFileMixin,
5+
AsyncDeleteMixin,
6+
AsyncDownloadFileMixin,
7+
AsyncGetMixin,
8+
AsyncUpdateMixin,
9+
CollectionMixin,
10+
CreateFileMixin,
11+
DeleteMixin,
12+
DownloadFileMixin,
13+
GetMixin,
14+
UpdateMixin,
15+
)
16+
from mpt_api_client.models import Model
17+
18+
19+
class StatementAttachment(Model):
20+
"""Statement Attachment resource."""
21+
22+
23+
class StatementAttachmentsServiceConfig:
24+
"""Statement Attachments service configuration."""
25+
26+
_endpoint = "/public/v1/billing/statements/{statement_id}/attachments"
27+
_model_class = StatementAttachment
28+
_collection_key = "data"
29+
_upload_file_key = "file"
30+
_upload_data_key = "attachment"
31+
32+
33+
class StatementAttachmentsService(
34+
CreateFileMixin[StatementAttachment],
35+
UpdateMixin[StatementAttachment],
36+
DownloadFileMixin[StatementAttachment],
37+
DeleteMixin,
38+
GetMixin[StatementAttachment],
39+
CollectionMixin[StatementAttachment],
40+
Service[StatementAttachment],
41+
StatementAttachmentsServiceConfig,
42+
):
43+
"""Statement Attachments service."""
44+
45+
46+
class AsyncStatementAttachmentsService(
47+
AsyncCreateFileMixin[StatementAttachment],
48+
AsyncUpdateMixin[StatementAttachment],
49+
AsyncDownloadFileMixin[StatementAttachment],
50+
AsyncDeleteMixin,
51+
AsyncGetMixin[StatementAttachment],
52+
AsyncCollectionMixin[StatementAttachment],
53+
AsyncService[StatementAttachment],
54+
StatementAttachmentsServiceConfig,
55+
):
56+
"""Statement Attachments service."""

mpt_api_client/resources/billing/statements.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
)
1010
from mpt_api_client.models import Model
1111
from mpt_api_client.resources.billing.mixins import AsyncIssuableMixin, IssuableMixin
12+
from mpt_api_client.resources.billing.statement_attachments import (
13+
AsyncStatementAttachmentsService,
14+
StatementAttachmentsService,
15+
)
1216
from mpt_api_client.resources.billing.statement_charges import (
1317
AsyncStatementChargesService,
1418
StatementChargesService,
@@ -44,6 +48,13 @@ def charges(self, statement_id: str) -> StatementChargesService:
4448
endpoint_params={"statement_id": statement_id},
4549
)
4650

51+
def attachments(self, statement_id: str) -> StatementAttachmentsService:
52+
"""Return statement attachments service."""
53+
return StatementAttachmentsService(
54+
http_client=self.http_client,
55+
endpoint_params={"statement_id": statement_id},
56+
)
57+
4758

4859
class AsyncStatementsService(
4960
AsyncUpdateMixin[Statement],
@@ -61,3 +72,10 @@ def charges(self, statement_id: str) -> AsyncStatementChargesService:
6172
http_client=self.http_client,
6273
endpoint_params={"statement_id": statement_id},
6374
)
75+
76+
def attachments(self, statement_id: str) -> AsyncStatementAttachmentsService:
77+
"""Return statement attachments service."""
78+
return AsyncStatementAttachmentsService(
79+
http_client=self.http_client,
80+
endpoint_params={"statement_id": statement_id},
81+
)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.billing.statement_attachments import (
4+
AsyncStatementAttachmentsService,
5+
StatementAttachmentsService,
6+
)
7+
8+
9+
@pytest.fixture
10+
def statement_attachments_service(http_client) -> StatementAttachmentsService:
11+
return StatementAttachmentsService(
12+
http_client=http_client, endpoint_params={"statement_id": "STM-0000-0001"}
13+
)
14+
15+
16+
@pytest.fixture
17+
def async_statement_attachments_service(async_http_client) -> AsyncStatementAttachmentsService:
18+
return AsyncStatementAttachmentsService(
19+
http_client=async_http_client, endpoint_params={"statement_id": "STM-0000-0001"}
20+
)
21+
22+
23+
def test_endpoint(statement_attachments_service) -> None:
24+
result = (
25+
statement_attachments_service.path
26+
== "/public/v1/billing/statements/STM-0000-0001/attachments"
27+
)
28+
29+
assert result is True
30+
31+
32+
def test_async_endpoint(async_statement_attachments_service) -> None:
33+
result = (
34+
async_statement_attachments_service.path
35+
== "/public/v1/billing/statements/STM-0000-0001/attachments"
36+
)
37+
38+
assert result is True
39+
40+
41+
@pytest.mark.parametrize("method", ["get", "create", "update", "delete", "iterate", "download"])
42+
def test_methods_present(statement_attachments_service, method: str) -> None:
43+
result = hasattr(statement_attachments_service, method)
44+
45+
assert result is True
46+
47+
48+
@pytest.mark.parametrize("method", ["get", "create", "update", "delete", "iterate", "download"])
49+
def test_async_methods_present(async_statement_attachments_service, method: str) -> None:
50+
result = hasattr(async_statement_attachments_service, method)
51+
52+
assert result is True

tests/unit/resources/billing/test_statements.py

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

3+
from mpt_api_client.resources.billing.statement_attachments import (
4+
AsyncStatementAttachmentsService,
5+
StatementAttachmentsService,
6+
)
37
from mpt_api_client.resources.billing.statement_charges import (
48
AsyncStatementChargesService,
59
StatementChargesService,
@@ -19,7 +23,19 @@ def async_statements_service(async_http_client):
1923

2024
@pytest.mark.parametrize(
2125
"method",
22-
["get", "update", "issue", "cancel", "error", "pending", "queue", "retry", "recalculate"],
26+
[
27+
"get",
28+
"update",
29+
"issue",
30+
"cancel",
31+
"error",
32+
"pending",
33+
"queue",
34+
"retry",
35+
"recalculate",
36+
"attachments",
37+
"charges",
38+
],
2339
)
2440
def test_mixins_present(statements_service, method):
2541
result = hasattr(statements_service, method)
@@ -29,7 +45,19 @@ def test_mixins_present(statements_service, method):
2945

3046
@pytest.mark.parametrize(
3147
"method",
32-
["get", "update", "issue", "cancel", "error", "pending", "queue", "retry", "recalculate"],
48+
[
49+
"get",
50+
"update",
51+
"issue",
52+
"cancel",
53+
"error",
54+
"pending",
55+
"queue",
56+
"retry",
57+
"recalculate",
58+
"attachments",
59+
"charges",
60+
],
3361
)
3462
def test_async_mixins_present(async_statements_service, method):
3563
result = hasattr(async_statements_service, method)
@@ -41,6 +69,7 @@ def test_async_mixins_present(async_statements_service, method):
4169
("service_method", "expected_service_class"),
4270
[
4371
("charges", StatementChargesService),
72+
("attachments", StatementAttachmentsService),
4473
],
4574
)
4675
def test_property_services(statements_service, service_method, expected_service_class):
@@ -54,6 +83,7 @@ def test_property_services(statements_service, service_method, expected_service_
5483
("service_method", "expected_service_class"),
5584
[
5685
("charges", AsyncStatementChargesService),
86+
("attachments", AsyncStatementAttachmentsService),
5787
],
5888
)
5989
def test_async_property_services(async_statements_service, service_method, expected_service_class):

0 commit comments

Comments
 (0)