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
26 changes: 26 additions & 0 deletions tests/e2e/catalog/product/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
import pytest

from mpt_api_client.exceptions import MPTAPIError


@pytest.fixture
def product_data():
return {"name": "Test Product", "website": "https://www.example.com"}


@pytest.fixture
def created_product(mpt_vendor, product_data, logo_fd):
product = mpt_vendor.catalog.products.create(product_data, file=logo_fd)

yield product

try:
mpt_vendor.catalog.products.delete(product.id)
except MPTAPIError as error:
print(f"TEARDOWN - Unable to delete product {product.id}: {error.title}") # noqa: WPS421


@pytest.fixture
async def async_created_product(async_mpt_vendor, product_data, logo_fd):
product = await async_mpt_vendor.catalog.products.create(product_data, file=logo_fd)

yield product

try:
await async_mpt_vendor.catalog.products.delete(product.id)
except MPTAPIError as error:
print(f"TEARDOWN - Unable to delete product {product.id}: {error.title}") # noqa: WPS421


@pytest.fixture
def parameter_group_id(e2e_config):
return e2e_config["catalog.product.parameter_group.id"]
Expand Down
13 changes: 4 additions & 9 deletions tests/e2e/catalog/product/documents/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import pytest


@pytest.fixture
def document_id(e2e_config):
return e2e_config["catalog.product.document.id"]


@pytest.fixture
def document_data():
return {
Expand All @@ -17,10 +12,10 @@ def document_data():


@pytest.fixture
def vendor_document_service(mpt_vendor, product_id):
return mpt_vendor.catalog.products.documents(product_id)
def vendor_document_service(mpt_vendor, created_product):
return mpt_vendor.catalog.products.documents(created_product.id)


@pytest.fixture
def async_vendor_document_service(async_mpt_vendor, product_id):
return async_mpt_vendor.catalog.products.documents(product_id)
def async_vendor_document_service(async_mpt_vendor, async_created_product):
return async_mpt_vendor.catalog.products.documents(async_created_product.id)
105 changes: 55 additions & 50 deletions tests/e2e/catalog/product/documents/test_async_document.py
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
Expand All @@ -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"]

Comment on lines 14 to 39

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Member Author

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 optional upload_file param so the file-backed document fixture can use them too (backward compatible: it is only forwarded to create() when provided, so existing non-file callers are unchanged). 🤖 Generated by AI


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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3fee2a1test_filter_documents / test_filter_documents_async now use assert_service_filter_with_iterate / assert_async_service_filter_with_iterate. 🤖 Generated by AI



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"
Expand All @@ -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)
65 changes: 31 additions & 34 deletions tests/e2e/catalog/product/documents/test_sync_document.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
import pytest

from mpt_api_client.exceptions import MPTAPIError
from mpt_api_client.rql.query_builder import RQLQuery
from tests.e2e.helper import (
assert_service_filter_with_iterate,
assert_update_resource,
create_fixture_resource_and_delete,
)

pytestmark = [pytest.mark.flaky]


@pytest.fixture
def created_document_from_file(vendor_document_service, document_data, pdf_fd):
document_data["documentType"] = "File"
document = vendor_document_service.create(document_data, pdf_fd)
yield document
try:
vendor_document_service.delete(document.id)
except MPTAPIError as error:
print(f"TEARDOWN - Unable to delete document {document.id}: {error.title}")
with create_fixture_resource_and_delete(
vendor_document_service, document_data, upload_file=pdf_fd
) as document:
yield document


@pytest.fixture
def created_document_from_url(vendor_document_service, document_data, pdf_url):
document_data["url"] = pdf_url
document = vendor_document_service.create(document_data)
yield document
try:
vendor_document_service.delete(document.id)
except MPTAPIError as error:
print(f"TEARDOWN - Unable to delete document {document.id}: {error.title}")
with create_fixture_resource_and_delete(vendor_document_service, document_data) as document:
yield document


def test_create_document(created_document_from_file, document_data): # noqa: AAA01
Expand All @@ -39,24 +37,25 @@ def test_create_document_from_url(created_document_from_url, document_data): #


def test_update_document(vendor_document_service, created_document_from_file):
update_data = {"name": "Updated e2e test document - please delete"}
assert_update_resource(
vendor_document_service,
created_document_from_file.id,
"name",
"Updated e2e test document - please delete",
) # act

result = vendor_document_service.update(created_document_from_file.id, update_data)

assert result.name == update_data["name"]
def test_get_document(vendor_document_service, created_document_from_file):
result = vendor_document_service.get(created_document_from_file.id)

assert result.id == created_document_from_file.id

def test_get_document(vendor_document_service, document_id):
result = vendor_document_service.get(document_id)

assert result.id == document_id


def test_download_document(vendor_document_service, document_id):
result = vendor_document_service.download(document_id)
def test_download_document(vendor_document_service, created_document_from_file):
result = vendor_document_service.download(created_document_from_file.id)

assert result.file_contents is not None
assert result.filename == "pdf - empty.pdf"
assert result.filename == "empty.pdf"


def test_iterate_documents(vendor_document_service, created_document_from_file):
Expand All @@ -68,18 +67,16 @@ def test_iterate_documents(vendor_document_service, created_document_from_file):


def test_filter_documents(vendor_document_service, created_document_from_file):
result = list(
vendor_document_service.filter(RQLQuery(id=created_document_from_file.id)).iterate()
)

assert len(result) == 1
assert result[0].id == created_document_from_file.id
assert_service_filter_with_iterate(
vendor_document_service, created_document_from_file.id, None
) # act


def test_review_and_publish_document(mpt_vendor, mpt_ops, created_document_from_file, product_id):
vendor_service = mpt_vendor.catalog.products.documents(product_id)
ops_service = mpt_ops.catalog.products.documents(product_id)
document = vendor_service.review(created_document_from_file.id)
def test_review_and_publish_document(
vendor_document_service, mpt_ops, created_document_from_file, created_product
):
ops_service = mpt_ops.catalog.products.documents(created_product.id)
document = vendor_document_service.review(created_document_from_file.id)
assert document.status == "Pending"
document = ops_service.publish(created_document_from_file.id)
assert document.status == "Published"
Expand Down
13 changes: 0 additions & 13 deletions tests/e2e/catalog/product/test_async_product.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
import pytest

from mpt_api_client import RQLQuery
from mpt_api_client.exceptions import MPTAPIError

pytestmark = [pytest.mark.flaky]


@pytest.fixture
async def async_created_product(async_mpt_vendor, product_data, logo_fd):
product = await async_mpt_vendor.catalog.products.create(product_data, file=logo_fd)

yield product

try:
await async_mpt_vendor.catalog.products.delete(product.id)
except MPTAPIError as error:
print(f"TEARDOWN - Unable to delete product {product.id}: {error.title}") # noqa: WPS421


def test_create_product(async_created_product, product_data):
result = async_created_product.name == product_data["name"]

Expand Down
13 changes: 0 additions & 13 deletions tests/e2e/catalog/product/test_sync_product.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
import pytest

from mpt_api_client import RQLQuery
from mpt_api_client.exceptions import MPTAPIError

pytestmark = [pytest.mark.flaky]


@pytest.fixture
def created_product(mpt_vendor, product_data, logo_fd):
product = mpt_vendor.catalog.products.create(product_data, file=logo_fd)

yield product

try:
mpt_vendor.catalog.products.delete(product.id)
except MPTAPIError as error:
print(f"TEARDOWN - Unable to delete product {product.id}: {error.title}") # noqa: WPS421


def test_create_product(created_product, product_data):
result = created_product.name == product_data["name"]

Expand Down
Loading
Loading