Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion mpt_api_client/mpt_client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
from typing import Self

from mpt_api_client.http import AsyncHTTPClient, HTTPClient
from mpt_api_client.resources import AsyncCatalog, AsyncCommerce, Catalog, Commerce
from mpt_api_client.resources import (
AsyncAudit,
AsyncBilling,
AsyncCatalog,
AsyncCommerce,
Audit,
Billing,
Catalog,
Commerce,
)


class AsyncMPTClient:
Expand Down Expand Up @@ -37,6 +46,16 @@ def commerce(self) -> AsyncCommerce:
"""Commerce MPT API Client."""
return AsyncCommerce(http_client=self.http_client)

@property
def audit(self) -> AsyncAudit:
"""Audit MPT API Client."""
return AsyncAudit(http_client=self.http_client)

@property
def billing(self) -> AsyncBilling:
"""Billing MPT API Client."""
return AsyncBilling(http_client=self.http_client)


class MPTClient:
"""MPT API Client."""
Expand Down Expand Up @@ -75,3 +94,13 @@ def commerce(self) -> Commerce:
def catalog(self) -> Catalog:
"""Catalog MPT API Client."""
return Catalog(http_client=self.http_client)

@property
def audit(self) -> Audit:
"""Audit MPT API Client."""
return Audit(http_client=self.http_client)

@property
def billing(self) -> Billing:
"""Billing MPT API Client."""
return Billing(http_client=self.http_client)
13 changes: 12 additions & 1 deletion mpt_api_client/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
from mpt_api_client.resources.audit import AsyncAudit, Audit
from mpt_api_client.resources.billing import AsyncBilling, Billing
from mpt_api_client.resources.catalog import AsyncCatalog, Catalog
from mpt_api_client.resources.commerce import AsyncCommerce, Commerce

__all__ = ["AsyncCatalog", "AsyncCommerce", "Catalog", "Commerce"] # noqa: WPS410
__all__ = [ # noqa: WPS410
"AsyncAudit",
"AsyncBilling",
"AsyncCatalog",
"AsyncCommerce",
"Audit",
"Billing",
"Catalog",
"Commerce",
]
3 changes: 3 additions & 0 deletions mpt_api_client/resources/audit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from mpt_api_client.resources.audit.audit import AsyncAudit, Audit

__all__ = ["AsyncAudit", "Audit"] # noqa: WPS410
14 changes: 14 additions & 0 deletions mpt_api_client/resources/audit/audit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
from mpt_api_client.resources.audit.event_types import (
AsyncEventTypesService,
EventTypesService,
)
from mpt_api_client.resources.audit.records import AsyncRecordsService, RecordsService


Expand All @@ -13,6 +17,11 @@ def records(self) -> RecordsService:
"""Records service."""
return RecordsService(http_client=self.http_client)

@property
def event_types(self) -> EventTypesService:
"""Event Types service."""
return EventTypesService(http_client=self.http_client)


class AsyncAudit:
"""Async Audit MPT API Module."""
Expand All @@ -24,3 +33,8 @@ def __init__(self, *, http_client: AsyncHTTPClient):
def records(self) -> AsyncRecordsService:
"""Records service."""
return AsyncRecordsService(http_client=self.http_client)

@property
def event_types(self) -> AsyncEventTypesService:
"""Event Types service."""
return AsyncEventTypesService(http_client=self.http_client)
28 changes: 28 additions & 0 deletions mpt_api_client/resources/audit/event_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.http.mixins import (
AsyncUpdateMixin,
UpdateMixin,
)
from mpt_api_client.models import Model


class EventType(Model):
"""Event Type resource."""


class EventTypesServiceConfig:
"""Event Types service configuration."""

_endpoint = "/public/v1/audit/event-types"
_model_class = EventType
_collection_key = "data"


class EventTypesService(UpdateMixin[EventType], Service[EventType], EventTypesServiceConfig):
"""Event Types service."""


