Skip to content

Commit a109b16

Browse files
author
Robert Segal
committed
Added ledger attachments endpoints
1 parent 498c0b1 commit a109b16

4 files changed

Lines changed: 110 additions & 0 deletions

File tree

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 LedgerAttachment(Model):
14+
"""Ledger Attachment resource."""
15+
16+
17+
class LedgerAttachmentsServiceConfig:
18+
"""Ledger Attachments service configuration."""
19+
20+
_endpoint = "/public/v1/billing/ledgers/{ledger_id}/attachments"
21+
_model_class = LedgerAttachment
22+
_collection_key = "data"
23+
24+
25+
class LedgerAttachmentsService(
26+
FileOperationsMixin[LedgerAttachment],
27+
DeleteMixin,
28+
UpdateMixin[LedgerAttachment],
29+
Service[LedgerAttachment],
30+
LedgerAttachmentsServiceConfig,
31+
):
32+
"""Ledger Attachments service."""
33+
34+
35+
class AsyncLedgerAttachmentsService(
36+
AsyncFileOperationsMixin[LedgerAttachment],
37+
AsyncDeleteMixin,
38+
AsyncUpdateMixin[LedgerAttachment],
39+
AsyncService[LedgerAttachment],
40+
LedgerAttachmentsServiceConfig,
41+
):
42+
"""Ledger Attachments service."""

mpt_api_client/resources/billing/ledgers.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
CreateMixin,
55
)
66
from mpt_api_client.models import Model
7+
from mpt_api_client.resources.billing.ledger_attachments import (
8+
AsyncLedgerAttachmentsService,
9+
LedgerAttachmentsService,
10+
)
711
from mpt_api_client.resources.billing.ledger_charges import (
812
AsyncLedgerChargesService,
913
LedgerChargesService,
@@ -36,6 +40,13 @@ def charges(self, ledger_id: str) -> LedgerChargesService:
3640
endpoint_params={"ledger_id": ledger_id},
3741
)
3842

43+
def attachments(self, ledger_id: str) -> LedgerAttachmentsService:
44+
"""Return ledger attachments service."""
45+
return LedgerAttachmentsService(
46+
http_client=self.http_client,
47+
endpoint_params={"ledger_id": ledger_id},
48+
)
49+
3950

4051
class AsyncLedgersService(
4152
AsyncCreateMixin[Ledger],
@@ -50,3 +61,10 @@ def charges(self, ledger_id: str) -> AsyncLedgerChargesService:
5061
http_client=self.http_client,
5162
endpoint_params={"ledger_id": ledger_id},
5263
)
64+
65+
def attachments(self, ledger_id: str) -> AsyncLedgerAttachmentsService:
66+
"""Return ledger attachments service."""
67+
return AsyncLedgerAttachmentsService(
68+
http_client=self.http_client,
69+
endpoint_params={"ledger_id": ledger_id},
70+
)
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.ledger_attachments import (
4+
AsyncLedgerAttachmentsService,
5+
LedgerAttachmentsService,
6+
)
7+
8+
9+
@pytest.fixture
10+
def ledger_attachments_service(http_client) -> LedgerAttachmentsService:
11+
return LedgerAttachmentsService(
12+
http_client=http_client, endpoint_params={"ledger_id": "LED-0000-0001"}
13+
)
14+
15+
16+
@pytest.fixture
17+
def async_ledger_attachments_service(async_http_client) -> AsyncLedgerAttachmentsService:
18+
return AsyncLedgerAttachmentsService(
19+
http_client=async_http_client, endpoint_params={"ledger_id": "LED-0000-0001"}
20+
)
21+
22+
23+
def test_endpoint(ledger_attachments_service) -> None:
24+
assert (
25+
ledger_attachments_service.endpoint
26+
== "/public/v1/billing/ledgers/LED-0000-0001/attachments"
27+
)
28+
29+
30+
def test_async_endpoint(async_ledger_attachments_service) -> None:
31+
assert (
32+
async_ledger_attachments_service.endpoint
33+
== "/public/v1/billing/ledgers/LED-0000-0001/attachments"
34+
)
35+
36+
37+
@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
38+
def test_methods_present(ledger_attachments_service, method: str) -> None:
39+
assert hasattr(ledger_attachments_service, method)
40+
41+
42+
@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
43+
def test_async_methods_present(async_ledger_attachments_service, method: str) -> None:
44+
assert hasattr(async_ledger_attachments_service, method)

tests/resources/billing/test_ledgers.py

Lines changed: 6 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.ledger_attachments import (
4+
AsyncLedgerAttachmentsService,
5+
LedgerAttachmentsService,
6+
)
37
from mpt_api_client.resources.billing.ledger_charges import (
48
AsyncLedgerChargesService,
59
LedgerChargesService,
@@ -37,6 +41,7 @@ def test_async_mixins_present(async_ledgers_service, method):
3741
("service_method", "expected_service_class"),
3842
[
3943
("charges", LedgerChargesService),
44+
("attachments", LedgerAttachmentsService),
4045
],
4146
)
4247
def test_property_services(ledgers_service, service_method, expected_service_class):
@@ -50,6 +55,7 @@ def test_property_services(ledgers_service, service_method, expected_service_cla
5055
("service_method", "expected_service_class"),
5156
[
5257
("charges", AsyncLedgerChargesService),
58+
("attachments", AsyncLedgerAttachmentsService),
5359
],
5460
)
5561
def test_async_property_services(async_ledgers_service, service_method, expected_service_class):

0 commit comments

Comments
 (0)