Skip to content

Commit 498c0b1

Browse files
author
Robert Segal
committed
Added billing journal charges endpoint
1 parent 8a8cce3 commit 498c0b1

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from mpt_api_client.http import AsyncService, Service
2+
from mpt_api_client.models import Model
3+
4+
5+
class JournalCharge(Model):
6+
"""Journal Charge resource."""
7+
8+
9+
class JournalChargesServiceConfig:
10+
"""Journal Charges service configuration."""
11+
12+
_endpoint = "/public/v1/billing/journals/{journal_id}/charges"
13+
_model_class = JournalCharge
14+
_collection_key = "data"
15+
16+
17+
class JournalChargesService(
18+
Service[JournalCharge],
19+
JournalChargesServiceConfig,
20+
):
21+
"""Journal Charges service."""
22+
23+
24+
class AsyncJournalChargesService(
25+
AsyncService[JournalCharge],
26+
JournalChargesServiceConfig,
27+
):
28+
"""Async Journal Charges service."""

mpt_api_client/resources/billing/journals.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
AsyncJournalAttachmentsService,
1212
JournalAttachmentsService,
1313
)
14+
from mpt_api_client.resources.billing.journal_charges import (
15+
AsyncJournalChargesService,
16+
JournalChargesService,
17+
)
1418
from mpt_api_client.resources.billing.journal_sellers import (
1519
AsyncJournalSellersService,
1620
JournalSellersService,
@@ -53,6 +57,12 @@ def sellers(self, journal_id: str) -> JournalSellersService:
5357
http_client=self.http_client, endpoint_params={"journal_id": journal_id}
5458
)
5559

60+
def charges(self, journal_id: str) -> JournalChargesService:
61+
"""Return journal charges service."""
62+
return JournalChargesService(
63+
http_client=self.http_client, endpoint_params={"journal_id": journal_id}
64+
)
65+
5666

5767
class AsyncJournalsService(
5868
AsyncCreateMixin[Journal],
@@ -76,3 +86,9 @@ def sellers(self, journal_id: str) -> AsyncJournalSellersService:
7686
return AsyncJournalSellersService(
7787
http_client=self.http_client, endpoint_params={"journal_id": journal_id}
7888
)
89+
90+
def charges(self, journal_id: str) -> AsyncJournalChargesService:
91+
"""Return journal charges service."""
92+
return AsyncJournalChargesService(
93+
http_client=self.http_client, endpoint_params={"journal_id": journal_id}
94+
)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.billing.journal_charges import (
4+
AsyncJournalChargesService,
5+
JournalChargesService,
6+
)
7+
8+
9+
@pytest.fixture
10+
def journal_charges_service(http_client):
11+
return JournalChargesService(
12+
http_client=http_client, endpoint_params={"journal_id": "JRN-0000-0001"}
13+
)
14+
15+
16+
@pytest.fixture
17+
def async_journal_charges_service(async_http_client):
18+
return AsyncJournalChargesService(
19+
http_client=async_http_client, endpoint_params={"journal_id": "JRN-0000-0001"}
20+
)
21+
22+
23+
def test_endpoint(journal_charges_service):
24+
assert journal_charges_service.endpoint == "/public/v1/billing/journals/JRN-0000-0001/charges"
25+
26+
27+
def test_async_endpoint(async_journal_charges_service):
28+
assert async_journal_charges_service.endpoint == (
29+
"/public/v1/billing/journals/JRN-0000-0001/charges"
30+
)
31+
32+
33+
@pytest.mark.parametrize("method", ["get"])
34+
def test_methods_present(journal_charges_service, method):
35+
assert hasattr(journal_charges_service, method)
36+
37+
38+
@pytest.mark.parametrize("method", ["get"])
39+
def test_async_methods_present(async_journal_charges_service, method):
40+
assert hasattr(async_journal_charges_service, method)

tests/resources/billing/test_journals.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
AsyncJournalAttachmentsService,
55
JournalAttachmentsService,
66
)
7+
from mpt_api_client.resources.billing.journal_charges import (
8+
AsyncJournalChargesService,
9+
JournalChargesService,
10+
)
711
from mpt_api_client.resources.billing.journal_sellers import (
812
AsyncJournalSellersService,
913
JournalSellersService,
@@ -42,6 +46,7 @@ def test_async_mixins_present(async_journals_service, method):
4246
[
4347
("attachments", JournalAttachmentsService),
4448
("sellers", JournalSellersService),
49+
("charges", JournalChargesService),
4550
],
4651
)
4752
def test_property_services(journals_service, service_method, expected_service_class):
@@ -56,6 +61,7 @@ def test_property_services(journals_service, service_method, expected_service_cl
5661
[
5762
("attachments", AsyncJournalAttachmentsService),
5863
("sellers", AsyncJournalSellersService),
64+
("charges", AsyncJournalChargesService),
5965
],
6066
)
6167
def test_async_property_services(async_journals_service, service_method, expected_service_class):

0 commit comments

Comments
 (0)