class AsyncEventTypesService(
AsyncUpdateMixin[EventType], AsyncService[EventType], EventTypesServiceConfig
):
"""Async Event Types service."""
3 changes: 3 additions & 0 deletions mpt_api_client/resources/billing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from mpt_api_client.resources.billing.billing import AsyncBilling, Billing

__all__ = ["AsyncBilling", "Billing"] # noqa: WPS410
3 changes: 3 additions & 0 deletions tests/resources/audit/test_audit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from mpt_api_client.resources.audit.audit import AsyncAudit, Audit
from mpt_api_client.resources.audit.event_types import AsyncEventTypesService, EventTypesService
from mpt_api_client.resources.audit.records import AsyncRecordsService, RecordsService


Expand All @@ -18,6 +19,7 @@ def async_audit(async_http_client):
("property_name", "expected_service_class"),
[
("records", RecordsService),
("event_types", EventTypesService),
],
)
def test_audit_properties(audit, property_name, expected_service_class):
Expand All @@ -32,6 +34,7 @@ def test_audit_properties(audit, property_name, expected_service_class):
("property_name", "expected_service_class"),
[
("records", AsyncRecordsService),
("event_types", AsyncEventTypesService),
],
)
def test_async_audit_properties(async_audit, property_name, expected_service_class):
Expand Down
23 changes: 23 additions & 0 deletions tests/resources/audit/test_event_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pytest

from mpt_api_client.resources.audit.event_types import AsyncEventTypesService, EventTypesService


@pytest.fixture
def event_types_service(http_client):
return EventTypesService(http_client=http_client)


@pytest.fixture
def async_event_types_service(async_http_client):
return AsyncEventTypesService(http_client=async_http_client)


@pytest.mark.parametrize("method", ["get", "update"])
def test_mixins_present(event_types_service, method):
assert hasattr(event_types_service, method)


@pytest.mark.parametrize("method", ["get", "update"])
def test_async_mixins_present(async_event_types_service, method):
assert hasattr(async_event_types_service, method)
19 changes: 18 additions & 1 deletion tests/test_mpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,31 @@

from mpt_api_client.http import AsyncHTTPClient, HTTPClient
from mpt_api_client.mpt_client import AsyncMPTClient, MPTClient
from mpt_api_client.resources import AsyncCatalog, AsyncCommerce, Catalog, Commerce
from mpt_api_client.resources import (
AsyncAudit,
AsyncBilling,
AsyncCatalog,
AsyncCommerce,
Audit,
Billing,
Catalog,
Commerce,
)
from tests.conftest import API_TOKEN, API_URL


def test_mpt_client() -> None:
mpt = MPTClient.from_config(base_url=API_URL, api_token=API_TOKEN)
commerce = mpt.commerce
catalog = mpt.catalog
audit = mpt.audit
billing = mpt.billing

assert isinstance(mpt, MPTClient)
assert isinstance(commerce, Commerce)
assert isinstance(catalog, Catalog)
assert isinstance(audit, Audit)
assert isinstance(billing, Billing)


def test_mpt_client_env(monkeypatch: pytest.MonkeyPatch) -> None:
Expand All @@ -30,10 +43,14 @@ def test_async_mpt_client() -> None:
mpt = AsyncMPTClient.from_config(base_url=API_URL, api_token=API_TOKEN)
commerce = mpt.commerce
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is better to make the test parametrized instead of multiple asserts :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is better to make the test parametrized instead of multiple asserts :-)

I can update this test on my next PR. I'm adding Accounts, so I can make this parametrized when I update this test. Have to update it anyway.

catalog = mpt.catalog
audit = mpt.audit
billing = mpt.billing

assert isinstance(mpt, AsyncMPTClient)
assert isinstance(commerce, AsyncCommerce)
assert isinstance(catalog, AsyncCatalog)
assert isinstance(audit, AsyncAudit)
assert isinstance(billing, AsyncBilling)


def test_async_mpt_client_env(monkeypatch: pytest.MonkeyPatch) -> None:
Expand Down