Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions mpt_api_client/resources/billing/journal_attachments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.http.mixins import (
AsyncDeleteMixin,
AsyncFileOperationsMixin,
AsyncUpdateMixin,
DeleteMixin,
FileOperationsMixin,
UpdateMixin,
)
from mpt_api_client.models import Model


class JournalAttachment(Model):
"""Journal Attachment resource."""


class JournalAttachmentsServiceConfig:
"""Journal Attachments service configuration."""

_endpoint = "/public/v1/billing/journals/{journal_id}/attachments"
_model_class = JournalAttachment
_collection_key = "data"


class JournalAttachmentsService(
FileOperationsMixin[JournalAttachment],
DeleteMixin,
UpdateMixin[JournalAttachment],
Service[JournalAttachment],
JournalAttachmentsServiceConfig,
):
"""Journal Attachments service."""


class AsyncJournalAttachmentsService(
AsyncFileOperationsMixin[JournalAttachment],
AsyncDeleteMixin,
AsyncUpdateMixin[JournalAttachment],
AsyncService[JournalAttachment],
JournalAttachmentsServiceConfig,
):
"""Journal Attachments service."""
18 changes: 18 additions & 0 deletions mpt_api_client/resources/billing/journals.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
UpdateMixin,
)
from mpt_api_client.models import Model
from mpt_api_client.resources.billing.journal_attachments import (
AsyncJournalAttachmentsService,
JournalAttachmentsService,
)
from mpt_api_client.resources.billing.mixins import AsyncRegeneratableMixin, RegeneratableMixin


Expand All @@ -32,6 +36,13 @@ class JournalsService(
):
"""Journals service."""

def attachments(self, journal_id: str) -> JournalAttachmentsService:
"""Return journal attachments service."""
return JournalAttachmentsService(
http_client=self.http_client,
endpoint_params={"journal_id": journal_id},
)


class AsyncJournalsService(
AsyncCreateMixin[Journal],
Expand All @@ -42,3 +53,10 @@ class AsyncJournalsService(
JournalsServiceConfig,
):
"""Async Journals service."""

def attachments(self, journal_id: str) -> AsyncJournalAttachmentsService:
"""Return journal attachments service."""
return AsyncJournalAttachmentsService(
http_client=self.http_client,
endpoint_params={"journal_id": journal_id},
)
44 changes: 44 additions & 0 deletions tests/resources/billing/test_journal_attachments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import pytest

from mpt_api_client.resources.billing.journal_attachments import (
AsyncJournalAttachmentsService,
JournalAttachmentsService,
)


@pytest.fixture
def journal_attachments_service(http_client) -> JournalAttachmentsService:
return JournalAttachmentsService(
http_client=http_client, endpoint_params={"journal_id": "JRN-0000-0001"}
)


@pytest.fixture
def async_journal_attachments_service(async_http_client) -> AsyncJournalAttachmentsService:
return AsyncJournalAttachmentsService(
http_client=async_http_client, endpoint_params={"journal_id": "JRN-0000-0001"}
)


def test_endpoint(journal_attachments_service) -> None:
assert (
journal_attachments_service.endpoint
== "/public/v1/billing/journals/JRN-0000-0001/attachments"
)


def test_async_endpoint(async_journal_attachments_service) -> None:
assert (
async_journal_attachments_service.endpoint
== "/public/v1/billing/journals/JRN-0000-0001/attachments"
)


@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
def test_methods_present(journal_attachments_service, method: str) -> None:
assert hasattr(journal_attachments_service, method)


@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
def test_async_methods_present(async_journal_attachments_service, method: str) -> None:
assert hasattr(async_journal_attachments_service, method)
30 changes: 30 additions & 0 deletions tests/resources/billing/test_journals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import pytest

from mpt_api_client.resources.billing.journal_attachments import (
AsyncJournalAttachmentsService,
JournalAttachmentsService,
)
from mpt_api_client.resources.billing.journals import AsyncJournalsService, JournalsService


Expand Down Expand Up @@ -27,3 +31,29 @@ def test_mixins_present(journals_service, method):
)
def test_async_mixins_present(async_journals_service, method):
assert hasattr(async_journals_service, method)


@pytest.mark.parametrize(
("service_method", "expected_service_class"),
[
("attachments", JournalAttachmentsService),
],
)
def test_property_services(journals_service, service_method, expected_service_class):
service = getattr(journals_service, service_method)("JRN-0000-0001")

assert isinstance(service, expected_service_class)
assert service.endpoint_params == {"journal_id": "JRN-0000-0001"}


@pytest.mark.parametrize(
("service_method", "expected_service_class"),
[
("attachments", AsyncJournalAttachmentsService),
],
)
def test_async_property_services(async_journals_service, service_method, expected_service_class):
service = getattr(async_journals_service, service_method)("JRN-0000-0001")

assert isinstance(service, expected_service_class)
assert service.endpoint_params == {"journal_id": "JRN-0000-0001"}