Skip to content

Commit 78a3edf

Browse files
author
Robert Segal
committed
Added billing journals endpoints
1 parent 3524b0b commit 78a3edf

File tree

10 files changed

+422
-0
lines changed

10 files changed

+422
-0
lines changed

mpt_api_client/resources/billing/__init__.py

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
2+
from mpt_api_client.resources.billing.journals import AsyncJournalsService, JournalsService
3+
4+
5+
class Billing:
6+
"""Billing MPT API Module."""
7+
8+
def __init__(self, *, http_client: HTTPClient):
9+
self.http_client = http_client
10+
11+
@property
12+
def journals(self) -> JournalsService:
13+
"""Journals service."""
14+
return JournalsService(http_client=self.http_client)
15+
16+
17+
class AsyncBilling:
18+
"""Billing MPT API Module."""
19+
20+
def __init__(self, *, http_client: AsyncHTTPClient):
21+
self.http_client = http_client
22+
23+
@property
24+
def journals(self) -> AsyncJournalsService:
25+
"""Journals service."""
26+
return AsyncJournalsService(http_client=self.http_client)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from mpt_api_client.http import AsyncService, CreateMixin, Service
2+
from mpt_api_client.http.mixins import (
3+
AsyncCreateMixin,
4+
AsyncDeleteMixin,
5+
AsyncUpdateMixin,
6+
DeleteMixin,
7+
UpdateMixin,
8+
)
9+
from mpt_api_client.models import Model
10+
from mpt_api_client.resources.billing.mixins import AsyncRegeneratableMixin, RegeneratableMixin
11+
12+
13+
class Journal(Model):
14+
"""Journal resource."""
15+
16+
17+
class JournalsServiceConfig:
18+
"""Journals service configuration."""
19+
20+
_endpoint = "/public/v1/billing/journals"
21+
_model_class = Journal
22+
_collection_key = "data"
23+
24+
25+
class JournalsService(
26+
CreateMixin[Journal],
27+
DeleteMixin,
28+
UpdateMixin[Journal],
29+
RegeneratableMixin[Journal],
30+
Service[Journal],
31+
JournalsServiceConfig,
32+
):
33+
"""Journals service."""
34+
35+
36+
class AsyncJournalsService(
37+
AsyncCreateMixin[Journal],
38+
AsyncDeleteMixin,
39+
AsyncUpdateMixin[Journal],
40+
AsyncRegeneratableMixin[Journal],
41+
AsyncService[Journal],
42+
JournalsServiceConfig,
43+
):
44+
"""Async Journals service."""
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
from mpt_api_client.models import ResourceData
2+
3+
4+
# TODO: Consider moving Regeneratable mixins to http/mixins if publishable and activatable are moved
5+
class RegeneratableMixin[Model]:
6+
"""Regeneratable mixin adds the ability to regenerate resources."""
7+
8+
def regenerate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
9+
"""Regenerate resource.
10+
11+
Args:
12+
resource_id: Resource ID
13+
resource_data: Resource data will be updated
14+
"""
15+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
16+
resource_id, "POST", "regenerate", json=resource_data
17+
)
18+
19+
def submit(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
20+
"""Submit resource.
21+
22+
Args:
23+
resource_id: Resource ID
24+
resource_data: Resource data will be updated
25+
"""
26+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
27+
resource_id, "POST", "submit", json=resource_data
28+
)
29+
30+
def enquiry(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
31+
"""Enquiry resource.
32+
33+
Args:
34+
resource_id: Resource ID
35+
resource_data: Resource data will be updated
36+
"""
37+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
38+
resource_id, "POST", "enquiry", json=resource_data
39+
)
40+
41+
def accept(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
42+
"""Accept resource.
43+
44+
Args:
45+
resource_id: Resource ID
46+
resource_data: Resource data will be updated
47+
"""
48+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
49+
resource_id, "POST", "accept", json=resource_data
50+
)
51+
52+
53+
class AsyncRegeneratableMixin[Model]:
54+
"""Regeneratable mixin adds the ability to regenerate resources."""
55+
56+
async def regenerate(
57+
self, resource_id: str, resource_data: ResourceData | None = None
58+
) -> Model:
59+
"""Regenerate resource.
60+
61+
Args:
62+
resource_id: Resource ID
63+
resource_data: Resource data will be updated
64+
"""
65+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
66+
resource_id, "POST", "regenerate", json=resource_data
67+
)
68+
69+
async def submit(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
70+
"""Submit resource.
71+
72+
Args:
73+
resource_id: Resource ID
74+
resource_data: Resource data will be updated
75+
"""
76+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
77+
resource_id, "POST", "submit", json=resource_data
78+
)
79+
80+
async def enquiry(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
81+
"""Enquiry resource.
82+
83+
Args:
84+
resource_id: Resource ID
85+
resource_data: Resource data will be updated
86+
"""
87+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
88+
resource_id, "POST", "enquiry", json=resource_data
89+
)
90+
91+
async def accept(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
92+
"""Accept resource.
93+
94+
Args:
95+
resource_id: Resource ID
96+
resource_data: Resource data will be updated
97+
"""
98+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
99+
resource_id, "POST", "accept", json=resource_data
100+
)

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ extend-ignore =
3232

