Skip to content

Commit 3eeb558

Browse files
committed
MPT-14891 E2E for product terms and variants
1 parent 6c91d66 commit 3eeb558

19 files changed

Lines changed: 402 additions & 38 deletions

e2e_config.test.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@
1717
"catalog.product.parameter.id": "PAR-7255-3950-0016",
1818
"catalog.product.parameter_group.id": "PGR-7255-3950-0001",
1919
"catalog.product.template.id": "TPL-7255-3950-0001",
20+
"catalog.product.terms.id": "TCS-7255-3950-0001",
21+
"catalog.product.terms.variant.id": "TCV-7255-3950-0001-0001",
2022
"catalog.unit.id": "UNT-1229"
2123
}

mpt_api_client/resources/catalog/mixins.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ async def unpublish(self, resource_id: str, resource_data: ResourceData | None =
8484
class AsyncCreateFileMixin[Model]:
8585
"""Create file mixin."""
8686

87-
_upload_file_key = "file"
88-
_upload_data_key = "document"
89-
9087
async def create(self, resource_data: ResourceData, file: FileTypes | None = None) -> Model:
9188
"""Create document.
9289
@@ -101,13 +98,13 @@ async def create(self, resource_data: ResourceData, file: FileTypes | None = Non
10198
"""
10299
files = {}
103100
if file:
104-
files[self._upload_file_key] = file
101+
files[self._upload_file_key] = file # type: ignore[attr-defined]
105102
response = await self.http_client.request( # type: ignore[attr-defined]
106103
"post",
107104
self.path, # type: ignore[attr-defined]
108105
json=resource_data,
109106
files=files,
110-
json_file_key=self._upload_data_key,
107+
json_file_key=self._upload_data_key, # type: ignore[attr-defined]
111108
force_multipart=True,
112109
)
113110
return self._model_class.from_response(response) # type: ignore[attr-defined, no-any-return]
@@ -124,9 +121,6 @@ class AsyncDocumentMixin[Model](
124121
class CreateFileMixin[Model]:
125122
"""Create file mixin."""
126123

127-
_upload_file_key = "file"
128-
_upload_data_key = "document"
129-
130124
def create(self, resource_data: ResourceData, file: FileTypes | None = None) -> Model:
131125
"""Create document.
132126
@@ -141,13 +135,13 @@ def create(self, resource_data: ResourceData, file: FileTypes | None = None) ->
141135
"""
142136
files = {}
143137
if file:
144-
files[self._upload_file_key] = file
138+
files[self._upload_file_key] = file # type: ignore[attr-defined]
145139
response = self.http_client.request( # type: ignore[attr-defined]
146140
"post",
147141
self.path, # type: ignore[attr-defined]
148142
json=resource_data,
149143
files=files,
150-
json_file_key=self._upload_data_key,
144+
json_file_key=self._upload_data_key, # type: ignore[attr-defined]
151145
force_multipart=True,
152146
)
153147
return self._model_class.from_response(response) # type: ignore[attr-defined, no-any-return]
@@ -160,9 +154,6 @@ class DocumentMixin[Model](
160154
):
161155
"""Document mixin."""
162156

163-
_upload_file_key = "file"
164-
_upload_data_key = "document"
165-
166157

167158
class MediaMixin[Model](
168159
CreateFileMixin[Model],
@@ -171,9 +162,6 @@ class MediaMixin[Model](
171162
):
172163
"""Media mixin."""
173164

174-
_upload_file_key = "file"
175-
_upload_data_key = "media"
176-
177165

178166
class ActivatableMixin[Model]:
179167
"""Activatable mixin adds the ability to activate and deactivate."""
@@ -235,6 +223,3 @@ class AsyncMediaMixin[Model](
235223
AsyncPublishableMixin[Model],
236224
):
237225
"""Media mixin."""
238-
239-
_upload_file_key = "file"
240-
_upload_data_key = "media"

mpt_api_client/resources/catalog/product_term_variants.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
from mpt_api_client.http import AsyncService, Service
22
from mpt_api_client.http.mixins import (
33
AsyncCollectionMixin,
4-
AsyncFilesOperationsMixin,
4+
AsyncDownloadFileMixin,
55
AsyncModifiableResourceMixin,
66
CollectionMixin,
7-
FilesOperationsMixin,
7+
DownloadFileMixin,
88
ModifiableResourceMixin,
99
)
1010
from mpt_api_client.models import Model
1111
from mpt_api_client.resources.catalog.mixins import (
12+
AsyncCreateFileMixin,
1213
AsyncPublishableMixin,
14+
CreateFileMixin,
1315
PublishableMixin,
1416
)
1517

@@ -21,13 +23,16 @@ class TermVariant(Model):
2123
class TermVariantServiceConfig:
2224
"""Term variant service configuration."""
2325

24-
_endpoint = "/public/v1/catalog/products/terms/{term_id}/variants"
26+
_endpoint = "/public/v1/catalog/products/{product_id}/terms/{term_id}/variants"
2527
_model_class = TermVariant
2628
_collection_key = "data"
29+
_upload_file_key = "file"
30+
_upload_data_key = "variant"
2731

2832

2933
class TermVariantService(
30-
FilesOperationsMixin[TermVariant],
34+
CreateFileMixin[TermVariant],
35+
DownloadFileMixin[TermVariant],
3136
ModifiableResourceMixin[TermVariant],
3237
PublishableMixin[TermVariant],
3338
CollectionMixin[TermVariant],
@@ -38,7 +43,8 @@ class TermVariantService(
3843

3944

4045
class AsyncTermVariantService(
41-
AsyncFilesOperationsMixin[TermVariant],
46+
AsyncCreateFileMixin[TermVariant],
47+
AsyncDownloadFileMixin[TermVariant],
4248
AsyncModifiableResourceMixin[TermVariant],
4349
AsyncPublishableMixin[TermVariant],
4450
AsyncCollectionMixin[TermVariant],

mpt_api_client/resources/catalog/product_terms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def variants(self, term_id: str) -> TermVariantService:
3838
"""Access term variants service."""
3939
return TermVariantService(
4040
http_client=self.http_client,
41-
endpoint_params={"term_id": term_id},
41+
endpoint_params={"product_id": self.endpoint_params["product_id"], "term_id": term_id},
4242
)
4343

4444

@@ -55,5 +55,5 @@ def variants(self, term_id: str) -> AsyncTermVariantService:
5555
"""Access async term variants service."""
5656
return AsyncTermVariantService(
5757
http_client=self.http_client,
58-
endpoint_params={"term_id": term_id},
58+
endpoint_params={"product_id": self.endpoint_params["product_id"], "term_id": term_id},
5959
)

mpt_api_client/resources/catalog/products_documents.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class DocumentServiceConfig:
2222
_endpoint = "/public/v1/catalog/products/{product_id}/documents"
2323
_model_class = Document
2424
_collection_key = "data"
25+
_upload_file_key = "file"
26+
_upload_data_key = "document"
2527

2628

2729
class DocumentService(

mpt_api_client/resources/catalog/products_media.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class MediaServiceConfig:
2222
_endpoint = "/public/v1/catalog/products/{product_id}/media"
2323
_model_class = Media
2424
_collection_key = "data"
25+
_upload_file_key = "file"
26+
_upload_data_key = "media"
2527

2628

2729
class MediaService(

tests/e2e/catalog/product/documents/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def document_data():
1212
"name": "e2e test document - please delete",
1313
"description": "E2E test document for automated testing",
1414
"language": "en-gb",
15+
"url": "",
1516
}
1617

1718

tests/e2e/catalog/product/documents/test_async_document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from mpt_api_client.exceptions import MPTAPIError
44
from mpt_api_client.rql.query_builder import RQLQuery
55

6-
pytestmark = [pytest.mark.flaky, pytest.mark.asyncio]
6+
pytestmark = [pytest.mark.flaky]
77

88

99
@pytest.fixture

tests/e2e/catalog/product/documents/test_sync_document.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def created_document_from_file(logger, vendor_document_service, document_data, p
1818

1919

2020
@pytest.fixture
21-
def created_document_from_link(logger, vendor_document_service, document_data, pdf_url):
21+
def created_document_from_url(logger, vendor_document_service, document_data, pdf_url):
2222
document_data["url"] = pdf_url
2323
document = vendor_document_service.create(document_data)
2424
yield document
@@ -33,9 +33,9 @@ def test_create_document(created_document_from_file, document_data):
3333
assert created_document_from_file.description == document_data["description"]
3434

3535

36-
def test_create_from_link(created_document_from_link, pdf_url, document_data):
37-
assert created_document_from_link.name == document_data["name"]
38-
assert created_document_from_link.description == document_data["description"]
36+
def test_create_document_from_url(created_document_from_url, document_data):
37+
assert created_document_from_url.name == document_data["name"]
38+
assert created_document_from_url.description == document_data["description"]
3939

4040

4141
def test_update_document(vendor_document_service, created_document_from_file):

tests/e2e/catalog/product/media/test_async_media.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from mpt_api_client.exceptions import MPTAPIError
44

5-
pytestmark = [pytest.mark.flaky, pytest.mark.asyncio]
5+
pytestmark = [pytest.mark.flaky]
66

77

88
@pytest.fixture

0 commit comments

Comments
 (0)