Skip to content

Commit 34b5574

Browse files
author
Robert Segal
committed
Added billing journals endpoints
1 parent 3524b0b commit 34b5574

File tree

10 files changed

+402
-0
lines changed

10 files changed

+402
-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: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
from mpt_api_client.models import ResourceData
2+
3+
4+
class RegeneratableMixin[Model]:
5+
"""Regeneratable mixin adds the ability to regenerate resources."""
6+
7+
def regenerate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
8+
"""Regenerate resource.
9+
10+
Args:
11+
resource_id: Resource ID
12+
resource_data: Resource data will be updated
13+
"""
14+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
15+
resource_id, "POST", "regenerate", json=resource_data
16+
)
17+
18+
def submit(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
19+
"""Submit resource.
20+
21+
Args:
22+
resource_id: Resource ID
23+
resource_data: Resource data will be updated
24+
"""
25+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
26+
resource_id, "POST", "submit", json=resource_data
27+
)
28+
29+
def enquiry(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
30+
"""Enquiry resource.
31+
32+
Args:
33+
resource_id: Resource ID
34+
resource_data: Resource data will be updated
35+
"""
36+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
37+
resource_id, "POST", "enquiry", json=resource_data
38+
)
39+
40+
def accept(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
41+
"""Accept resource.
42+
43+
Args:
44+
resource_id: Resource ID
45+
resource_data: Resource data will be updated
46+
"""
47+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
48+
resource_id, "POST", "accept", json=resource_data
49+
)
50+
51+
52+
class AsyncRegeneratableMixin[Model]:
53+
"""Regeneratable mixin adds the ability to regenerate resources."""
54+
55+
async def regenerate(
56+
self, resource_id: str, resource_data: ResourceData | None = None
57+
) -> Model:
58+
"""Regenerate resource.
59+
60+
Args:
61+
resource_id: Resource ID
62+
resource_data: Resource data will be updated
63+
"""
64+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
65+
resource_id, "POST", "regenerate", json=resource_data
66+
)
67+
68+
async def submit(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
69+
"""Submit resource.
70+
71+
Args:
72+
resource_id: Resource ID
73+
resource_data: Resource data will be updated
74+
"""
75+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
76+
resource_id, "POST", "submit", json=resource_data
77+
)
78+
79+
async def enquiry(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
80+
"""Enquiry resource.
81+
82+
Args:
83+
resource_id: Resource ID
84+
resource_data: Resource data will be updated
85+
"""
86+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
87+
resource_id, "POST", "enquiry", json=resource_data
88+
)
89+
90+
async def accept(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
91+
"""Accept resource.
92+
93+
Args:
94+
resource_id: Resource ID
95+
resource_data: Resource data will be updated
96+
"""
97+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
98+
resource_id, "POST", "accept", json=resource_data
99+
)

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)