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
19 changes: 13 additions & 6 deletions mpt_api_client/resources/notifications/accounts.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
from mpt_api_client.exceptions import MPTError
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.http.mixins import AsyncCollectionMixin, CollectionMixin
from mpt_api_client.models import Model


class MethodNotAllowedError(MPTError):
"""Method not allowed error."""


class Contact(Model):
"""Account resource."""
class NotificationContact(Model):
"""Notification Contact resource."""


class AccountsServiceConfig:
"""Accounts service config."""

_endpoint = "/public/v1/commerce/accounts/{account_id}/categories/{category_id}/contacts"
_model_class = Contact
_endpoint = "/public/v1/notifications/accounts/{account_id}/categories/{category_id}/contacts"
_model_class = NotificationContact
_collection_key = "data"


class AccountsService(Service[Contact], AccountsServiceConfig):
class AccountsService(
CollectionMixin[NotificationContact], Service[NotificationContact], AccountsServiceConfig
):
"""Accounts service."""


class AsyncAccountsService(AsyncService[Contact], AccountsServiceConfig):
class AsyncAccountsService(
AsyncCollectionMixin[NotificationContact],
AsyncService[NotificationContact],
AccountsServiceConfig,
):
"""Async Accounts service."""
8 changes: 8 additions & 0 deletions tests/e2e/notifications/accounts/test_async_accounts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
async def test_async_accounts(async_mpt_ops, account_id, category_id):
iterator = async_mpt_ops.notifications.accounts(
account_id=account_id, category_id=category_id
).iterate()

result = [contact async for contact in iterator]

assert isinstance(result, list)
8 changes: 8 additions & 0 deletions tests/e2e/notifications/accounts/test_sync_accounts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def test_accounts(mpt_ops, account_id, category_id):
iterator = mpt_ops.notifications.accounts(
account_id=account_id, category_id=category_id
).iterate()

result = list(iterator)

assert isinstance(result, list)
14 changes: 14 additions & 0 deletions tests/unit/resources/notifications/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,17 @@ def accounts_service(http_client):
@pytest.fixture
def async_accounts_service(async_http_client):
return AsyncAccountsService(http_client=async_http_client)


@pytest.mark.parametrize("method", ["iterate"])
def test_sync_accounts_service_methods(accounts_service, method):
result = hasattr(accounts_service, method)

assert result is True


@pytest.mark.parametrize("method", ["iterate"])
def test_async_accounts_service_methods(async_accounts_service, method):
result = hasattr(async_accounts_service, method)

assert result is True