-
Notifications
You must be signed in to change notification settings - Fork 0
MPT-22435 derive product-document e2e fixtures from a created product #351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,31 @@ | ||
| import pytest | ||
|
|
||
| from mpt_api_client.exceptions import MPTAPIError | ||
| from mpt_api_client.rql.query_builder import RQLQuery | ||
| from tests.e2e.helper import ( | ||
| assert_async_service_filter_with_iterate, | ||
| assert_async_update_resource, | ||
| async_create_fixture_resource_and_delete, | ||
| ) | ||
|
|
||
| pytestmark = [pytest.mark.flaky] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def async_document_service(async_mpt_vendor, product_id): | ||
| return async_mpt_vendor.catalog.products.documents(product_id) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def created_document_from_file_async(async_document_service, document_data, pdf_fd): | ||
| async def created_document_from_file_async(async_vendor_document_service, document_data, pdf_fd): | ||
| document_data["documentType"] = "File" | ||
| document = await async_document_service.create(document_data, file=pdf_fd) | ||
| yield document | ||
| try: | ||
| await async_document_service.delete(document.id) | ||
| except MPTAPIError as error: | ||
| print(f"TEARDOWN - Unable to delete document {document.id}: {error.title}") | ||
| async with async_create_fixture_resource_and_delete( | ||
| async_vendor_document_service, document_data, upload_file=pdf_fd | ||
| ) as document: | ||
| yield document | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def created_document_from_link_async(async_document_service, document_data, pdf_url): | ||
| async def created_document_from_link_async(async_vendor_document_service, document_data, pdf_url): | ||
| document_data["url"] = pdf_url | ||
| document = await async_document_service.create(document_data) | ||
| yield document | ||
| try: | ||
| await async_document_service.delete(document.id) | ||
| except MPTAPIError as error: | ||
| print(f"TEARDOWN - Unable to delete document {document.id}: {error.title}") | ||
| async with async_create_fixture_resource_and_delete( | ||
| async_vendor_document_service, document_data | ||
| ) as document: | ||
| yield document | ||
|
|
||
|
|
||
| def test_create_document_async(created_document_from_file_async, document_data): # noqa: AAA01 | ||
|
|
@@ -43,50 +38,58 @@ def test_create_from_link_async(created_document_from_link_async, pdf_url, docum | |
| assert created_document_from_link_async.description == document_data["description"] | ||
|
|
||
|
|
||
| async def test_update_document_async(async_document_service, created_document_from_file_async): | ||
| update_data = {"name": "Updated e2e test document - please delete"} | ||
|
|
||
| result = await async_document_service.update(created_document_from_file_async.id, update_data) | ||
|
|
||
| assert result.name == update_data["name"] | ||
| async def test_update_document_async( | ||
| async_vendor_document_service, created_document_from_file_async | ||
| ): | ||
| await assert_async_update_resource( | ||
| async_vendor_document_service, | ||
| created_document_from_file_async.id, | ||
| "name", | ||
| "Updated e2e test document - please delete", | ||
| ) # act | ||
|
|
||
|
|
||
| async def test_get_document_async(async_document_service, document_id): | ||
| result = await async_document_service.get(document_id) | ||
| async def test_get_document_async(async_vendor_document_service, created_document_from_file_async): | ||
| result = await async_vendor_document_service.get(created_document_from_file_async.id) | ||
|
|
||
| assert result.id == document_id | ||
| assert result.id == created_document_from_file_async.id | ||
|
|
||
|
|
||
| async def test_download_document_async(async_document_service, document_id): | ||
| result = await async_document_service.download(document_id) | ||
| async def test_download_document_async( | ||
| async_vendor_document_service, created_document_from_file_async | ||
| ): | ||
| result = await async_vendor_document_service.download(created_document_from_file_async.id) | ||
|
|
||
| assert result.file_contents is not None | ||
| assert result.filename == "pdf - empty.pdf" | ||
| assert result.filename == "empty.pdf" | ||
|
|
||
|
|
||
| async def test_iterate_documents_async(async_document_service, created_document_from_file_async): | ||
| documents = [doc async for doc in async_document_service.iterate()] | ||
| async def test_iterate_documents_async( | ||
| async_vendor_document_service, created_document_from_file_async | ||
| ): | ||
| documents = [doc async for doc in async_vendor_document_service.iterate()] | ||
|
|
||
| result = any(doc.id == created_document_from_file_async.id for doc in documents) | ||
|
|
||
| assert result is True | ||
|
Comment on lines
+67
to
74
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check helper: assert_service_filter_with_iterate and assert_async_service_filter_with_iterate
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 3fee2a1 — |
||
|
|
||
|
|
||
| async def test_filter_documents_async(async_document_service, created_document_from_file_async): | ||
| filtered_service = async_document_service.filter( | ||
| RQLQuery(id=created_document_from_file_async.id) | ||
| ) | ||
| documents = [doc async for doc in filtered_service.iterate()] | ||
| assert len(documents) == 1 | ||
| assert documents[0].id == created_document_from_file_async.id | ||
| async def test_filter_documents_async( | ||
| async_vendor_document_service, created_document_from_file_async | ||
| ): | ||
| await assert_async_service_filter_with_iterate( | ||
| async_vendor_document_service, created_document_from_file_async.id, None | ||
| ) # act | ||
|
|
||
|
|
||
| async def test_review_and_publish_document_async( | ||
| async_mpt_vendor, async_mpt_ops, created_document_from_file_async, product_id | ||
| async_vendor_document_service, | ||
| async_mpt_ops, | ||
| created_document_from_file_async, | ||
| async_created_product, | ||
| ): | ||
| vendor_service = async_mpt_vendor.catalog.products.documents(product_id) | ||
| ops_service = async_mpt_ops.catalog.products.documents(product_id) | ||
| document = await vendor_service.review(created_document_from_file_async.id) | ||
| ops_service = async_mpt_ops.catalog.products.documents(async_created_product.id) | ||
| document = await async_vendor_document_service.review(created_document_from_file_async.id) | ||
| assert document.status == "Pending" | ||
| document = await ops_service.publish(created_document_from_file_async.id) | ||
| assert document.status == "Published" | ||
|
|
@@ -96,12 +99,14 @@ async def test_review_and_publish_document_async( | |
| assert result.status == "Unpublished" | ||
|
|
||
|
|
||
| async def test_not_found_async(async_document_service): | ||
| async def test_not_found_async(async_vendor_document_service): | ||
| with pytest.raises(MPTAPIError): | ||
| await async_document_service.get("DOC-000-000-000") | ||
| await async_vendor_document_service.get("DOC-000-000-000") | ||
|
|
||
|
|
||
| async def test_delete_document_async(async_document_service, created_document_from_file_async): | ||
| await async_document_service.delete(created_document_from_file_async.id) | ||
| async def test_delete_document_async( | ||
| async_vendor_document_service, created_document_from_file_async | ||
| ): | ||
| await async_vendor_document_service.delete(created_document_from_file_async.id) | ||
| with pytest.raises(MPTAPIError): | ||
| await async_document_service.get(created_document_from_file_async.id) | ||
| await async_vendor_document_service.get(created_document_from_file_async.id) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have helpers that does this for you:
check async_create_fixture_resource_and_delete and create_fixture_resource_and_delete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 3fee2a1 — both fixtures (sync + async) now use
create_fixture_resource_and_delete/async_create_fixture_resource_and_delete. I extended those helpers with an optionalupload_fileparam so the file-backed document fixture can use them too (backward compatible: it is only forwarded tocreate()when provided, so existing non-file callers are unchanged). 🤖 Generated by AI