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
28 changes: 28 additions & 0 deletions mpt_api_client/resources/billing/journal_charges.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.models import Model


class JournalCharge(Model):
"""Journal Charge resource."""


class JournalChargesServiceConfig:
"""Journal Charges service configuration."""

_endpoint = "/public/v1/billing/journals/{journal_id}/charges"
_model_class = JournalCharge
_collection_key = "data"


class JournalChargesService(
Service[JournalCharge],
JournalChargesServiceConfig,
):
"""Journal Charges service."""


class AsyncJournalChargesService(
AsyncService[JournalCharge],
JournalChargesServiceConfig,
):
"""Async Journal Charges service."""
16 changes: 16 additions & 0 deletions mpt_api_client/resources/billing/journals.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
AsyncJournalAttachmentsService,
JournalAttachmentsService,
)
from mpt_api_client.resources.billing.journal_charges import (
AsyncJournalChargesService,
JournalChargesService,
)
from mpt_api_client.resources.billing.journal_sellers import (
AsyncJournalSellersService,
JournalSellersService,
Expand Down Expand Up @@ -53,6 +57,12 @@ def sellers(self, journal_id: str) -> JournalSellersService:
http_client=self.http_client, endpoint_params={"journal_id": journal_id}
)

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


class AsyncJournalsService(
AsyncCreateMixin[Journal],
Expand All @@ -76,3 +86,9 @@ def sellers(self, journal_id: str) -> AsyncJournalSellersService:
return AsyncJournalSellersService(
http_client=self.http_client, endpoint_params={"journal_id": journal_id}
)

def charges(self, journal_id: str) -> AsyncJournalChargesService:
"""Return journal charges service."""
return AsyncJournalChargesService(
http_client=self.http_client, endpoint_params={"journal_id": journal_id}
)
42 changes: 42 additions & 0 deletions mpt_api_client/resources/billing/ledger_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 LedgerAttachment(Model):
"""Ledger Attachment resource."""


class LedgerAttachmentsServiceConfig:
"""Ledger Attachments service configuration."""

_endpoint = "/public/v1/billing/ledgers/{ledger_id}/attachments"
_model_class = LedgerAttachment
_collection_key = "data"


class LedgerAttachmentsService(
FileOperationsMixin[LedgerAttachment],
DeleteMixin,
UpdateMixin[LedgerAttachment],
Service[LedgerAttachment],
LedgerAttachmentsServiceConfig,
):
"""Ledger Attachments service."""


class AsyncLedgerAttachmentsService(
AsyncFileOperationsMixin[LedgerAttachment],
AsyncDeleteMixin,
AsyncUpdateMixin[LedgerAttachment],
AsyncService[LedgerAttachment],
LedgerAttachmentsServiceConfig,
):
"""Ledger Attachments service."""
18 changes: 18 additions & 0 deletions mpt_api_client/resources/billing/ledgers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
CreateMixin,
)
from mpt_api_client.models import Model
from mpt_api_client.resources.billing.ledger_attachments import (
AsyncLedgerAttachmentsService,
LedgerAttachmentsService,
)
from mpt_api_client.resources.billing.ledger_charges import (
AsyncLedgerChargesService,
LedgerChargesService,
Expand Down Expand Up @@ -36,6 +40,13 @@ def charges(self, ledger_id: str) -> LedgerChargesService:
endpoint_params={"ledger_id": ledger_id},
)

def attachments(self, ledger_id: str) -> LedgerAttachmentsService:
"""Return ledger attachments service."""
return LedgerAttachmentsService(
http_client=self.http_client,
endpoint_params={"ledger_id": ledger_id},
)


class AsyncLedgersService(
AsyncCreateMixin[Ledger],
Expand All @@ -50,3 +61,10 @@ def charges(self, ledger_id: str) -> AsyncLedgerChargesService:
http_client=self.http_client,
endpoint_params={"ledger_id": ledger_id},
)

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

