Skip to content

Commit 6e86662

Browse files
authored
[MPT-13819] Added billing journals attachments endpoints (#50)
Added billing journals attachments endpoints https://softwareone.atlassian.net/browse/MPT-13819
2 parents 04eb920 + 018bea2 commit 6e86662

File tree

4 files changed

+134
-0
lines changed

4 files changed

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