-
Notifications
You must be signed in to change notification settings - Fork 0
[MPT-16219] Added e2e tests for commerce orders #160
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
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
Some comments aren't visible on the classic Files Changed page.
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,72 @@ | ||
| import pytest | ||
| from freezegun import freeze_time | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def invalid_order_id(): | ||
| return "ORD-0000-0000" | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| @freeze_time("2025-12-01T10:00:00.000Z") | ||
| def order_factory(licensee_id, commerce_product_id, commerce_item_id, authorization_id): | ||
| def factory( | ||
| notes: str = "E2E Created Order", | ||
| line_item_period: str = "1y", | ||
| line_item_commitment: str = "1y", | ||
| line_quantity: int = 10, | ||
| ): | ||
| return { | ||
| "agreement": { | ||
| "licensee": {"id": licensee_id}, | ||
| "product": {"id": commerce_product_id}, | ||
| }, | ||
| "authorization": {"id": authorization_id}, | ||
| "type": "Purchase", | ||
| "status": "Draft", | ||
| "parameters": { | ||
| "ordering": [], | ||
| "fulfillment": [], | ||
| }, | ||
| "notes": notes, | ||
| "lines": [ | ||
| { | ||
| "item": { | ||
| "id": commerce_item_id, | ||
| "terms": { | ||
| "model": "quantity", | ||
| "period": line_item_period, | ||
| "commitment": line_item_commitment, | ||
| }, | ||
| }, | ||
| "price": { | ||
| "currency": "USD", | ||
| "unitSP": 15, | ||
| "SPx1": None, | ||
| "SPxM": 1.25, | ||
| "SPxY": 15, | ||
| }, | ||
| "quantity": line_quantity, | ||
| } | ||
| ], | ||
| } | ||
|
|
||
| return factory | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def order_subscription_factory(): | ||
| def factory( | ||
| line_id: str, | ||
| name: str = "E2E Created Order Subscription", | ||
| ): | ||
| return { | ||
| "name": name, | ||
| "parameters": {"fulfillment": []}, | ||
| "lines": [{"id": line_id}], | ||
| "terms": {"model": "quantity", "period": "1y", "commitment": "1y"}, | ||
| "autoRenew": True, | ||
| "template": None, | ||
| } | ||
|
|
||
| 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,141 @@ | ||
| import pytest | ||
|
|
||
| from mpt_api_client.exceptions import MPTAPIError | ||
| from mpt_api_client.rql.query_builder import RQLQuery | ||
|
|
||
| pytestmark = [pytest.mark.flaky] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def created_order(async_mpt_client, order_factory): | ||
| new_order_request_data = order_factory() | ||
|
|
||
| return await async_mpt_client.commerce.orders.create(new_order_request_data) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def processed_order(async_mpt_client, created_order): | ||
| return await async_mpt_client.commerce.orders.process(created_order.id) | ||
|
|
||
|
|
||
| async def test_get_order_by_id(async_mpt_client, order_id): | ||
| result = await async_mpt_client.commerce.orders.get(order_id) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_list_orders(async_mpt_client): | ||
| limit = 10 | ||
|
|
||
| result = await async_mpt_client.commerce.orders.fetch_page(limit=limit) | ||
|
|
||
| assert len(result) > 0 | ||
|
|
||
|
|
||
| async def test_get_order_by_id_not_found(async_mpt_client, invalid_order_id): | ||
| with pytest.raises(MPTAPIError, match=r"404 Not Found"): | ||
| await async_mpt_client.commerce.orders.get(invalid_order_id) | ||
|
|
||
|
|
||
| async def test_filter_orders(async_mpt_client, order_id): | ||
| select_fields = ["-authorization"] | ||
| filtered_orders = ( | ||
| async_mpt_client.commerce.orders.filter(RQLQuery(id=order_id)) | ||
| .filter(RQLQuery(type="Purchase")) | ||
| .select(*select_fields) | ||
| ) | ||
|
|
||
| result = [order async for order in filtered_orders.iterate()] | ||
|
|
||
| assert len(result) == 1 | ||
|
|
||
|
|
||
| def test_create_order(created_order): | ||
| result = created_order | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_update_order(async_mpt_client, created_order, order_factory): | ||
| update_data = order_factory(notes="E2E Updated Order Notes") | ||
|
|
||
| result = await async_mpt_client.commerce.orders.update(created_order.id, update_data) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_process_order(async_mpt_client, created_order): | ||
| result = await async_mpt_client.commerce.orders.process(created_order.id) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_query_order(async_mpt_vendor, async_mpt_client, created_order): | ||
| processed_order = await async_mpt_client.commerce.orders.process(created_order.id) | ||
|
|
||
| result = await async_mpt_vendor.commerce.orders.query(processed_order.id) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_complete_order(async_mpt_vendor, order_subscription_factory, processed_order): | ||
| processed_order_lines = processed_order.lines | ||
| line_id = processed_order_lines[0].id | ||
| order_subscription = order_subscription_factory(line_id) | ||
| order_subscriptions = async_mpt_vendor.commerce.orders.subscriptions(processed_order.id) | ||
| await order_subscriptions.create(order_subscription) | ||
|
|
||
| result = await async_mpt_vendor.commerce.orders.complete(processed_order.id) | ||
|
|
||
| assert result is not None | ||
|
|
||
robcsegal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| async def test_fail_order(async_mpt_vendor, processed_order): | ||
| fail_order_data = { | ||
| "statusNotes": { | ||
| "message": "Failing order for E2E test", | ||
| "id": processed_order.id, | ||
| } | ||
| } | ||
|
|
||
| result = await async_mpt_vendor.commerce.orders.fail(processed_order.id, fail_order_data) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_delete_draft_order(async_mpt_client, created_order): | ||
| await async_mpt_client.commerce.orders.delete(created_order.id) | ||
|
|
||
|
|
||
| async def test_quote_order(async_mpt_client, created_order): | ||
| result = await async_mpt_client.commerce.orders.quote(created_order.id) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_validate_order(async_mpt_client, created_order): | ||
| result = await async_mpt_client.commerce.orders.validate(created_order.id) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_order_template(async_mpt_client, created_order): | ||
| result = await async_mpt_client.commerce.orders.template(created_order.id) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_order_render(async_mpt_client, created_order): | ||
| result = await async_mpt_client.commerce.orders.render(created_order.id) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_notify_order(async_mpt_client, created_order, commerce_user_id): | ||
| user_data = { | ||
| "userId": commerce_user_id, | ||
| "notifyMe": False, | ||
| } | ||
| await async_mpt_client.commerce.orders.quote(created_order.id) | ||
|
|
||
| await async_mpt_client.commerce.orders.notify(created_order.id, user_data) | ||
robcsegal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.