Skip to content

Commit f7c99c2

Browse files
Robert Segald3rky
authored andcommitted
Added billing custom ledger charges endpoints
1 parent 14db8e2 commit f7c99c2

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-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 CustomLedgerCharge(Model):
6+
"""Custom Ledger Charge resource."""
7+
8+
9+
class CustomLedgerChargesServiceConfig:
10+
"""Custom Ledger Charges service configuration."""
11+
12+
_endpoint = "/public/v1/billing/custom-ledgers/{custom_ledger_id}/charges"
13+
_model_class = CustomLedgerCharge
14+
_collection_key = "data"
15+
16+
17+
class CustomLedgerChargesService(
18+
Service[CustomLedgerCharge],
19+
CustomLedgerChargesServiceConfig,
20+
):
21+
"""Custom Ledger Charges service."""
22+
23+
24+
class AsyncCustomLedgerChargesService(
25+
AsyncService[CustomLedgerCharge],
26+
CustomLedgerChargesServiceConfig,
27+
):
28+
"""Async Custom Ledger Charges service."""

mpt_api_client/resources/billing/custom_ledgers.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
UpdateMixin,
99
)
1010
from mpt_api_client.models import Model
11+
from mpt_api_client.resources.billing.custom_ledger_charges import (
12+
AsyncCustomLedgerChargesService,
13+
CustomLedgerChargesService,
14+
)
1115
from mpt_api_client.resources.billing.mixins import AcceptableMixin, AsyncAcceptableMixin
1216

1317

@@ -33,6 +37,13 @@ class CustomLedgersService(
3337
):
3438
"""Custom Ledgers service."""
3539

40+
def charges(self, custom_ledger_id: str) -> CustomLedgerChargesService:
41+
"""Return custom ledger charges service."""
42+
return CustomLedgerChargesService(
43+
http_client=self.http_client,
44+
endpoint_params={"custom_ledger_id": custom_ledger_id},
45+
)
46+
3647

3748
class AsyncCustomLedgersService(
3849
AsyncCreateMixin[CustomLedger],
@@ -43,3 +54,10 @@ class AsyncCustomLedgersService(
4354
CustomLedgersServiceConfig,
4455
):
4556
"""Async Custom Ledgers service."""
57+
58+
def charges(self, custom_ledger_id: str) -> AsyncCustomLedgerChargesService:
59+
"""Return custom ledger charges service."""
60+
return AsyncCustomLedgerChargesService(
61+
http_client=self.http_client,
62+
endpoint_params={"custom_ledger_id": custom_ledger_id},
63+
)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.billing.custom_ledger_charges import (
4+
AsyncCustomLedgerChargesService,
5+
CustomLedgerChargesService,
6+
)
7+
8+
9+
@pytest.fixture
10+
def custom_ledger_charges_service(http_client):
11+
return CustomLedgerChargesService(
12+
http_client=http_client, endpoint_params={"custom_ledger_id": "LDG-0000-0001"}
13+
)
14+
15+
16+
@pytest.fixture
17+
def async_custom_ledger_charges_service(async_http_client):
18+
return AsyncCustomLedgerChargesService(
19+
http_client=async_http_client, endpoint_params={"custom_ledger_id": "LDG-0000-0001"}
20+
)
21+
22+
23+
def test_endpoint(custom_ledger_charges_service):
24+
assert custom_ledger_charges_service.endpoint == (
25+
"/public/v1/billing/custom-ledgers/LDG-0000-0001/charges"
26+
)
27+
28+
29+
def test_async_endpoint(async_custom_ledger_charges_service):
30+
assert async_custom_ledger_charges_service.endpoint == (
31+
"/public/v1/billing/custom-ledgers/LDG-0000-0001/charges"
32+
)
33+
34+
35+
@pytest.mark.parametrize("method", ["get"])
36+
def test_methods_present(custom_ledger_charges_service, method):
37+
assert hasattr(custom_ledger_charges_service, method)
38+
39+
40+
@pytest.mark.parametrize("method", ["get"])
41+
def test_async_methods_present(async_custom_ledger_charges_service, method):
42+
assert hasattr(async_custom_ledger_charges_service, method)

tests/resources/billing/test_custom_ledgers.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import pytest
22

3+
from mpt_api_client.resources.billing.custom_ledger_charges import (
4+
AsyncCustomLedgerChargesService,
5+
CustomLedgerChargesService,
6+
)
37
from mpt_api_client.resources.billing.custom_ledgers import (
48
AsyncCustomLedgersService,
59
CustomLedgersService,
@@ -24,3 +28,31 @@ def test_mixins_present(custom_ledgers_service, method):
2428
@pytest.mark.parametrize("method", ["get", "create", "update", "delete", "accept", "queue"])
2529
def test_async_mixins_present(async_custom_ledgers_service, method):
2630
assert hasattr(async_custom_ledgers_service, method)
31+
32+
33+
@pytest.mark.parametrize(
34+
("service_method", "expected_service_class"),
35+
[
36+
("charges", CustomLedgerChargesService),
37+
],
38+
)
39+
def test_property_services(custom_ledgers_service, service_method, expected_service_class):
40+
service = getattr(custom_ledgers_service, service_method)("LDG-0000-0001")
41+
42+
assert isinstance(service, expected_service_class)
43+
assert service.endpoint_params == {"custom_ledger_id": "LDG-0000-0001"}
44+
45+
46+
@pytest.mark.parametrize(
47+
("service_method", "expected_service_class"),
48+
[
49+
("charges", AsyncCustomLedgerChargesService),
50+
],
51+
)
52+
def test_async_property_services(
53+
async_custom_ledgers_service, service_method, expected_service_class
54+
):
55+
service = getattr(async_custom_ledgers_service, service_method)("LDG-0000-0001")
56+
57+
assert isinstance(service, expected_service_class)
58+
assert service.endpoint_params == {"custom_ledger_id": "LDG-0000-0001"}

0 commit comments

Comments
 (0)