from mpt_api_client.resources.billing.journal_charges import (
AsyncJournalChargesService,
JournalChargesService,
)


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


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


def test_endpoint(journal_charges_service):
assert journal_charges_service.endpoint == "/public/v1/billing/journals/JRN-0000-0001/charges"


def test_async_endpoint(async_journal_charges_service):
assert async_journal_charges_service.endpoint == (
"/public/v1/billing/journals/JRN-0000-0001/charges"
)


@pytest.mark.parametrize("method", ["get"])
def test_methods_present(journal_charges_service, method):
assert hasattr(journal_charges_service, method)


@pytest.mark.parametrize("method", ["get"])
def test_async_methods_present(async_journal_charges_service, method):
assert hasattr(async_journal_charges_service, method)
6 changes: 6 additions & 0 deletions tests/resources/billing/test_journals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
AsyncJournalAttachmentsService,
JournalAttachmentsService,
)
from mpt_api_client.resources.billing.journal_charges import (
AsyncJournalChargesService,
JournalChargesService,
)
from mpt_api_client.resources.billing.journal_sellers import (
AsyncJournalSellersService,
JournalSellersService,
Expand Down Expand Up @@ -42,6 +46,7 @@ def test_async_mixins_present(async_journals_service, method):
[
("attachments", JournalAttachmentsService),
("sellers", JournalSellersService),
("charges", JournalChargesService),
],
)
def test_property_services(journals_service, service_method, expected_service_class):
Expand All @@ -56,6 +61,7 @@ def test_property_services(journals_service, service_method, expected_service_cl
[
("attachments", AsyncJournalAttachmentsService),
("sellers", AsyncJournalSellersService),
("charges", AsyncJournalChargesService),
],
)
def test_async_property_services(async_journals_service, service_method, expected_service_class):
Expand Down
44 changes: 44 additions & 0 deletions tests/resources/billing/test_ledger_attachments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import pytest

from mpt_api_client.resources.billing.ledger_attachments import (
AsyncLedgerAttachmentsService,
LedgerAttachmentsService,
)


@pytest.fixture
def ledger_attachments_service(http_client) -> LedgerAttachmentsService:
return LedgerAttachmentsService(
http_client=http_client, endpoint_params={"ledger_id": "LED-0000-0001"}
)


@pytest.fixture
def async_ledger_attachments_service(async_http_client) -> AsyncLedgerAttachmentsService:
return AsyncLedgerAttachmentsService(
http_client=async_http_client, endpoint_params={"ledger_id": "LED-0000-0001"}
)


def test_endpoint(ledger_attachments_service) -> None:
assert (
ledger_attachments_service.endpoint
== "/public/v1/billing/ledgers/LED-0000-0001/attachments"
)


def test_async_endpoint(async_ledger_attachments_service) -> None:
assert (
async_ledger_attachments_service.endpoint
== "/public/v1/billing/ledgers/LED-0000-0001/attachments"
)


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


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

from mpt_api_client.resources.billing.ledger_attachments import (
AsyncLedgerAttachmentsService,
LedgerAttachmentsService,
)
from mpt_api_client.resources.billing.ledger_charges import (
AsyncLedgerChargesService,
LedgerChargesService,
Expand Down Expand Up @@ -37,6 +41,7 @@ def test_async_mixins_present(async_ledgers_service, method):
("service_method", "expected_service_class"),
[
("charges", LedgerChargesService),
("attachments", LedgerAttachmentsService),
],
)
def test_property_services(ledgers_service, service_method, expected_service_class):
Expand All @@ -50,6 +55,7 @@ def test_property_services(ledgers_service, service_method, expected_service_cla
("service_method", "expected_service_class"),
[
("charges", AsyncLedgerChargesService),
("attachments", AsyncLedgerAttachmentsService),
],
)
def test_async_property_services(async_ledgers_service, service_method, expected_service_class):
Expand Down