Skip to content

Commit d4bc15e

Browse files
author
Robert Segal
committed
Added billing journals attachments endpoints
1 parent 04eb920 commit d4bc15e

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from mpt_api_client.http import AsyncService, Service
2+
from mpt_api_client.http.mixins import AsyncFileOperationsMixin, FileOperationsMixin
3+
from mpt_api_client.models import Model
4+
5+
6+
class JournalAttachment(Model):
7+
"""Journal Attachment resource."""
8+
9+
10+
class JournalAttachmentsServiceConfig:
11+
"""Journal Attachments service configuration."""
12+
13+
_endpoint = "/public/v1/billing/journals/{journal_id}/attachments"
14+
_model_class = JournalAttachment
15+
_collection_key = "data"
16+
17+
18+
class JournalAttachmentsService(
19+
FileOperationsMixin[JournalAttachment],
20+
Service[JournalAttachment],
21+
JournalAttachmentsServiceConfig,
22+
):
23+
"""Journal Attachments service."""
24+
25+
26+
class AsyncJournalAttachmentsService(
27+
AsyncFileOperationsMixin[JournalAttachment],
28+
AsyncService[JournalAttachment],
29+
JournalAttachmentsServiceConfig,
30+
):
31+
"""Journal Attachments service."""

mpt_api_client/resources/billing/journals.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
UpdateMixin,
88
)
99
from mpt_api_client.models import Model
10+
from mpt_api_client.resources.billing.journal_attachments import (
11+
AsyncJournalAttachmentsService,
12+
JournalAttachmentsService,
13+
)
1014
from mpt_api_client.resources.billing.mixins import AsyncRegeneratableMixin, RegeneratableMixin
1115

1216

@@ -32,6 +36,13 @@ class JournalsService(
3236
):
3337
"""Journals service."""
3438

39+
def attachments(self, journal_id: str) -> JournalAttachmentsService:
40+
"""Return journal attachments service."""
41+
return JournalAttachmentsService(
42+
http_client=self.http_client,
43+
endpoint_params={"journal_id": journal_id},
44+
)
45+
3546

3647
class AsyncJournalsService(
3748
AsyncCreateMixin[Journal],
@@ -42,3 +53,10 @@ class AsyncJournalsService(
4253
JournalsServiceConfig,
4354
):
4455
"""Async Journals service."""
56+
57+
def attachments(self, journal_id: str) -> AsyncJournalAttachmentsService:
58+
"""Return journal attachments service."""
59+
return AsyncJournalAttachmentsService(
60+
http_client=self.http_client,
61+
endpoint_params={"journal_id": journal_id},
62+
)
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.journal_attachments import (
4+
AsyncJournalAttachmentsService,
5+
JournalAttachmentsService,
6+
)
7+
8+
9+
@pytest.fixture
10+
def journal_attachments_service(http_client) -> JournalAttachmentsService:
11+
return JournalAttachmentsService(
12+
http_client=http_client, endpoint_params={"journal_id": "JRN-0000-0001"}
13+
)
14+
15+
16+
@pytest.fixture
17+
def async_journal_attachments_service(async_http_client) -> AsyncJournalAttachmentsService:
18+
return AsyncJournalAttachmentsService(
19+
http_client=async_http_client, endpoint_params={"journal_id": "JRN-0000-0001"}
20+
)
21+
22+
23+
def test_endpoint(journal_attachments_service) -> None:
24+
assert (
25+
journal_attachments_service.endpoint
26+
== "/public/v1/billing/journals/JRN-0000-0001/attachments"
27+
)
28+
29+
30+
def test_async_endpoint(async_journal_attachments_service) -> None:
31+
assert (
32+
async_journal_attachments_service.endpoint
33+
== "/public/v1/billing/journals/JRN-0000-0001/attachments"
34+
)
35+
36+
37+
@pytest.mark.parametrize("method", ["get", "create"])
38+
def test_methods_present(journal_attachments_service, method: str) -> None:
39+
assert hasattr(journal_attachments_service, method)
40+
41+
42+
@pytest.mark.parametrize("method", ["get", "create"])
43+
def test_async_methods_present(async_journal_attachments_service, method: str) -> None:
44+
assert hasattr(async_journal_attachments_service, method)

tests/resources/billing/test_journals.py

Lines changed: 30 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.journal_attachments import (
4+
AsyncJournalAttachmentsService,
5+
JournalAttachmentsService,
6+
)
37
from mpt_api_client.resources.billing.journals import AsyncJournalsService, JournalsService
48

59

@@ -27,3 +31,29 @@ def test_mixins_present(journals_service, method):
2731
)
2832
def test_async_mixins_present(async_journals_service, method):
2933
assert hasattr(async_journals_service, method)
34+
35+
36+
@pytest.mark.parametrize(
37+
("service_method", "expected_service_class"),
38+
[
39+
("attachments", JournalAttachmentsService),
40+
],
41+
)
42+
def test_property_services(journals_service, service_method, expected_service_class):
43+
service = getattr(journals_service, service_method)("JRN-0000-0001")
44+
45+
assert isinstance(service, expected_service_class)
46+
assert service.endpoint_params == {"journal_id": "JRN-0000-0001"}
47+
48+
49+
@pytest.mark.parametrize(
50+
("service_method", "expected_service_class"),
51+
[
52+
("attachments", AsyncJournalAttachmentsService),
53+
],
54+
)
55+
def test_async_property_services(async_journals_service, service_method, expected_service_class):
56+
service = getattr(async_journals_service, service_method)("JRN-0000-0001")
57+
58+
assert isinstance(service, expected_service_class)
59+
assert service.endpoint_params == {"journal_id": "JRN-0000-0001"}

0 commit comments

Comments
 (0)