-
Notifications
You must be signed in to change notification settings - Fork 0
[MPT-16318] Added e2e tests for commerce order assets #166
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
Merged
robcsegal
merged 1 commit into
main
from
MPT-16318-add-e-2-e-tests-for-commerce-order-assets
Dec 16, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def draft_order_asset_agreement_id(e2e_config): | ||
| return e2e_config["commerce.assets.draft.order.agreement.id"] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def asset_agreement_line_id(e2e_config): | ||
| return e2e_config["commerce.assets.agreement.line.id"] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def commerce_asset_draft_order_id(e2e_config): | ||
| return e2e_config["commerce.assets.draft.order.id"] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def order_asset_factory( | ||
| draft_order_asset_agreement_id, | ||
| buyer_id, | ||
| asset_agreement_line_id, | ||
| buyer_account_id, | ||
| seller_id, | ||
| commerce_product_id, | ||
| commerce_asset_draft_order_id, | ||
| ): | ||
| def factory( | ||
| name: str = "E2E Created Order Asset", | ||
| quantity: int = 1, | ||
| external_vendor_id: str = "ext-vendor-id", | ||
| ): | ||
| return { | ||
| "name": name, | ||
| "externalIds": {"vendor": external_vendor_id}, | ||
| "lines": [ | ||
| { | ||
| "id": asset_agreement_line_id, | ||
| "agreement": {"id": draft_order_asset_agreement_id}, | ||
| "buyer": {"id": buyer_id}, | ||
| "client": {"id": buyer_account_id}, | ||
| "oldQuantity": 0, | ||
| "quantity": quantity, | ||
| "price": { | ||
| "unitPP": 10, | ||
| "PPx1": 100, | ||
| "currency": "USD", | ||
| }, | ||
| } | ||
| ], | ||
| "order": {"id": commerce_asset_draft_order_id}, | ||
| "product": {"id": commerce_product_id}, | ||
| "seller": {"id": seller_id}, | ||
| } | ||
|
|
||
| return factory |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| from contextlib import asynccontextmanager | ||
|
|
||
| import pytest | ||
|
|
||
| from mpt_api_client.exceptions import MPTAPIError | ||
| from mpt_api_client.rql.query_builder import RQLQuery | ||
|
|
||
| pytestmark = [pytest.mark.flaky] | ||
|
|
||
|
|
||
| @asynccontextmanager | ||
| async def async_create_fixture_resource_and_delete(resource_manager, resource_data): | ||
| resource = await resource_manager.create(resource_data) | ||
|
|
||
| yield resource | ||
|
|
||
| try: | ||
| await resource_manager.delete(resource.id) | ||
| except MPTAPIError as error: | ||
| print(f"TEARDOWN - Unable to delete order asset: {getattr(error, 'title', str(error))}") # noqa: WPS421 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def created_order_asset(async_mpt_vendor, order_asset_factory, commerce_asset_draft_order_id): | ||
| # Must use this fixture for all tests to prevent api errors | ||
| asset_data = order_asset_factory() | ||
| orders = async_mpt_vendor.commerce.orders | ||
| assets = orders.assets(commerce_asset_draft_order_id) | ||
| async with async_create_fixture_resource_and_delete(assets, asset_data) as asset: | ||
| yield asset | ||
|
|
||
|
|
||
| async def test_get_order_asset_by_id( | ||
| async_mpt_vendor, created_order_asset, commerce_asset_draft_order_id | ||
| ): | ||
| asset_id = created_order_asset.id | ||
| orders = async_mpt_vendor.commerce.orders.assets(commerce_asset_draft_order_id) | ||
|
|
||
| result = await orders.get(asset_id) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_list_order_assets( | ||
| async_mpt_vendor, created_order_asset, commerce_asset_draft_order_id | ||
| ): | ||
| limit = 10 | ||
| orders = async_mpt_vendor.commerce.orders | ||
| assets = orders.assets(commerce_asset_draft_order_id) | ||
|
|
||
| result = await assets.fetch_page(limit=limit) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_get_order_asset_by_id_not_found( | ||
| async_mpt_vendor, created_order_asset, commerce_asset_draft_order_id, invalid_asset_id | ||
| ): | ||
| orders = async_mpt_vendor.commerce.orders | ||
| assets = orders.assets(commerce_asset_draft_order_id) | ||
|
|
||
| with pytest.raises(MPTAPIError, match="404 Not Found"): | ||
| await assets.get(invalid_asset_id) | ||
|
|
||
|
|
||
| async def test_filter_order_assets( | ||
| async_mpt_vendor, created_order_asset, commerce_asset_draft_order_id | ||
| ): | ||
| select_fields = ["-externalIds"] | ||
| asset_id = created_order_asset.id | ||
| assets = async_mpt_vendor.commerce.orders.assets(commerce_asset_draft_order_id) | ||
| filtered_assets = ( | ||
| assets.filter(RQLQuery(id=asset_id)) | ||
| .filter(RQLQuery(name="E2E Created Order Asset")) | ||
| .select(*select_fields) | ||
| ) | ||
|
|
||
| result = [asset async for asset in filtered_assets.iterate()] | ||
|
|
||
| assert len(result) == 1 | ||
|
|
||
|
|
||
| def test_create_order_asset(created_order_asset): | ||
| result = created_order_asset | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_update_order_asset( | ||
| async_mpt_vendor, | ||
| created_order_asset, | ||
| commerce_asset_draft_order_id, | ||
| ): | ||
| asset_id = created_order_asset.id | ||
| updated_asset_data = { | ||
| "name": "E2E Updated Order Asset", | ||
| } | ||
| orders = async_mpt_vendor.commerce.orders | ||
| assets = orders.assets(commerce_asset_draft_order_id) | ||
|
|
||
| result = await assets.update(asset_id, updated_asset_data) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_delete_order_asset( | ||
| async_mpt_vendor, | ||
| created_order_asset, | ||
| commerce_asset_draft_order_id, | ||
| ): | ||
| asset_id = created_order_asset.id | ||
| orders = async_mpt_vendor.commerce.orders | ||
|
|
||
| result = orders.assets(commerce_asset_draft_order_id) | ||
|
|
||
| await result.delete(asset_id) | ||
|
|
||
|
|
||
| async def test_render_order_asset( | ||
| async_mpt_vendor, | ||
| created_order_asset, | ||
| commerce_asset_draft_order_id, | ||
| ): | ||
| asset_id = created_order_asset.id | ||
| orders = async_mpt_vendor.commerce.orders | ||
| assets = orders.assets(commerce_asset_draft_order_id) | ||
|
|
||
| result = await assets.render(asset_id) | ||
|
|
||
| assert result is not None |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.