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


class JournalUpload(Model):
"""Journal Upload resource."""


class JournalUploadServiceConfig:
"""Journal Upload service configuration."""

_endpoint = "/public/v1/billing/journals/{journal_id}/upload"
_model_class = JournalUpload
_collection_key = "data"


class JournalUploadService(
FileOperationsMixin[JournalUpload],
Service[JournalUpload],
JournalUploadServiceConfig,
):
"""Journal Upload service."""


class AsyncJournalUploadService(
AsyncFileOperationsMixin[JournalUpload],
AsyncService[JournalUpload],
JournalUploadServiceConfig,
):
"""Journal Upload 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 @@ -19,6 +19,10 @@
AsyncJournalSellersService,
JournalSellersService,
)
from mpt_api_client.resources.billing.journal_upload import (
AsyncJournalUploadService,
JournalUploadService,
)
from mpt_api_client.resources.billing.mixins import AsyncRegeneratableMixin, RegeneratableMixin


Expand Down Expand Up @@ -63,6 +67,12 @@ def charges(self, journal_id: str) -> JournalChargesService:
http_client=self.http_client, endpoint_params={"journal_id": journal_id}
)

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


class AsyncJournalsService(
AsyncCreateMixin[Journal],
Expand Down Expand Up @@ -92,3 +102,9 @@ def charges(self, journal_id: str) -> AsyncJournalChargesService:
return AsyncJournalChargesService(
http_client=self.http_client, endpoint_params={"journal_id": journal_id}
)

def upload(self, journal_id: str) -> AsyncJournalUploadService:
"""Return journal upload service."""
return AsyncJournalUploadService(
http_client=self.http_client, endpoint_params={"journal_id": journal_id}
)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extend-ignore =


per-file-ignores =
mpt_api_client/resources/billing/*.py: WPS215 WPS202 WPS214
mpt_api_client/resources/billing/*.py: WPS215 WPS202 WPS214 WPS204
mpt_api_client/resources/catalog/*.py: WPS110 WPS215 WPS214
mpt_api_client/resources/commerce/*.py: WPS215
mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214
Expand Down
40 changes: 40 additions & 0 deletions tests/resources/billing/test_journal_upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import pytest

from mpt_api_client.resources.billing.journal_upload import (
AsyncJournalUploadService,
JournalUploadService,
)


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


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


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


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


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


@pytest.mark.parametrize("method", ["create"])
def test_async_methods_present(async_journal_upload_service, method: str) -> None:
assert hasattr(async_journal_upload_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 @@ -12,6 +12,10 @@
AsyncJournalSellersService,
JournalSellersService,
)
from mpt_api_client.resources.billing.journal_upload import (
AsyncJournalUploadService,
JournalUploadService,
)
from mpt_api_client.resources.billing.journals import AsyncJournalsService, JournalsService


Expand Down Expand Up @@ -47,6 +51,7 @@ def test_async_mixins_present(async_journals_service, method):
("attachments", JournalAttachmentsService),
("sellers", JournalSellersService),
("charges", JournalChargesService),
("upload", JournalUploadService),
],
)
def test_property_services(journals_service, service_method, expected_service_class):
Expand All @@ -62,6 +67,7 @@ def test_property_services(journals_service, service_method, expected_service_cl
("attachments", AsyncJournalAttachmentsService),
("sellers", AsyncJournalSellersService),
("charges", AsyncJournalChargesService),
("upload", AsyncJournalUploadService),
],
)
def test_async_property_services(async_journals_service, service_method, expected_service_class):
Expand Down