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
1 change: 1 addition & 0 deletions e2e_config.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@
"commerce.subscription.agreement.id": "AGR-2473-3299-1721",
"commerce.subscription.id": "SUB-3678-1831-2188",
"commerce.subscription.product.item.id": "ITM-1767-7355-0001",
"notifications.subscriber.id": "NTS-0829-7123-7123",
"notifications.message.id": "MSG-0000-6215-1019-0139"
}
40 changes: 40 additions & 0 deletions mpt_api_client/http/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,46 @@ async def get(self, resource_id: str, select: list[str] | str | None = None) ->
return await self._resource_action(resource_id=resource_id, query_params={"select": select}) # type: ignore[attr-defined, no-any-return]


class AsyncEnableMixin[Model: BaseModel]:
"""Enable resource mixin."""

async def enable(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Enable a specific resource."""
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
resource_id=resource_id, method="POST", action="enable", json=resource_data
)


class EnableMixin[Model: BaseModel]:
"""Enable resource mixin."""

def enable(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Enable a specific resource."""
return self._resource_action( # type: ignore[attr-defined, no-any-return]
resource_id=resource_id, method="POST", action="enable", json=resource_data
)


class AsyncDisableMixin[Model: BaseModel]:
"""Disable resource mixin."""

async def disable(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Disable a specific resource."""
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
resource_id=resource_id, method="POST", action="disable", json=resource_data
)


class DisableMixin[Model: BaseModel]:
"""Disable resource mixin."""

def disable(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Disable a specific resource ."""
return self._resource_action( # type: ignore[attr-defined, no-any-return]
resource_id=resource_id, method="POST", action="disable", json=resource_data
)


class QueryableMixin:
"""Mixin providing query functionality for filtering, ordering, and selecting fields."""

Expand Down
12 changes: 8 additions & 4 deletions mpt_api_client/resources/accounts/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
from mpt_api_client.http.mixins import (
AsyncCollectionMixin,
AsyncCreateFileMixin,
AsyncDisableMixin,
AsyncEnableMixin,
AsyncGetMixin,
AsyncUpdateFileMixin,
CollectionMixin,
CreateFileMixin,
DisableMixin,
EnableMixin,
GetMixin,
UpdateFileMixin,
)
Expand All @@ -17,9 +21,7 @@
from mpt_api_client.resources.accounts.mixins import (
ActivatableMixin,
AsyncActivatableMixin,
AsyncEnablableMixin,
AsyncValidateMixin,
EnablableMixin,
ValidateMixin,
)

Expand All @@ -42,7 +44,8 @@ class AccountsService(
CreateFileMixin[Account],
UpdateFileMixin[Account],
ActivatableMixin[Account],
EnablableMixin[Account],
EnableMixin[Account],
DisableMixin[Account],
ValidateMixin[Account],
GetMixin[Account],
CollectionMixin[Account],
Expand All @@ -62,7 +65,8 @@ class AsyncAccountsService(
AsyncCreateFileMixin[Account],
AsyncUpdateFileMixin[Account],
AsyncActivatableMixin[Account],
AsyncEnablableMixin[Account],
AsyncEnableMixin[Account],
AsyncDisableMixin[Account],
AsyncValidateMixin[Account],
AsyncGetMixin[Account],
AsyncCollectionMixin[Account],
Expand Down
11 changes: 8 additions & 3 deletions mpt_api_client/resources/accounts/api_tokens.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.http.mixins import (
AsyncCollectionMixin,
AsyncDisableMixin,
AsyncEnableMixin,
AsyncManagedResourceMixin,
CollectionMixin,
DisableMixin,
EnableMixin,
ManagedResourceMixin,
)
from mpt_api_client.models import Model
from mpt_api_client.resources.accounts.mixins import AsyncEnablableMixin, EnablableMixin


class ApiToken(Model):
Expand All @@ -23,7 +26,8 @@ class ApiTokensServiceConfig:

class ApiTokensService(
ManagedResourceMixin[ApiToken],
EnablableMixin[ApiToken],
EnableMixin[ApiToken],
DisableMixin[ApiToken],
CollectionMixin[ApiToken],
Service[ApiToken],
ApiTokensServiceConfig,
Expand All @@ -33,7 +37,8 @@ class ApiTokensService(

class AsyncApiTokensService(
AsyncManagedResourceMixin[ApiToken],
AsyncEnablableMixin[ApiToken],
AsyncEnableMixin[ApiToken],
AsyncDisableMixin[ApiToken],
AsyncCollectionMixin[ApiToken],
AsyncService[ApiToken],
ApiTokensServiceConfig,
Expand Down
12 changes: 8 additions & 4 deletions mpt_api_client/resources/accounts/buyers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
AsyncCollectionMixin,
AsyncCreateFileMixin,
AsyncDeleteMixin,
AsyncDisableMixin,
AsyncEnableMixin,
AsyncGetMixin,
AsyncUpdateFileMixin,
CollectionMixin,
CreateFileMixin,
DeleteMixin,
DisableMixin,
EnableMixin,
GetMixin,
UpdateFileMixin,
)
Expand All @@ -16,9 +20,7 @@
from mpt_api_client.resources.accounts.mixins import (
ActivatableMixin,
AsyncActivatableMixin,
AsyncEnablableMixin,
AsyncValidateMixin,
EnablableMixin,
ValidateMixin,
)

Expand All @@ -41,7 +43,8 @@ class BuyersService(
CreateFileMixin[Buyer],
UpdateFileMixin[Buyer],
ActivatableMixin[Buyer],
EnablableMixin[Buyer],
EnableMixin[Buyer],
DisableMixin[Buyer],
ValidateMixin[Buyer],
GetMixin[Buyer],
DeleteMixin,
Expand Down Expand Up @@ -74,7 +77,8 @@ class AsyncBuyersService(
AsyncCreateFileMixin[Buyer],
AsyncUpdateFileMixin[Buyer],
AsyncActivatableMixin[Buyer],
AsyncEnablableMixin[Buyer],
AsyncEnableMixin[Buyer],
AsyncDisableMixin[Buyer],
AsyncValidateMixin[Buyer],
AsyncGetMixin[Buyer],
AsyncDeleteMixin,
Expand Down
14 changes: 8 additions & 6 deletions mpt_api_client/resources/accounts/licensees.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
AsyncCollectionMixin,
AsyncCreateFileMixin,
AsyncDeleteMixin,
AsyncDisableMixin,
AsyncEnableMixin,
AsyncGetMixin,
AsyncUpdateFileMixin,
CollectionMixin,
CreateFileMixin,
DeleteMixin,
DisableMixin,
EnableMixin,
GetMixin,
UpdateFileMixin,
)
from mpt_api_client.models import Model
from mpt_api_client.resources.accounts.mixins import (
AsyncEnablableMixin,
EnablableMixin,
)


class Licensee(Model):
Expand All @@ -35,7 +35,8 @@ class LicenseesServiceConfig:
class LicenseesService(
CreateFileMixin[Licensee],
UpdateFileMixin[Licensee],
EnablableMixin[Licensee],
EnableMixin[Licensee],
DisableMixin[Licensee],
GetMixin[Licensee],
DeleteMixin,
CollectionMixin[Licensee],
Expand All @@ -48,7 +49,8 @@ class LicenseesService(
class AsyncLicenseesService(
AsyncCreateFileMixin[Licensee],
AsyncUpdateFileMixin[Licensee],
AsyncEnablableMixin[Licensee],
AsyncEnableMixin[Licensee],
AsyncDisableMixin[Licensee],
AsyncGetMixin[Licensee],
AsyncDeleteMixin,
AsyncCollectionMixin[Licensee],
Expand Down
52 changes: 0 additions & 52 deletions mpt_api_client/resources/accounts/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,6 @@ def deactivate(self, resource_id: str, resource_data: ResourceData | None = None
)


class EnablableMixin[Model]:
"""Enablable mixin for enabling and disabling resources."""

def enable(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Enable a resource.

Args:
resource_id: Resource ID
resource_data: Resource data will be updated
"""
return self._resource_action( # type: ignore[attr-defined, no-any-return]
resource_id, "POST", "enable", json=resource_data
)

def disable(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Disable a resource.

Args:
resource_id: Resource ID
resource_data: Resource data will be updated
"""
return self._resource_action( # type: ignore[attr-defined, no-any-return]
resource_id, "POST", "disable", json=resource_data
)


class ValidateMixin[Model]:
"""Validate mixin adds the ability to validate a resource."""

Expand Down Expand Up @@ -159,32 +133,6 @@ async def deactivate(
)


class AsyncEnablableMixin[Model]:
"""Asynchronous Enablable mixin for enabling and disabling resources."""

async def enable(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Enable a resource.

Args:
resource_id: Resource ID
resource_data: Resource data will be updated
"""
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
resource_id, "POST", "enable", json=resource_data
)

async def disable(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Disable a resource.

Args:
resource_id: Resource ID
resource_data: Resource data will be updated
"""
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
resource_id, "POST", "disable", json=resource_data
)


class AsyncValidateMixin[Model]:
"""Asynchronous Validate mixin adds the ability to validate a resource."""

Expand Down
8 changes: 8 additions & 0 deletions mpt_api_client/resources/notifications/subscribers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.http.mixins import (
AsyncCollectionMixin,
AsyncDisableMixin,
AsyncEnableMixin,
AsyncManagedResourceMixin,
CollectionMixin,
DisableMixin,
EnableMixin,
ManagedResourceMixin,
)
from mpt_api_client.models import Model
Expand All @@ -21,6 +25,8 @@ class SubscribersServiceConfig:


class SubscribersService(
EnableMixin[Subscriber],
DisableMixin[Subscriber],
ManagedResourceMixin[Subscriber],
CollectionMixin[Subscriber],
Service[Subscriber],
Expand All @@ -30,6 +36,8 @@ class SubscribersService(


class AsyncSubscribersService(
AsyncEnableMixin[Subscriber],
AsyncDisableMixin[Subscriber],
AsyncManagedResourceMixin[Subscriber],
AsyncCollectionMixin[Subscriber],
AsyncService[Subscriber],
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,8 @@ def authorization_id(e2e_config):
@pytest.fixture
def price_list_id(e2e_config):
return e2e_config["catalog.price_list.id"]


@pytest.fixture
def user_group_id(e2e_config):
return e2e_config["accounts.user_group.id"]
Empty file.
64 changes: 64 additions & 0 deletions tests/e2e/notifications/subscribers/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import pytest

from mpt_api_client.exceptions import MPTAPIError


@pytest.fixture
def subscriber_id(e2e_config):
return e2e_config.get("notifications.subscriber.id")


@pytest.fixture
def invalid_subscriber_id():
return "NTS-0000-0000-0000"


@pytest.fixture
def recipients_factory(user_id, user_group_id):
def _recipients( # noqa: WPS430
users: list | None = None,
user_groups: list | None = None,
) -> dict:
return {
"users": users or [{"id": user_id}],
"userGroups": user_groups or [{"id": user_group_id}],
}

return _recipients


@pytest.fixture
def subscriber_factory(recipients_factory):
def _subscriber( # noqa: WPS430
recipients: dict | None = None,
note: str = "Test note",
) -> dict:
return {
"recipients": recipients or recipients_factory(),
"note": note,
}

return _subscriber


@pytest.fixture
def disabled_subscriber_id(mpt_client, subscriber_id):
subscriber = mpt_client.notifications.subscribers.get(subscriber_id)
if subscriber.status != "Disabled":
subscriber = mpt_client.notifications.subscribers.disable(subscriber_id)

yield subscriber.id

try:
mpt_client.notifications.subscribers.enable(subscriber_id)
except MPTAPIError:
print(f"TEARDOWN - Unable to re-enable subscriber {subscriber_id=}") # noqa: WPS421


@pytest.fixture
def active_subscriber_id(mpt_client, subscriber_id):
subscriber = mpt_client.notifications.subscribers.get(subscriber_id)
if subscriber.status != "Active":
subscriber = mpt_client.notifications.subscribers.enable(subscriber_id)

return subscriber.id
Loading