3333

3434
per-file-ignores =
35+
mpt_api_client/resources/billing/*.py: WPS215
3536
mpt_api_client/resources/catalog/*.py: WPS110 WPS215 WPS214
3637
mpt_api_client/resources/commerce/*.py: WPS215
3738
mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214

tests/resources/billing/__init__.py

Whitespace-only changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.billing.billing import AsyncBilling, Billing
4+
from mpt_api_client.resources.billing.journals import AsyncJournalsService, JournalsService
5+
6+
7+
@pytest.fixture
8+
def billing(http_client):
9+
return Billing(http_client=http_client)
10+
11+
12+
@pytest.fixture
13+
def async_billing(async_http_client):
14+
return AsyncBilling(http_client=async_http_client)
15+
16+
17+
@pytest.mark.parametrize(
18+
("property_name", "expected_service_class"),
19+
[
20+
("journals", JournalsService),
21+
],
22+
)
23+
def test_billing_properties(billing, property_name, expected_service_class):
24+
"""Test that Billing properties return correct instances."""
25+
service = getattr(billing, property_name)
26+
27+
assert isinstance(service, expected_service_class)
28+
assert service.http_client is billing.http_client
29+
30+
31+
@pytest.mark.parametrize(
32+
("property_name", "expected_service_class"),
33+
[
34+
("journals", AsyncJournalsService),
35+
],
36+
)
37+
def test_async_billing_properties(async_billing, property_name, expected_service_class):
38+
"""Test that AsyncBilling properties return correct instances."""
39+
service = getattr(async_billing, property_name)
40+
41+
assert isinstance(service, expected_service_class)
42+
assert service.http_client is async_billing.http_client
43+
44+
45+
def test_billing_initialization(http_client):
46+
billing = Billing(http_client=http_client)
47+
48+
assert billing.http_client is http_client
49+
assert isinstance(billing, Billing)
50+
51+
52+
def test_async_billing_initialization(async_http_client):
53+
async_billing = AsyncBilling(http_client=async_http_client)
54+
55+
assert async_billing.http_client is async_http_client
56+
assert isinstance(async_billing, AsyncBilling)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.billing.journals import AsyncJournalsService, JournalsService
4+
5+
6+
@pytest.fixture
7+
def journals_service(http_client):
8+
return JournalsService(http_client=http_client)
9+
10+
11+
@pytest.fixture
12+
def async_journals_service(async_http_client):
13+
return AsyncJournalsService(http_client=async_http_client)
14+
15+
16+
@pytest.mark.parametrize(
17+
"method",
18+
["get", "create", "update", "delete"],
19+
)
20+
def test_mixins_present(journals_service, method):
21+
assert hasattr(journals_service, method)
22+
23+
24+
@pytest.mark.parametrize(
25+
"method",
26+
["get", "create", "update", "delete"],
27+
)
28+
def test_async_mixins_present(async_journals_service, method):
29+
assert hasattr(async_journals_service, method)

0 commit comments

Comments
 (0)