From 4cab9ee1da7476accc8ed969175e9feddb4de5c7 Mon Sep 17 00:00:00 2001 From: Albert Sola Date: Thu, 16 Oct 2025 18:02:11 +0100 Subject: [PATCH] MPT-14532 Cleanup base service --- mpt_api_client/http/async_service.py | 4 +- mpt_api_client/http/base_service.py | 102 ++------------- mpt_api_client/http/mixins.py | 84 +++++++++++- mpt_api_client/http/query_state.py | 72 +++++++++++ mpt_api_client/http/service.py | 4 +- .../resources/notifications/batches.py | 8 +- tests/http/test_async_service.py | 19 +-- tests/http/test_base_service.py | 122 +++++++----------- tests/http/test_mixins.py | 104 +++++++++++++-- tests/http/test_query_state.py | 49 +++++++ tests/http/test_service.py | 18 +-- .../accounts/test_account_user_groups.py | 4 +- .../accounts/test_accounts_user_groups.py | 4 +- .../resources/accounts/test_accounts_users.py | 4 +- .../billing/test_credit_memo_attachments.py | 4 +- .../billing/test_custom_ledger_attachments.py | 4 +- .../billing/test_custom_ledger_charges.py | 4 +- .../billing/test_custom_ledger_upload.py | 4 +- .../billing/test_invoice_attachments.py | 5 +- .../billing/test_journal_attachments.py | 5 +- .../resources/billing/test_journal_charges.py | 4 +- .../resources/billing/test_journal_sellers.py | 7 +- .../resources/billing/test_journal_upload.py | 6 +- .../billing/test_ledger_attachments.py | 7 +- .../resources/billing/test_ledger_charges.py | 6 +- .../billing/test_statement_charges.py | 6 +- .../catalog/test_price_list_items.py | 4 +- .../test_pricing_policy_attachments.py | 4 +- .../catalog/test_product_term_variants.py | 6 +- tests/resources/catalog/test_product_terms.py | 4 +- .../catalog/test_products_documents.py | 4 +- .../catalog/test_products_item_groups.py | 4 +- .../resources/catalog/test_products_media.py | 4 +- .../catalog/test_products_parameter_groups.py | 6 +- .../catalog/test_products_parameters.py | 4 +- .../catalog/test_products_templates.py | 4 +- .../commerce/test_agreements_attachments.py | 4 +- .../commerce/test_order_subcription.py | 4 +- 38 files changed, 429 insertions(+), 283 deletions(-) create mode 100644 mpt_api_client/http/query_state.py create mode 100644 tests/http/test_query_state.py diff --git a/mpt_api_client/http/async_service.py b/mpt_api_client/http/async_service.py index 1e19df8b..77d4cd1e 100644 --- a/mpt_api_client/http/async_service.py +++ b/mpt_api_client/http/async_service.py @@ -85,7 +85,7 @@ async def _fetch_page_as_response(self, limit: int = 100, offset: int = 0) -> Re HTTPStatusError: if the response status code is not 200. """ pagination_params: dict[str, int] = {"limit": limit, "offset": offset} - return await self.http_client.request("get", self.build_url(pagination_params)) + return await self.http_client.request("get", self.build_path(pagination_params)) async def _resource_do_request( # noqa: WPS211 self, @@ -112,7 +112,7 @@ async def _resource_do_request( # noqa: WPS211 Raises: HTTPError: If the action fails. """ - resource_url = urljoin(f"{self.endpoint}/", resource_id) + resource_url = urljoin(f"{self.path}/", resource_id) url = urljoin(f"{resource_url}/", action) if action else resource_url return await self.http_client.request( method, url, json=json, query_params=query_params, headers=headers diff --git a/mpt_api_client/http/base_service.py b/mpt_api_client/http/base_service.py index d37558ea..8d456175 100644 --- a/mpt_api_client/http/base_service.py +++ b/mpt_api_client/http/base_service.py @@ -1,13 +1,13 @@ -import copy -from typing import Any, Self +from typing import Any +from mpt_api_client.http.mixins import QueryableMixin +from mpt_api_client.http.query_state import QueryState from mpt_api_client.http.types import Response from mpt_api_client.models import Collection, Meta from mpt_api_client.models import Model as BaseModel -from mpt_api_client.rql import RQLQuery -class ServiceBase[Client, Model: BaseModel]: # noqa: WPS214 +class ServiceBase[Client, Model: BaseModel](QueryableMixin): # noqa: WPS214 """Service base with agnostic HTTP client.""" _endpoint: str @@ -18,107 +18,29 @@ def __init__( self, *, http_client: Client, - query_rql: RQLQuery | None = None, - query_order_by: list[str] | None = None, - query_select: list[str] | None = None, + query_state: QueryState | None = None, endpoint_params: dict[str, str] | None = None, ) -> None: self.http_client = http_client - self.query_rql: RQLQuery | None = query_rql - self.query_order_by = query_order_by - self.query_select = query_select + self.query_state = query_state or QueryState() self.endpoint_params = endpoint_params or {} - def clone(self) -> Self: - """Create a copy of collection client for immutable operations. - - Returns: - New collection client with same settings. - """ - return type(self)( - http_client=self.http_client, - query_rql=self.query_rql, - query_order_by=copy.copy(self.query_order_by) if self.query_order_by else None, - query_select=copy.copy(self.query_select) if self.query_select else None, - endpoint_params=self.endpoint_params, - ) - @property - def endpoint(self) -> str: + def path(self) -> str: """Service endpoint URL.""" return self._endpoint.format(**self.endpoint_params) - def build_url( + def build_path( self, query_params: dict[str, Any] | None = None, - ) -> str: # noqa: WPS210 + ) -> str: """Builds the endpoint URL with all the query parameters. Returns: - Partial URL with query parameters. + Complete URL with query parameters. """ - query_params = query_params or {} - if self.query_order_by: - query_params.update({"order": ",".join(self.query_order_by)}) - if self.query_select: - query_params.update({"select": ",".join(self.query_select)}) - - query_parts = [ - f"{param_key}={param_value}" for param_key, param_value in query_params.items() - ] - - if self.query_rql: - query_parts.append(str(self.query_rql)) - - if query_parts: - query = "&".join(query_parts) - return f"{self.endpoint}?{query}" - return self.endpoint - - def order_by(self, *fields: str) -> Self: - """Returns new collection with ordering setup. - - Returns: - New collection with ordering setup. - - Raises: - ValueError: If ordering has already been set. - """ - if self.query_order_by is not None: - raise ValueError("Ordering is already set. Cannot set ordering multiple times.") - new_collection = self.clone() - new_collection.query_order_by = list(fields) - return new_collection - - def filter(self, rql: RQLQuery) -> Self: - """Creates a new collection with the filter added to the filter collection. - - Returns: - New copy of the collection with the filter added. - """ - if self.query_rql: - rql = self.query_rql & rql - new_collection = self.clone() - new_collection.query_rql = rql - return new_collection - - def select(self, *fields: str) -> Self: - """Set select fields. Raises ValueError if select fields are already set. - - Returns: - New copy of the collection with the select fields set. - - Raises: - ValueError: If select fields are already set. - """ - if self.query_select is not None: - raise ValueError( - "Select fields are already set. Cannot set select fields multiple times." - ) - - new_client = self.clone() - new_client.query_select = list(fields) - return new_client + query = self.query_state.build(query_params) + return f"{self.path}?{query}" if query else self.path @classmethod def _create_collection(cls, response: Response) -> Collection[Model]: diff --git a/mpt_api_client/http/mixins.py b/mpt_api_client/http/mixins.py index 04d28ab2..75aaaf25 100644 --- a/mpt_api_client/http/mixins.py +++ b/mpt_api_client/http/mixins.py @@ -1,8 +1,11 @@ import json +from typing import Self from urllib.parse import urljoin +from mpt_api_client.http.query_state import QueryState from mpt_api_client.http.types import FileTypes, Response from mpt_api_client.models import FileModel, ResourceData +from mpt_api_client.rql import RQLQuery def _json_to_file_payload(resource_data: ResourceData) -> bytes: @@ -20,7 +23,7 @@ def create(self, resource_data: ResourceData) -> Model: Returns: New resource created. """ - response = self.http_client.request("post", self.endpoint, json=resource_data) # type: ignore[attr-defined] + response = self.http_client.request("post", self.path, json=resource_data) # type: ignore[attr-defined] return self._model_class.from_response(response) # type: ignore[attr-defined, no-any-return] @@ -82,7 +85,7 @@ def create( "application/json", ) - response = self.http_client.request("post", self.endpoint, files=files) # type: ignore[attr-defined] + response = self.http_client.request("post", self.path, files=files) # type: ignore[attr-defined] return self._model_class.from_response(response) # type: ignore[attr-defined, no-any-return] @@ -110,7 +113,7 @@ async def create(self, resource_data: ResourceData) -> Model: Returns: New resource created. """ - response = await self.http_client.request("post", self.endpoint, json=resource_data) # type: ignore[attr-defined] + response = await self.http_client.request("post", self.path, json=resource_data) # type: ignore[attr-defined] return self._model_class.from_response(response) # type: ignore[attr-defined, no-any-return] @@ -124,7 +127,7 @@ async def delete(self, resource_id: str) -> None: Args: resource_id: Resource ID. """ - url = urljoin(f"{self.endpoint}/", resource_id) # type: ignore[attr-defined] + url = urljoin(f"{self.path}/", resource_id) # type: ignore[attr-defined] await self.http_client.request("delete", url) # type: ignore[attr-defined] @@ -173,7 +176,7 @@ async def create( "application/json", ) - response = await self.http_client.request("post", self.endpoint, files=files) # type: ignore[attr-defined] + response = await self.http_client.request("post", self.path, files=files) # type: ignore[attr-defined] return self._model_class.from_response(response) # type: ignore[attr-defined, no-any-return] @@ -227,3 +230,74 @@ async def get(self, resource_id: str, select: list[str] | str | None = None) -> if isinstance(select, list): select = ",".join(select) if select else None return await self._resource_action(resource_id=resource_id, query_params={"select": select}) # type: ignore[attr-defined, no-any-return] + + +class QueryableMixin: + """Mixin providing query functionality for filtering, ordering, and selecting fields.""" + + def order_by(self, *fields: str) -> Self: + """Returns new collection with ordering setup. + + Returns: + New collection with ordering setup. + + Raises: + ValueError: If ordering has already been set. + """ + if self.query_state.order_by is not None: # type: ignore[attr-defined] + raise ValueError("Ordering is already set. Cannot set ordering multiple times.") + return self._create_new_instance( + query_state=QueryState( + rql=self.query_state.filter, # type: ignore[attr-defined] + order_by=list(fields), + select=self.query_state.select, # type: ignore[attr-defined] + ) + ) + + def filter(self, rql: RQLQuery) -> Self: + """Creates a new collection with the filter added to the filter collection. + + Returns: + New copy of the collection with the filter added. + """ + existing_filter = self.query_state.filter # type: ignore[attr-defined] + combined_filter = existing_filter & rql if existing_filter else rql + return self._create_new_instance( + QueryState( + rql=combined_filter, + order_by=self.query_state.order_by, # type: ignore[attr-defined] + select=self.query_state.select, # type: ignore[attr-defined] + ) + ) + + def select(self, *fields: str) -> Self: + """Set select fields. Raises ValueError if select fields are already set. + + Returns: + New copy of the collection with the select fields set. + + Raises: + ValueError: If select fields are already set. + """ + if self.query_state.select is not None: # type: ignore[attr-defined] + raise ValueError( + "Select fields are already set. Cannot set select fields multiple times." + ) + return self._create_new_instance( + QueryState( + rql=self.query_state.filter, # type: ignore[attr-defined] + order_by=self.query_state.order_by, # type: ignore[attr-defined] + select=list(fields), + ), + ) + + def _create_new_instance( + self, + query_state: QueryState, + ) -> Self: + """Create a new instance with the given parameters.""" + return self.__class__( + http_client=self.http_client, # type: ignore[call-arg,attr-defined] + query_state=query_state, + endpoint_params=self.endpoint_params, # type: ignore[attr-defined] + ) diff --git a/mpt_api_client/http/query_state.py b/mpt_api_client/http/query_state.py new file mode 100644 index 00000000..04c530e5 --- /dev/null +++ b/mpt_api_client/http/query_state.py @@ -0,0 +1,72 @@ +from typing import Any + +from mpt_api_client.rql import RQLQuery + + +class QueryState: + """Stores and manages API query state for filtering, selecting, and ordering data. + + This class maintains the current state of query parameters (filter, order_by, select) + and provides functionality to build query strings from that state. It's responsible + for both storing query configuration and constructing the appropriate query parameters + that modify the behavior and shape of data returned by the API. + """ + + def __init__( + self, + rql: RQLQuery | None = None, + order_by: list[str] | None = None, + select: list[str] | None = None, + ) -> None: + """Initialize the query state with optional filter, ordering, and selection criteria. + + Args: + rql: RQL query for filtering data. + order_by: List of fields to order by (prefix with '-' for descending). + select: List of fields to select in the response. + """ + self._filter = rql + self._order_by = order_by + self._select = select + + @property + def filter(self) -> RQLQuery | None: + """Get the current filter query.""" + return self._filter + + @property + def order_by(self) -> list[str] | None: + """Get the current order by fields.""" + return self._order_by + + @property + def select(self) -> list[str] | None: + """Get the current select fields.""" + return self._select + + def build(self, query_params: dict[str, Any] | None = None) -> str: + """Build a query string from the current state and additional parameters. + + Args: + query_params: Additional query parameters to include in the query string. + + Returns: + Complete query string with all parameters, or empty string if no parameters. + """ + query_params = query_params or {} + if self._order_by: + query_params.update({"order": ",".join(self._order_by)}) + if self._select: + query_params.update({"select": ",".join(self._select)}) + + query_parts = [ + f"{param_key}={param_value}" for param_key, param_value in query_params.items() + ] + + if self._filter: + query_parts.append(str(self._filter)) + + if query_parts: + query = "&".join(query_parts) + return f"{query}" + return "" diff --git a/mpt_api_client/http/service.py b/mpt_api_client/http/service.py index 33be4827..999edc93 100644 --- a/mpt_api_client/http/service.py +++ b/mpt_api_client/http/service.py @@ -84,7 +84,7 @@ def _fetch_page_as_response(self, limit: int = 100, offset: int = 0) -> Response HTTPStatusError: if the response status code is not 200. """ pagination_params: dict[str, int] = {"limit": limit, "offset": offset} - return self.http_client.request("get", self.build_url(pagination_params)) + return self.http_client.request("get", self.build_path(pagination_params)) def _resource_do_request( # noqa: WPS211 self, @@ -111,7 +111,7 @@ def _resource_do_request( # noqa: WPS211 Raises: HTTPError: If the action fails. """ - resource_url = urljoin(f"{self.endpoint}/", resource_id) + resource_url = urljoin(f"{self.path}/", resource_id) url = urljoin(f"{resource_url}/", action) if action else resource_url return self.http_client.request( method, url, json=json, query_params=query_params, headers=headers diff --git a/mpt_api_client/resources/notifications/batches.py b/mpt_api_client/resources/notifications/batches.py index 8d053c8f..5c89ff54 100644 --- a/mpt_api_client/resources/notifications/batches.py +++ b/mpt_api_client/resources/notifications/batches.py @@ -49,7 +49,7 @@ def create( "application/json", ) - response = self.http_client.request("post", self.endpoint, files=files) + response = self.http_client.request("post", self.path, files=files) return self._model_class.from_response(response) def get_batch_attachment(self, batch_id: str, attachment_id: str) -> FileModel: @@ -63,7 +63,7 @@ def get_batch_attachment(self, batch_id: str, attachment_id: str) -> FileModel: FileModel containing the attachment. """ response = self.http_client.request( - "get", f"{self.endpoint}/{batch_id}/attachments/{attachment_id}" + "get", f"{self.path}/{batch_id}/attachments/{attachment_id}" ) return FileModel(response) @@ -101,7 +101,7 @@ async def create( "application/json", ) - response = await self.http_client.request("post", self.endpoint, files=files) + response = await self.http_client.request("post", self.path, files=files) return self._model_class.from_response(response) async def get_batch_attachment(self, batch_id: str, attachment_id: str) -> FileModel: @@ -115,6 +115,6 @@ async def get_batch_attachment(self, batch_id: str, attachment_id: str) -> FileM FileModel containing the attachment. """ response = await self.http_client.request( - "get", f"{self.endpoint}/{batch_id}/attachments/{attachment_id}" + "get", f"{self.path}/{batch_id}/attachments/{attachment_id}" ) return FileModel(response) diff --git a/tests/http/test_async_service.py b/tests/http/test_async_service.py index 34bd6d06..f8fa36d2 100644 --- a/tests/http/test_async_service.py +++ b/tests/http/test_async_service.py @@ -3,6 +3,7 @@ import respx from mpt_api_client.exceptions import MPTAPIError +from mpt_api_client.http.query_state import QueryState from tests.http.conftest import AsyncDummyService @@ -96,22 +97,22 @@ async def test_async_fetch_page_with_filter( def test_async_init_defaults(async_dummy_service): - assert async_dummy_service.query_rql is None - assert async_dummy_service.query_order_by is None - assert async_dummy_service.query_select is None - assert async_dummy_service.build_url() == "/api/v1/test" + assert async_dummy_service.query_state.filter is None + assert async_dummy_service.query_state.order_by is None + assert async_dummy_service.query_state.select is None + assert async_dummy_service.build_path() == "/api/v1/test" def test_async_init_with_filter(async_http_client, filter_status_active): collection_client = AsyncDummyService( http_client=async_http_client, - query_rql=filter_status_active, + query_state=QueryState(rql=filter_status_active), ) - assert collection_client.query_rql == filter_status_active - assert collection_client.query_order_by is None - assert collection_client.query_select is None - assert collection_client.build_url() == "/api/v1/test?eq(status,active)" + assert collection_client.query_state.filter == filter_status_active + assert collection_client.query_state.order_by is None + assert collection_client.query_state.select is None + assert collection_client.build_path() == "/api/v1/test?eq(status,active)" async def test_async_iterate_single_page(async_dummy_service, single_page_response): diff --git a/tests/http/test_base_service.py b/tests/http/test_base_service.py index 39a414b5..6189b674 100644 --- a/tests/http/test_base_service.py +++ b/tests/http/test_base_service.py @@ -1,101 +1,77 @@ -import pytest - -from mpt_api_client import RQLQuery from mpt_api_client.http import Service +from mpt_api_client.http.query_state import QueryState from tests.conftest import DummyModel +from tests.http.conftest import DummyService -class EndpointDummyService(Service[DummyModel]): - _endpoint = "/api/{version}/test" +class ParametrisedDummyService( # noqa: WPS215 + Service[DummyModel], +): + _endpoint = "/api/{version}/test/{tenant}" _model_class = DummyModel -@pytest.fixture -def base_dummy_service(http_client): - return EndpointDummyService(http_client=http_client, endpoint_params={"version": "v1"}) - - def test_endpoint(http_client): - service = EndpointDummyService(http_client=http_client, endpoint_params={"version": "vLatest"}) - - assert service.endpoint_params == {"version": "vLatest"} - assert service.endpoint == "/api/vLatest/test" - - -def test_filter(base_dummy_service, filter_status_active): - new_collection = base_dummy_service.filter(filter_status_active) - - assert base_dummy_service.query_rql is None - assert new_collection != base_dummy_service - assert new_collection.query_rql == filter_status_active + service = ParametrisedDummyService( + http_client=http_client, endpoint_params={"version": "vLatest", "tenant": "T-123"} + ) + assert service.endpoint_params == {"version": "vLatest", "tenant": "T-123"} + assert service.path == "/api/vLatest/test/T-123" -def test_multiple_filters(base_dummy_service): - filter_query = RQLQuery(status="active") - filter_query2 = RQLQuery(name="test") - new_collection = base_dummy_service.filter(filter_query).filter(filter_query2) +def test_endpoint_with_multiple_params(http_client): + service = ParametrisedDummyService( + http_client=http_client, endpoint_params={"version": "v2", "tenant": "test-tenant"} + ) - assert base_dummy_service.query_rql is None - assert new_collection.query_rql == filter_query & filter_query2 + assert service.path == "/api/v2/test/test-tenant" -def test_select(base_dummy_service): - new_collection = base_dummy_service.select("agreement", "-product") +def test_build_url_no_query_params(dummy_service): + url = dummy_service.build_path() + assert url == "/api/v1/test" - assert base_dummy_service.query_select is None - assert new_collection != base_dummy_service - assert new_collection.query_select == ["agreement", "-product"] +def test_build_url_with_query_params(dummy_service): + query_params = {"limit": "10", "offset": "20"} + url = dummy_service.build_path(query_params) + assert url == "/api/v1/test?limit=10&offset=20" -def test_select_exception(base_dummy_service): - with pytest.raises(ValueError): - base_dummy_service.select("agreement").select("product") +def test_build_url_with_query_state(http_client, filter_status_active): + service_with_state = DummyService( + http_client=http_client, + query_state=QueryState( + rql=filter_status_active, order_by=["created", "-name"], select=["id", "name"] + ), + ) -def test_order_by(base_dummy_service): - new_collection = base_dummy_service.order_by("created", "-name") + url = service_with_state.build_path() + assert url == "/api/v1/test?order=created,-name&select=id,name&eq(status,active)" - assert base_dummy_service.query_order_by is None - assert new_collection != base_dummy_service - assert new_collection.query_order_by == ["created", "-name"] +def test_build_url_with_query_state_and_params(http_client, filter_status_active): + service_with_state = ParametrisedDummyService( + http_client=http_client, + query_state=QueryState(rql=filter_status_active), + endpoint_params={"version": "v2", "tenant": "T-123"}, + ) -def test_order_by_exception(base_dummy_service): - with pytest.raises( - ValueError, match=r"Ordering is already set. Cannot set ordering multiple times." - ): - base_dummy_service.order_by("created").order_by("name") + query_params = {"limit": "5"} + url = service_with_state.build_path(query_params) + assert url == "/api/v2/test/T-123?limit=5&eq(status,active)" -def test_url(base_dummy_service, filter_status_active): - custom_collection = ( - base_dummy_service.filter(filter_status_active) - .select("-audit", "product.agreements", "-product.agreements.product") +def test_build_url_with_chained_methods(dummy_service, filter_status_active): + chained_service = ( + dummy_service.filter(filter_status_active) .order_by("-created", "name") + .select("id", "name", "-audit") ) - url = custom_collection.build_url() - - assert custom_collection != base_dummy_service - assert url == ( - "/api/v1/test?order=-created,name" - "&select=-audit,product.agreements,-product.agreements.product" - "&eq(status,active)" - ) - - -def test_clone(base_dummy_service, filter_status_active): - configured = ( - base_dummy_service.filter(filter_status_active) - .order_by("created", "-name") - .select("agreement", "-product") + url = chained_service.build_path({"limit": "10"}) + expected_url = ( + "/api/v1/test?limit=10&order=-created,name&select=id,name,-audit&eq(status,active)" ) - - cloned = configured.clone() - - assert cloned is not configured - assert isinstance(cloned, configured.__class__) - assert cloned.http_client is configured.http_client - assert str(cloned.query_rql) == str(configured.query_rql) - assert cloned.endpoint_params == configured.endpoint_params + assert url == expected_url diff --git a/tests/http/test_mixins.py b/tests/http/test_mixins.py index 1df1e5df..091a2002 100644 --- a/tests/http/test_mixins.py +++ b/tests/http/test_mixins.py @@ -5,6 +5,7 @@ import pytest import respx +from mpt_api_client import RQLQuery from mpt_api_client.resources.catalog.products_media import ( AsyncMediaService, MediaService, @@ -119,9 +120,7 @@ def test_sync_update_resource(dummy_service): assert json.loads(request.content.decode()) == resource_data -# FileOperationsMixin tests async def test_async_file_create_with_data(async_media_service): - """Test FileOperationsMixin async create method with resource data.""" media_data = {"id": "MED-133"} with respx.mock: mock_route = respx.post( @@ -151,7 +150,6 @@ async def test_async_file_create_with_data(async_media_service): async def test_async_file_create_no_data(async_media_service): - """Test FileOperationsMixin async create method without resource data.""" media_data = {"id": "MED-133"} with respx.mock: mock_route = respx.post( @@ -176,7 +174,6 @@ async def test_async_file_create_no_data(async_media_service): async def test_async_file_download(async_media_service): - """Test FileOperationsMixin async download method.""" media_content = b"Image file content or binary data" with respx.mock: @@ -204,7 +201,6 @@ async def test_async_file_download(async_media_service): def test_sync_file_download(media_service): - """Test FileOperationsMixin download method.""" media_content = b"Image file content or binary data" with respx.mock: @@ -232,7 +228,6 @@ def test_sync_file_download(media_service): def test_sync_file_create_with_data(media_service): - """Test FileOperationsMixin create method with resource data.""" media_data = {"id": "MED-133"} with respx.mock: mock_route = respx.post( @@ -262,7 +257,6 @@ def test_sync_file_create_with_data(media_service): def test_sync_file_create_no_data(media_service): - """Test FileOperationsMixin create method without resource data.""" media_data = {"id": "MED-133"} with respx.mock: mock_route = respx.post( @@ -286,15 +280,21 @@ def test_sync_file_create_no_data(media_service): assert new_media.to_dict() == media_data -def test_sync_get_mixin(dummy_service): - """Test GetMixin get method.""" +@pytest.mark.parametrize( + "select_value", + [ + ["id", "name"], + "id,name", + ], +) +def test_sync_get_mixin(dummy_service, select_value): resource_data = {"id": "RES-123", "name": "Test Resource"} with respx.mock: mock_route = respx.get( "https://api.example.com/api/v1/test/RES-123", params={"select": "id,name"} ).mock(return_value=httpx.Response(httpx.codes.OK, json=resource_data)) - resource = dummy_service.get("RES-123", select=["id", "name"]) + resource = dummy_service.get("RES-123", select=select_value) request = mock_route.calls[0].request accept_header = (b"Accept", b"application/json") @@ -315,3 +315,87 @@ async def test_async_get(async_dummy_service): accept_header = (b"Accept", b"application/json") assert accept_header in request.headers.raw assert resource.to_dict() == resource_data + + +async def test_async_get_select_str(async_dummy_service): + resource_data = {"id": "RES-123", "name": "Test Resource"} + with respx.mock: + mock_route = respx.get( + "https://api.example.com/api/v1/test/RES-123", params={"select": "id,name"} + ).mock(return_value=httpx.Response(httpx.codes.OK, json=resource_data)) + + resource = await async_dummy_service.get("RES-123", select="id,name") + + request = mock_route.calls[0].request + accept_header = (b"Accept", b"application/json") + assert accept_header in request.headers.raw + assert resource.to_dict() == resource_data + + +def test_queryable_mixin_order_by(dummy_service): + ordered_service = dummy_service.order_by("created", "-name") + + assert ordered_service != dummy_service + assert dummy_service.query_state.order_by is None + assert ordered_service.query_state.order_by == ["created", "-name"] + assert ordered_service.http_client is dummy_service.http_client + assert ordered_service.endpoint_params == dummy_service.endpoint_params + + +def test_queryable_mixin_order_by_exception(dummy_service): + ordered_service = dummy_service.order_by("created") + + with pytest.raises( + ValueError, match=r"Ordering is already set. Cannot set ordering multiple times." + ): + ordered_service.order_by("name") + + +def test_queryable_mixin_filter(dummy_service, filter_status_active): + filtered_service = dummy_service.filter(filter_status_active) + + assert filtered_service != dummy_service + assert dummy_service.query_state.filter is None + assert filtered_service.query_state.filter == filter_status_active + assert filtered_service.http_client is dummy_service.http_client + assert filtered_service.endpoint_params == dummy_service.endpoint_params + + +def test_queryable_mixin_filters(dummy_service): + filter1 = RQLQuery(status="active") + filter2 = RQLQuery(name="test") + + filtered_service = dummy_service.filter(filter1).filter(filter2) + + assert dummy_service.query_state.filter is None + assert filtered_service.query_state.filter == filter1 & filter2 + + +def test_queryable_mixin_select(dummy_service): + selected_service = dummy_service.select("id", "name", "-audit") + + assert selected_service != dummy_service + assert dummy_service.query_state.select is None + assert selected_service.query_state.select == ["id", "name", "-audit"] + assert selected_service.http_client is dummy_service.http_client + assert selected_service.endpoint_params == dummy_service.endpoint_params + + +def test_queryable_mixin_select_exception(dummy_service): + selected_service = dummy_service.select("id", "name") + + with pytest.raises( + ValueError, match=r"Select fields are already set. Cannot set select fields multiple times." + ): + selected_service.select("other_field") + + +def test_queryable_mixin_method_chaining(dummy_service, filter_status_active): + chained_service = ( + dummy_service.filter(filter_status_active).order_by("created", "-name").select("id", "name") + ) + + assert chained_service != dummy_service + assert chained_service.query_state.filter == filter_status_active + assert chained_service.query_state.order_by == ["created", "-name"] + assert chained_service.query_state.select == ["id", "name"] diff --git a/tests/http/test_query_state.py b/tests/http/test_query_state.py new file mode 100644 index 00000000..c03c02c8 --- /dev/null +++ b/tests/http/test_query_state.py @@ -0,0 +1,49 @@ +import pytest + +from mpt_api_client.http.query_state import QueryState + + +@pytest.fixture +def query_state(): + return QueryState() + + +def test_filter_init(filter_status_active): + query_state = QueryState( + rql=filter_status_active, select=["agreement", "-product"], order_by=["-created", "name"] + ) + + assert query_state.filter == filter_status_active + assert query_state.select == ["agreement", "-product"] + assert query_state.order_by == ["-created", "name"] + + +def test_build_url(filter_status_active): + query_state = QueryState( + rql=filter_status_active, + select=["-audit", "product.agreements", "-product.agreements.product"], + order_by=["-created", "name"], + ) + + query_string = query_state.build() + + assert query_string == ( + "order=-created,name" + "&select=-audit,product.agreements,-product.agreements.product" + "&eq(status,active)" + ) + + +def test_empty_build(query_state): + query_string = query_state.build() + + assert not query_string + + +def test_build_with_params(filter_status_active): + query_state = QueryState(rql=filter_status_active, order_by=["created"], select=["name"]) + query_params = {"limit": "10"} + + query_string = query_state.build(query_params) + + assert query_string == "limit=10&order=created&select=name&eq(status,active)" diff --git a/tests/http/test_service.py b/tests/http/test_service.py index f794d445..b6b02a3a 100644 --- a/tests/http/test_service.py +++ b/tests/http/test_service.py @@ -111,22 +111,8 @@ def test_sync_get(dummy_service): def test_sync_init_defaults(http_client): collection_client = DummyService(http_client=http_client) - assert collection_client.query_rql is None - assert collection_client.query_order_by is None - assert collection_client.query_select is None - assert collection_client.build_url() == "/api/v1/test" - - -def test_sync_init_with_filter(http_client, filter_status_active): - collection_client = DummyService( - http_client=http_client, - query_rql=filter_status_active, - ) - - assert collection_client.query_rql == filter_status_active - assert collection_client.query_order_by is None - assert collection_client.query_select is None - assert collection_client.build_url() == "/api/v1/test?eq(status,active)" + assert collection_client.endpoint_params == {} + assert collection_client.build_path() == "/api/v1/test" def test_sync_iterate_single_page(dummy_service, single_page_response): diff --git a/tests/resources/accounts/test_account_user_groups.py b/tests/resources/accounts/test_account_user_groups.py index deffc3ed..1ef59c87 100644 --- a/tests/resources/accounts/test_account_user_groups.py +++ b/tests/resources/accounts/test_account_user_groups.py @@ -23,13 +23,13 @@ def async_account_user_groups_service(async_http_client): def test_endpoint(account_user_groups_service): - assert account_user_groups_service.endpoint == ( + assert account_user_groups_service.path == ( "/public/v1/accounts/account-users/ACC-0000-0001/groups" ) def test_async_endpoint(async_account_user_groups_service): - assert async_account_user_groups_service.endpoint == ( + assert async_account_user_groups_service.path == ( "/public/v1/accounts/account-users/ACC-0000-0001/groups" ) diff --git a/tests/resources/accounts/test_accounts_user_groups.py b/tests/resources/accounts/test_accounts_user_groups.py index 6cd240d2..c13e85ed 100644 --- a/tests/resources/accounts/test_accounts_user_groups.py +++ b/tests/resources/accounts/test_accounts_user_groups.py @@ -24,14 +24,14 @@ def async_accounts_user_groups_service(async_http_client): def test_endpoint(accounts_user_groups_service): assert ( - accounts_user_groups_service.endpoint + accounts_user_groups_service.path == "/public/v1/accounts/ACC-0000-0001/users/USR-0000-0001/groups" ) def test_async_endpoint(async_accounts_user_groups_service): assert ( - async_accounts_user_groups_service.endpoint + async_accounts_user_groups_service.path == "/public/v1/accounts/ACC-0000-0001/users/USR-0000-0001/groups" ) diff --git a/tests/resources/accounts/test_accounts_users.py b/tests/resources/accounts/test_accounts_users.py index edb3e41f..0a78ba12 100644 --- a/tests/resources/accounts/test_accounts_users.py +++ b/tests/resources/accounts/test_accounts_users.py @@ -25,11 +25,11 @@ def async_accounts_users_service(async_http_client): def test_endpoint(accounts_users_service): - assert accounts_users_service.endpoint == "/public/v1/accounts/ACC-0000-0001/users" + assert accounts_users_service.path == "/public/v1/accounts/ACC-0000-0001/users" def test_async_endpoint(async_accounts_users_service): - assert async_accounts_users_service.endpoint == "/public/v1/accounts/ACC-0000-0001/users" + assert async_accounts_users_service.path == "/public/v1/accounts/ACC-0000-0001/users" @pytest.mark.parametrize( diff --git a/tests/resources/billing/test_credit_memo_attachments.py b/tests/resources/billing/test_credit_memo_attachments.py index afc00fa5..063288bf 100644 --- a/tests/resources/billing/test_credit_memo_attachments.py +++ b/tests/resources/billing/test_credit_memo_attachments.py @@ -22,14 +22,14 @@ def async_credit_memo_attachments_service(async_http_client): def test_endpoint(credit_memo_attachments_service): assert ( - credit_memo_attachments_service.endpoint + credit_memo_attachments_service.path == "/public/v1/billing/credit-memos/CRM-0000-0001/attachments" ) def test_async_endpoint(async_credit_memo_attachments_service): assert ( - async_credit_memo_attachments_service.endpoint + async_credit_memo_attachments_service.path == "/public/v1/billing/credit-memos/CRM-0000-0001/attachments" ) diff --git a/tests/resources/billing/test_custom_ledger_attachments.py b/tests/resources/billing/test_custom_ledger_attachments.py index 320abffd..b6fbba6d 100644 --- a/tests/resources/billing/test_custom_ledger_attachments.py +++ b/tests/resources/billing/test_custom_ledger_attachments.py @@ -21,13 +21,13 @@ def async_custom_ledger_attachments_service(async_http_client): def test_endpoint(custom_ledger_attachments_service): - assert custom_ledger_attachments_service.endpoint == ( + assert custom_ledger_attachments_service.path == ( "/public/v1/billing/custom-ledgers/LDG-0000-0001/attachments" ) def test_async_endpoint(async_custom_ledger_attachments_service): - assert async_custom_ledger_attachments_service.endpoint == ( + assert async_custom_ledger_attachments_service.path == ( "/public/v1/billing/custom-ledgers/LDG-0000-0001/attachments" ) diff --git a/tests/resources/billing/test_custom_ledger_charges.py b/tests/resources/billing/test_custom_ledger_charges.py index 1c3a7208..626a09f2 100644 --- a/tests/resources/billing/test_custom_ledger_charges.py +++ b/tests/resources/billing/test_custom_ledger_charges.py @@ -21,13 +21,13 @@ def async_custom_ledger_charges_service(async_http_client): def test_endpoint(custom_ledger_charges_service): - assert custom_ledger_charges_service.endpoint == ( + assert custom_ledger_charges_service.path == ( "/public/v1/billing/custom-ledgers/LDG-0000-0001/charges" ) def test_async_endpoint(async_custom_ledger_charges_service): - assert async_custom_ledger_charges_service.endpoint == ( + assert async_custom_ledger_charges_service.path == ( "/public/v1/billing/custom-ledgers/LDG-0000-0001/charges" ) diff --git a/tests/resources/billing/test_custom_ledger_upload.py b/tests/resources/billing/test_custom_ledger_upload.py index d2fb8053..dacce499 100644 --- a/tests/resources/billing/test_custom_ledger_upload.py +++ b/tests/resources/billing/test_custom_ledger_upload.py @@ -21,13 +21,13 @@ def async_custom_ledger_upload_service(http_client): def test_endpoint(custom_ledger_upload_service): - assert custom_ledger_upload_service.endpoint == ( + assert custom_ledger_upload_service.path == ( "/public/v1/billing/custom-ledgers/LDG-0000-0001/upload" ) def test_async_endpoint(async_custom_ledger_upload_service): - assert async_custom_ledger_upload_service.endpoint == ( + assert async_custom_ledger_upload_service.path == ( "/public/v1/billing/custom-ledgers/LDG-0000-0001/upload" ) diff --git a/tests/resources/billing/test_invoice_attachments.py b/tests/resources/billing/test_invoice_attachments.py index e6942970..0476b1da 100644 --- a/tests/resources/billing/test_invoice_attachments.py +++ b/tests/resources/billing/test_invoice_attachments.py @@ -22,14 +22,13 @@ def async_invoice_attachments_service(async_http_client): def test_endpoint(invoice_attachments_service): assert ( - invoice_attachments_service.endpoint - == "/public/v1/billing/invoices/INV-0000-0001/attachments" + invoice_attachments_service.path == "/public/v1/billing/invoices/INV-0000-0001/attachments" ) def test_async_endpoint(async_invoice_attachments_service): assert ( - async_invoice_attachments_service.endpoint + async_invoice_attachments_service.path == "/public/v1/billing/invoices/INV-0000-0001/attachments" ) diff --git a/tests/resources/billing/test_journal_attachments.py b/tests/resources/billing/test_journal_attachments.py index 9e272b27..77811e9b 100644 --- a/tests/resources/billing/test_journal_attachments.py +++ b/tests/resources/billing/test_journal_attachments.py @@ -22,14 +22,13 @@ def async_journal_attachments_service(async_http_client) -> AsyncJournalAttachme def test_endpoint(journal_attachments_service) -> None: assert ( - journal_attachments_service.endpoint - == "/public/v1/billing/journals/JRN-0000-0001/attachments" + journal_attachments_service.path == "/public/v1/billing/journals/JRN-0000-0001/attachments" ) def test_async_endpoint(async_journal_attachments_service) -> None: assert ( - async_journal_attachments_service.endpoint + async_journal_attachments_service.path == "/public/v1/billing/journals/JRN-0000-0001/attachments" ) diff --git a/tests/resources/billing/test_journal_charges.py b/tests/resources/billing/test_journal_charges.py index 675621ce..5c1194bc 100644 --- a/tests/resources/billing/test_journal_charges.py +++ b/tests/resources/billing/test_journal_charges.py @@ -21,11 +21,11 @@ def async_journal_charges_service(async_http_client): def test_endpoint(journal_charges_service): - assert journal_charges_service.endpoint == "/public/v1/billing/journals/JRN-0000-0001/charges" + assert journal_charges_service.path == "/public/v1/billing/journals/JRN-0000-0001/charges" def test_async_endpoint(async_journal_charges_service): - assert async_journal_charges_service.endpoint == ( + assert async_journal_charges_service.path == ( "/public/v1/billing/journals/JRN-0000-0001/charges" ) diff --git a/tests/resources/billing/test_journal_sellers.py b/tests/resources/billing/test_journal_sellers.py index 9678525c..0ea97703 100644 --- a/tests/resources/billing/test_journal_sellers.py +++ b/tests/resources/billing/test_journal_sellers.py @@ -21,14 +21,11 @@ def async_journal_sellers_service(async_http_client): def test_endpoint(journal_sellers_service): - assert journal_sellers_service.endpoint == "/public/v1/billing/journals/JRN-0000-0001/sellers" + assert journal_sellers_service.path == "/public/v1/billing/journals/JRN-0000-0001/sellers" def test_async_endpoint(async_journal_sellers_service): - assert ( - async_journal_sellers_service.endpoint - == "/public/v1/billing/journals/JRN-0000-0001/sellers" - ) + assert async_journal_sellers_service.path == "/public/v1/billing/journals/JRN-0000-0001/sellers" @pytest.mark.parametrize("method", ["get"]) diff --git a/tests/resources/billing/test_journal_upload.py b/tests/resources/billing/test_journal_upload.py index fc0d3d85..1c7be840 100644 --- a/tests/resources/billing/test_journal_upload.py +++ b/tests/resources/billing/test_journal_upload.py @@ -21,13 +21,11 @@ def async_journal_upload_service(async_http_client): def test_endpoint(journal_upload_service) -> None: - assert journal_upload_service.endpoint == "/public/v1/billing/journals/JRN-0000-0001/upload" + assert journal_upload_service.path == "/public/v1/billing/journals/JRN-0000-0001/upload" def test_async_endpoint(async_journal_upload_service) -> None: - assert ( - async_journal_upload_service.endpoint == "/public/v1/billing/journals/JRN-0000-0001/upload" - ) + assert async_journal_upload_service.path == "/public/v1/billing/journals/JRN-0000-0001/upload" @pytest.mark.parametrize("method", ["create"]) diff --git a/tests/resources/billing/test_ledger_attachments.py b/tests/resources/billing/test_ledger_attachments.py index b33c9445..f5ef2173 100644 --- a/tests/resources/billing/test_ledger_attachments.py +++ b/tests/resources/billing/test_ledger_attachments.py @@ -21,15 +21,12 @@ def async_ledger_attachments_service(async_http_client) -> AsyncLedgerAttachment def test_endpoint(ledger_attachments_service) -> None: - assert ( - ledger_attachments_service.endpoint - == "/public/v1/billing/ledgers/LED-0000-0001/attachments" - ) + assert ledger_attachments_service.path == "/public/v1/billing/ledgers/LED-0000-0001/attachments" def test_async_endpoint(async_ledger_attachments_service) -> None: assert ( - async_ledger_attachments_service.endpoint + async_ledger_attachments_service.path == "/public/v1/billing/ledgers/LED-0000-0001/attachments" ) diff --git a/tests/resources/billing/test_ledger_charges.py b/tests/resources/billing/test_ledger_charges.py index 233d23a3..116a41ad 100644 --- a/tests/resources/billing/test_ledger_charges.py +++ b/tests/resources/billing/test_ledger_charges.py @@ -21,13 +21,11 @@ def async_ledger_charges_service(async_http_client): def test_endpoint(ledger_charges_service): - assert ledger_charges_service.endpoint == "/public/v1/billing/ledgers/LED-0000-0001/charges" + assert ledger_charges_service.path == "/public/v1/billing/ledgers/LED-0000-0001/charges" def test_async_endpoint(async_ledger_charges_service): - assert ( - async_ledger_charges_service.endpoint == "/public/v1/billing/ledgers/LED-0000-0001/charges" - ) + assert async_ledger_charges_service.path == "/public/v1/billing/ledgers/LED-0000-0001/charges" @pytest.mark.parametrize("method", ["get"]) diff --git a/tests/resources/billing/test_statement_charges.py b/tests/resources/billing/test_statement_charges.py index b52c7576..676297a0 100644 --- a/tests/resources/billing/test_statement_charges.py +++ b/tests/resources/billing/test_statement_charges.py @@ -21,13 +21,11 @@ def async_statement_charges_service(async_http_client): def test_endpoint(statement_charges_service): - assert statement_charges_service.endpoint == ( - "/public/v1/billing/statements/STM-0000-0001/charges" - ) + assert statement_charges_service.path == ("/public/v1/billing/statements/STM-0000-0001/charges") def test_async_endpoint(async_statement_charges_service): - assert async_statement_charges_service.endpoint == ( + assert async_statement_charges_service.path == ( "/public/v1/billing/statements/STM-0000-0001/charges" ) diff --git a/tests/resources/catalog/test_price_list_items.py b/tests/resources/catalog/test_price_list_items.py index 3a5013e9..6e3262d9 100644 --- a/tests/resources/catalog/test_price_list_items.py +++ b/tests/resources/catalog/test_price_list_items.py @@ -22,12 +22,12 @@ def async_price_list_items_service(async_http_client): @pytest.fixture def test_endpoint(price_list_items_service): - assert price_list_items_service.endpoint == "/public/v1/catalog/price-lists/ITM-0000-0001/items" + assert price_list_items_service.path == "/public/v1/catalog/price-lists/ITM-0000-0001/items" @pytest.fixture def async_test_endpoint(async_price_list_items_service): - assert async_price_list_items_service.endpoint == ( + assert async_price_list_items_service.path == ( "/public/v1/catalog/price-lists/ITM-0000-0001/items" ) diff --git a/tests/resources/catalog/test_pricing_policy_attachments.py b/tests/resources/catalog/test_pricing_policy_attachments.py index a1d88555..30b137f2 100644 --- a/tests/resources/catalog/test_pricing_policy_attachments.py +++ b/tests/resources/catalog/test_pricing_policy_attachments.py @@ -24,14 +24,14 @@ def async_pricing_policy_attachments_service( def test_endpoint(pricing_policy_attachments_service) -> None: assert ( - pricing_policy_attachments_service.endpoint + pricing_policy_attachments_service.path == "/public/v1/catalog/pricing-policies/PRP-0000-0001/attachments" ) def test_async_endpoint(async_pricing_policy_attachments_service) -> None: assert ( - async_pricing_policy_attachments_service.endpoint + async_pricing_policy_attachments_service.path == "/public/v1/catalog/pricing-policies/PRP-0000-0001/attachments" ) diff --git a/tests/resources/catalog/test_product_term_variants.py b/tests/resources/catalog/test_product_term_variants.py index 42ab3ee9..45a535ee 100644 --- a/tests/resources/catalog/test_product_term_variants.py +++ b/tests/resources/catalog/test_product_term_variants.py @@ -21,13 +21,11 @@ def async_term_variant_service(async_http_client: Any) -> AsyncTermVariantServic def test_endpoint(term_variant_service: TermVariantService) -> None: - assert term_variant_service.endpoint == "/public/v1/catalog/products/terms/TRM-001/variants" + assert term_variant_service.path == "/public/v1/catalog/products/terms/TRM-001/variants" def test_async_endpoint(async_term_variant_service: AsyncTermVariantService) -> None: - assert ( - async_term_variant_service.endpoint == "/public/v1/catalog/products/terms/TRM-001/variants" - ) + assert async_term_variant_service.path == "/public/v1/catalog/products/terms/TRM-001/variants" @pytest.mark.parametrize( diff --git a/tests/resources/catalog/test_product_terms.py b/tests/resources/catalog/test_product_terms.py index 42b6fd80..71ed909e 100644 --- a/tests/resources/catalog/test_product_terms.py +++ b/tests/resources/catalog/test_product_terms.py @@ -25,11 +25,11 @@ def async_term_service(async_http_client: Any) -> AsyncTermService: def test_endpoint(term_service: TermService) -> None: - assert term_service.endpoint == "/public/v1/catalog/products/PRD-001/terms" + assert term_service.path == "/public/v1/catalog/products/PRD-001/terms" def test_async_endpoint(async_term_service: AsyncTermService) -> None: - assert async_term_service.endpoint == "/public/v1/catalog/products/PRD-001/terms" + assert async_term_service.path == "/public/v1/catalog/products/PRD-001/terms" @pytest.mark.parametrize( diff --git a/tests/resources/catalog/test_products_documents.py b/tests/resources/catalog/test_products_documents.py index df06654a..7d0900b2 100644 --- a/tests/resources/catalog/test_products_documents.py +++ b/tests/resources/catalog/test_products_documents.py @@ -19,11 +19,11 @@ def async_document_service(async_http_client) -> AsyncDocumentService: def test_endpoint(document_service) -> None: - assert document_service.endpoint == "/public/v1/catalog/products/PRD-001/documents" + assert document_service.path == "/public/v1/catalog/products/PRD-001/documents" def test_async_endpoint(async_document_service) -> None: - assert async_document_service.endpoint == "/public/v1/catalog/products/PRD-001/documents" + assert async_document_service.path == "/public/v1/catalog/products/PRD-001/documents" @pytest.mark.parametrize( diff --git a/tests/resources/catalog/test_products_item_groups.py b/tests/resources/catalog/test_products_item_groups.py index 2bfb9d8a..05a72b14 100644 --- a/tests/resources/catalog/test_products_item_groups.py +++ b/tests/resources/catalog/test_products_item_groups.py @@ -19,11 +19,11 @@ def async_item_groups_service(async_http_client): def test_endpoint(item_groups_service): - assert item_groups_service.endpoint == "/public/v1/catalog/products/PRD-001/item-groups" + assert item_groups_service.path == "/public/v1/catalog/products/PRD-001/item-groups" def test_async_endpoint(async_item_groups_service): - assert async_item_groups_service.endpoint == "/public/v1/catalog/products/PRD-001/item-groups" + assert async_item_groups_service.path == "/public/v1/catalog/products/PRD-001/item-groups" @pytest.mark.parametrize("method", ["get", "create", "delete", "update"]) diff --git a/tests/resources/catalog/test_products_media.py b/tests/resources/catalog/test_products_media.py index 58a0d5ed..f82f00c0 100644 --- a/tests/resources/catalog/test_products_media.py +++ b/tests/resources/catalog/test_products_media.py @@ -19,11 +19,11 @@ def async_media_service(async_http_client) -> AsyncMediaService: def test_endpoint(media_service) -> None: - assert media_service.endpoint == "/public/v1/catalog/products/PRD-001/media" + assert media_service.path == "/public/v1/catalog/products/PRD-001/media" def test_async_endpoint(async_media_service) -> None: - assert async_media_service.endpoint == "/public/v1/catalog/products/PRD-001/media" + assert async_media_service.path == "/public/v1/catalog/products/PRD-001/media" @pytest.mark.parametrize( diff --git a/tests/resources/catalog/test_products_parameter_groups.py b/tests/resources/catalog/test_products_parameter_groups.py index 7382fb65..0369dae9 100644 --- a/tests/resources/catalog/test_products_parameter_groups.py +++ b/tests/resources/catalog/test_products_parameter_groups.py @@ -21,14 +21,12 @@ def async_parameter_groups_service(async_http_client): def test_endpoint(parameter_groups_service): - assert ( - parameter_groups_service.endpoint == "/public/v1/catalog/products/PRD-001/parameter-groups" - ) + assert parameter_groups_service.path == "/public/v1/catalog/products/PRD-001/parameter-groups" def test_async_endpoint(async_parameter_groups_service): assert ( - async_parameter_groups_service.endpoint + async_parameter_groups_service.path == "/public/v1/catalog/products/PRD-001/parameter-groups" ) diff --git a/tests/resources/catalog/test_products_parameters.py b/tests/resources/catalog/test_products_parameters.py index 4bf3a003..407dac82 100644 --- a/tests/resources/catalog/test_products_parameters.py +++ b/tests/resources/catalog/test_products_parameters.py @@ -19,11 +19,11 @@ def async_parameters_service(async_http_client): def test_endpoint(parameters_service): - assert parameters_service.endpoint == "/public/v1/catalog/products/PRD-001/parameters" + assert parameters_service.path == "/public/v1/catalog/products/PRD-001/parameters" def test_async_endpoint(async_parameters_service): - assert async_parameters_service.endpoint == "/public/v1/catalog/products/PRD-001/parameters" + assert async_parameters_service.path == "/public/v1/catalog/products/PRD-001/parameters" @pytest.mark.parametrize("method", ["get", "create", "delete", "update"]) diff --git a/tests/resources/catalog/test_products_templates.py b/tests/resources/catalog/test_products_templates.py index c175c4e8..a19309f7 100644 --- a/tests/resources/catalog/test_products_templates.py +++ b/tests/resources/catalog/test_products_templates.py @@ -19,11 +19,11 @@ def async_templates_service(async_http_client): def test_endpoint(templates_service): - assert templates_service.endpoint == "/public/v1/catalog/products/PRD-001/templates" + assert templates_service.path == "/public/v1/catalog/products/PRD-001/templates" def test_async_endpoint(async_templates_service): - assert async_templates_service.endpoint == "/public/v1/catalog/products/PRD-001/templates" + assert async_templates_service.path == "/public/v1/catalog/products/PRD-001/templates" @pytest.mark.parametrize("method", ["get", "create", "delete", "update", "fetch_page", "iterate"]) diff --git a/tests/resources/commerce/test_agreements_attachments.py b/tests/resources/commerce/test_agreements_attachments.py index be656d68..f2f28554 100644 --- a/tests/resources/commerce/test_agreements_attachments.py +++ b/tests/resources/commerce/test_agreements_attachments.py @@ -21,11 +21,11 @@ def async_attachment_service(async_http_client) -> AsyncAgreementsAttachmentServ def test_endpoint(attachment_service) -> None: - assert attachment_service.endpoint == "/public/v1/commerce/agreements/AGR-123/attachments" + assert attachment_service.path == "/public/v1/commerce/agreements/AGR-123/attachments" def test_async_endpoint(async_attachment_service) -> None: - assert async_attachment_service.endpoint == "/public/v1/commerce/agreements/AGR-123/attachments" + assert async_attachment_service.path == "/public/v1/commerce/agreements/AGR-123/attachments" @pytest.mark.parametrize("method", ["get", "create", "delete", "download"]) diff --git a/tests/resources/commerce/test_order_subcription.py b/tests/resources/commerce/test_order_subcription.py index 535d1188..8ef19ea4 100644 --- a/tests/resources/commerce/test_order_subcription.py +++ b/tests/resources/commerce/test_order_subcription.py @@ -31,8 +31,8 @@ def test_async_mixins_present(async_subscription_service, method): def test_endpoint(subscription_service): - assert subscription_service.endpoint == "/public/v1/commerce/orders/ORD-123/subscriptions" + assert subscription_service.path == "/public/v1/commerce/orders/ORD-123/subscriptions" def test_async_endpoint(async_subscription_service): - assert async_subscription_service.endpoint == "/public/v1/commerce/orders/ORD-123/subscriptions" + assert async_subscription_service.path == "/public/v1/commerce/orders/ORD-123/subscriptions"