Skip to content

Commit be531e6

Browse files
author
Robert Segal
committed
Added billing invoice attachments endpoints
1 parent 2f888d9 commit be531e6

File tree

4 files changed

+134
-0
lines changed

4 files changed

+134
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from mpt_api_client.http import AsyncService, Service
2+
from mpt_api_client.http.mixins import (
3+
AsyncDeleteMixin,
4+
AsyncFileOperationsMixin,
5+
AsyncUpdateMixin,
6+
DeleteMixin,
7+
FileOperationsMixin,
8+
UpdateMixin,
9+
)
10+
from mpt_api_client.models import Model
11+
12+
13+
class InvoiceAttachment(Model):
14+
"""Invoice Attachment resource."""
15+
16+
17+
class InvoiceAttachmentsServiceConfig:
18+
"""Invoice Attachments service configuration."""
19+
20+
_endpoint = "/public/v1/billing/invoices/{invoice_id}/attachments"
21+
_model_class = InvoiceAttachment
22+
_collection_key = "data"
23+
24+
25+
class InvoiceAttachmentsService(
26+
FileOperationsMixin[InvoiceAttachment],
27+
DeleteMixin,
28+
UpdateMixin[InvoiceAttachment],
29+
Service[InvoiceAttachment],
30+
InvoiceAttachmentsServiceConfig,
31+
):
32+
"""Invoice Attachments service."""
33+
34+
35+
class AsyncInvoiceAttachmentsService(
36+
AsyncFileOperationsMixin[InvoiceAttachment],
37+
AsyncDeleteMixin,
38+
AsyncUpdateMixin[InvoiceAttachment],
39+
AsyncService[InvoiceAttachment],
40+
InvoiceAttachmentsServiceConfig,
41+
):
42+
"""Invoice Attachments service."""

mpt_api_client/resources/billing/invoices.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from mpt_api_client.http import AsyncService, Service
22
from mpt_api_client.http.mixins import AsyncCreateMixin, AsyncUpdateMixin, CreateMixin, UpdateMixin
33
from mpt_api_client.models import Model
4+
from mpt_api_client.resources.billing.invoice_attachments import (
5+
AsyncInvoiceAttachmentsService,
6+
InvoiceAttachmentsService,
7+
)
48

59

610
class Invoice(Model):
@@ -23,6 +27,13 @@ class InvoicesService(
2327
):
2428
"""Invoices service."""
2529

30+
def attachments(self, invoice_id: str) -> InvoiceAttachmentsService:
31+
"""Return invoice attachments service."""
32+
return InvoiceAttachmentsService(
33+
http_client=self.http_client,
34+
endpoint_params={"invoice_id": invoice_id},
35+
)
36+
2637

2738
class AsyncInvoicesService(
2839
AsyncCreateMixin[Invoice],
@@ -31,3 +42,10 @@ class AsyncInvoicesService(
3142
InvoicesServiceConfig,
3243
):
3344
"""Async Invoices service."""
45+
46+
def attachments(self, invoice_id: str) -> AsyncInvoiceAttachmentsService:
47+
"""Return invoice attachments service."""
48+
return AsyncInvoiceAttachmentsService(
49+
http_client=self.http_client,
50+
endpoint_params={"invoice_id": invoice_id},
51+
)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.billing.invoice_attachments import (
4+
AsyncInvoiceAttachmentsService,
5+
InvoiceAttachmentsService,
6+
)
7+
8+
9+
@pytest.fixture
10+
def invoice_attachments_service(http_client) -> InvoiceAttachmentsService:
11+
return InvoiceAttachmentsService(
12+
http_client=http_client, endpoint_params={"invoice_id": "INV-0000-0001"}
13+
)
14+
15+
16+
@pytest.fixture
17+
def async_invoice_attachments_service(async_http_client) -> AsyncInvoiceAttachmentsService:
18+
return AsyncInvoiceAttachmentsService(
19+
http_client=async_http_client, endpoint_params={"invoice_id": "INV-0000-0001"}
20+
)
21+
22+
23+
def test_endpoint(invoice_attachments_service) -> None:
24+
assert (
25+
invoice_attachments_service.endpoint
26+
== "/public/v1/billing/invoices/INV-0000-0001/attachments"
27+
)
28+
29+
30+
def test_async_endpoint(async_invoice_attachments_service) -> None:
31+
assert (
32+
async_invoice_attachments_service.endpoint
33+
== "/public/v1/billing/invoices/INV-0000-0001/attachments"
34+
)
35+
36+
37+
@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
38+
def test_methods_present(invoice_attachments_service, method: str) -> None:
39+
assert hasattr(invoice_attachments_service, method)
40+
41+
42+
@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
43+
def test_async_methods_present(async_invoice_attachments_service, method: str) -> None:
44+
assert hasattr(async_invoice_attachments_service, method)

tests/resources/billing/test_invoices.py

Lines changed: 30 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.invoice_attachments import (
4+
AsyncInvoiceAttachmentsService,
5+
InvoiceAttachmentsService,
6+
)
37
from mpt_api_client.resources.billing.invoices import (
48
AsyncInvoicesService,
59
InvoicesService,
@@ -30,3 +34,29 @@ def test_mixins_present(invoices_service, method):
3034
)
3135
def test_async_mixins_present(async_invoices_service, method):
3236
assert hasattr(async_invoices_service, method)
37+
38+
39+
@pytest.mark.parametrize(
40+
("service_method", "expected_service_class"),
41+
[
42+
("attachments", InvoiceAttachmentsService),
43+
],
44+
)
45+
def test_property_services(invoices_service, service_method, expected_service_class):
46+
service = getattr(invoices_service, service_method)("INV-0000-0001")
47+
48+
assert isinstance(service, expected_service_class)
49+
assert service.endpoint_params == {"invoice_id": "INV-0000-0001"}
50+
51+
52+
@pytest.mark.parametrize(
53+
("service_method", "expected_service_class"),
54+
[
55+
("attachments", AsyncInvoiceAttachmentsService),
56+
],
57+
)
58+
def test_async_property_services(async_invoices_service, service_method, expected_service_class):
59+
service = getattr(async_invoices_service, service_method)("INV-0000-0001")
60+
61+
assert isinstance(service, expected_service_class)
62+
assert service.endpoint_params == {"invoice_id": "INV-0000-0001"}

0 commit comments

Comments
 (0)