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
Empty file.
26 changes: 26 additions & 0 deletions mpt_api_client/resources/billing/billing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
from mpt_api_client.resources.billing.journals import AsyncJournalsService, JournalsService


class Billing:
"""Billing MPT API Module."""

def __init__(self, *, http_client: HTTPClient):
self.http_client = http_client

@property
def journals(self) -> JournalsService:
"""Journals service."""
return JournalsService(http_client=self.http_client)


class AsyncBilling:
"""Billing MPT API Module."""

def __init__(self, *, http_client: AsyncHTTPClient):
self.http_client = http_client

@property
def journals(self) -> AsyncJournalsService:
"""Journals service."""
return AsyncJournalsService(http_client=self.http_client)
44 changes: 44 additions & 0 deletions mpt_api_client/resources/billing/journals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from mpt_api_client.http import AsyncService, CreateMixin, Service
from mpt_api_client.http.mixins import (
AsyncCreateMixin,
AsyncDeleteMixin,
AsyncUpdateMixin,
DeleteMixin,
UpdateMixin,
)
from mpt_api_client.models import Model
from mpt_api_client.resources.billing.mixins import AsyncRegeneratableMixin, RegeneratableMixin


class Journal(Model):
"""Journal resource."""


class JournalsServiceConfig:
"""Journals service configuration."""

_endpoint = "/public/v1/billing/journals"
_model_class = Journal
_collection_key = "data"


class JournalsService(
CreateMixin[Journal],
DeleteMixin,
UpdateMixin[Journal],
RegeneratableMixin[Journal],
Service[Journal],
JournalsServiceConfig,
):
"""Journals service."""


class AsyncJournalsService(
AsyncCreateMixin[Journal],
AsyncDeleteMixin,
AsyncUpdateMixin[Journal],
AsyncRegeneratableMixin[Journal],
AsyncService[Journal],
JournalsServiceConfig,
):
"""Async Journals service."""
100 changes: 100 additions & 0 deletions mpt_api_client/resources/billing/mixins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from mpt_api_client.models import ResourceData


# TODO: Consider moving Regeneratable mixins to http/mixins if publishable and activatable are moved
class RegeneratableMixin[Model]:
"""Regeneratable mixin adds the ability to regenerate resources."""

def regenerate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Regenerate 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", "regenerate", json=resource_data
)

def submit(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Submit 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", "submit", json=resource_data
)

def enquiry(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Enquiry 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", "enquiry", json=resource_data
)

def accept(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Accept 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", "accept", json=resource_data
)


class AsyncRegeneratableMixin[Model]:
"""Regeneratable mixin adds the ability to regenerate resources."""

async def regenerate(
self, resource_id: str, resource_data: ResourceData | None = None
) -> Model:
"""Regenerate 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", "regenerate", json=resource_data
)

async def submit(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Submit 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", "submit", json=resource_data
)

async def enquiry(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Enquiry 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", "enquiry", json=resource_data
)

async def accept(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Accept 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", "accept", json=resource_data
)
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extend-ignore =


per-file-ignores =
mpt_api_client/resources/billing/*.py: WPS215
mpt_api_client/resources/catalog/*.py: WPS110 WPS215 WPS214
mpt_api_client/resources/commerce/*.py: WPS215
mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214
Expand Down
Empty file.
56 changes: 56 additions & 0 deletions tests/resources/billing/test_billing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import pytest

from mpt_api_client.resources.billing.billing import AsyncBilling, Billing
from mpt_api_client.resources.billing.journals import AsyncJournalsService, JournalsService


@pytest.fixture
def billing(http_client):
return Billing(http_client=http_client)


@pytest.fixture
def async_billing(async_http_client):
return AsyncBilling(http_client=async_http_client)


@pytest.mark.parametrize(
("property_name", "expected_service_class"),
[
("journals", JournalsService),
],
)
def test_billing_properties(billing, property_name, expected_service_class):
"""Test that Billing properties return correct instances."""
service = getattr(billing, property_name)

assert isinstance(service, expected_service_class)
assert service.http_client is billing.http_client


@pytest.mark.parametrize(
("property_name", "expected_service_class"),
[
("journals", AsyncJournalsService),
],
)
def test_async_billing_properties(async_billing, property_name, expected_service_class):
"""Test that AsyncBilling properties return correct instances."""
service = getattr(async_billing, property_name)

assert isinstance(service, expected_service_class)
assert service.http_client is async_billing.http_client


def test_billing_initialization(http_client):
billing = Billing(http_client=http_client)

assert billing.http_client is http_client
assert isinstance(billing, Billing)


def test_async_billing_initialization(async_http_client):
async_billing = AsyncBilling(http_client=async_http_client)

assert async_billing.http_client is async_http_client
assert isinstance(async_billing, AsyncBilling)
29 changes: 29 additions & 0 deletions tests/resources/billing/test_journals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest

from mpt_api_client.resources.billing.journals import AsyncJournalsService, JournalsService


@pytest.fixture
def journals_service(http_client):
return JournalsService(http_client=http_client)


@pytest.fixture
def async_journals_service(async_http_client):
return AsyncJournalsService(http_client=async_http_client)


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


@pytest.mark.parametrize(
"method",
["get", "create", "update", "delete"],
)
def test_async_mixins_present(async_journals_service, method):
assert hasattr(async_journals_service, method)
Loading