-
Notifications
You must be signed in to change notification settings - Fork 0
[MPT-14909] Added e2e tests for commerce order subscription #165
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-14909-add-e-2-e-tests-for-commerce-order-subscription
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import pytest | ||
| from freezegun import freeze_time | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def order_subscription_factory(agreement_subscription_line_id): | ||
| @freeze_time("2025-11-14T09:00:00.000Z") | ||
| def factory( | ||
| name: str = "E2E Created Order Subscription", | ||
| external_vendor_id: str = "ext-vendor-id", | ||
| ): | ||
| return { | ||
| "name": name, | ||
| "startDate": "2025-11-03T09:00:00.000Z", | ||
| "commitmentDate": "2026-11-02T09:00:00.000Z", | ||
| "autoRenew": True, | ||
| "externalIds": {"vendor": external_vendor_id}, | ||
| "template": None, | ||
| "lines": [{"id": agreement_subscription_line_id}], | ||
| "parameters": {"fulfillment": []}, | ||
| } | ||
|
|
||
| return factory | ||
103 changes: 103 additions & 0 deletions
103
tests/e2e/commerce/order/subscription/test_async_subscription.py
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,103 @@ | ||
| 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 subscription: {getattr(error, 'title', str(error))}") # noqa: WPS421 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def created_order_subscription(async_mpt_vendor, order_subscription_factory, order_id): | ||
| # Must use this fixture for all tests to prevent api failures | ||
| subscription_data = order_subscription_factory() | ||
| orders = async_mpt_vendor.commerce.orders | ||
| subscriptions = orders.subscriptions(order_id) | ||
| async with async_create_fixture_resource_and_delete( | ||
| subscriptions, subscription_data | ||
| ) as subscription: | ||
| yield subscription | ||
|
|
||
robcsegal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| async def test_get_order_subscription_by_id(async_mpt_vendor, created_order_subscription, order_id): | ||
| subscription_id = created_order_subscription.id | ||
| subscriptions = async_mpt_vendor.commerce.orders.subscriptions(order_id) | ||
|
|
||
| result = await subscriptions.get(subscription_id) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_list_order_subscriptions(async_mpt_vendor, created_order_subscription, order_id): | ||
| limit = 10 | ||
| orders = async_mpt_vendor.commerce.orders | ||
| subscriptions = orders.subscriptions(order_id) | ||
|
|
||
| result = await subscriptions.fetch_page(limit=limit) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_get_order_subscription_by_id_not_found( | ||
| async_mpt_vendor, created_order_subscription, order_id, invalid_subscription_id | ||
| ): | ||
| orders = async_mpt_vendor.commerce.orders | ||
| subscriptions = orders.subscriptions(order_id) | ||
|
|
||
| with pytest.raises(MPTAPIError, match="404 Not Found"): | ||
| await subscriptions.get(invalid_subscription_id) | ||
|
|
||
|
|
||
| async def test_filter_order_subscriptions(async_mpt_vendor, created_order_subscription, order_id): | ||
| select_fields = ["-externalIds"] | ||
| subscription_id = created_order_subscription.id | ||
| subscriptions = async_mpt_vendor.commerce.orders.subscriptions(order_id) | ||
| filtered_subscriptions = ( | ||
| subscriptions.filter(RQLQuery(id=subscription_id)) | ||
| .filter(RQLQuery(name="E2E Created Order Subscription")) | ||
| .select(*select_fields) | ||
| ) | ||
|
|
||
| result = [subscription async for subscription in filtered_subscriptions.iterate()] | ||
|
|
||
| assert len(result) == 1 | ||
|
|
||
|
|
||
| def test_create_order_subscription(created_order_subscription): | ||
| result = created_order_subscription | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_update_order_subscription(async_mpt_vendor, created_order_subscription, order_id): | ||
| subscription_id = created_order_subscription.id | ||
| updated_subscription_data = { | ||
| "name": "E2E Updated Order Subscription", | ||
| } | ||
| orders = async_mpt_vendor.commerce.orders | ||
| subscriptions = orders.subscriptions(order_id) | ||
|
|
||
| result = await subscriptions.update(subscription_id, updated_subscription_data) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_delete_order_subscription(async_mpt_vendor, created_order_subscription, order_id): | ||
| subscription_id = created_order_subscription.id | ||
| orders = async_mpt_vendor.commerce.orders | ||
|
|
||
| subscriptions = orders.subscriptions(order_id) | ||
| await subscriptions.delete(subscription_id) | ||
102 changes: 102 additions & 0 deletions
102
tests/e2e/commerce/order/subscription/test_sync_subscription.py
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,102 @@ | ||
| from contextlib import contextmanager | ||
|
|
||
| import pytest | ||
|
|
||
| from mpt_api_client.exceptions import MPTAPIError | ||
| from mpt_api_client.rql.query_builder import RQLQuery | ||
|
|
||
| pytestmark = [pytest.mark.flaky] | ||
|
|
||
|
|
||
| @contextmanager | ||
| def create_fixture_resource_and_delete(resource_manager, resource_data): | ||
| resource = resource_manager.create(resource_data) | ||
|
|
||
| yield resource | ||
|
|
||
| try: | ||
| resource_manager.delete(resource.id) | ||
| except MPTAPIError as error: | ||
| print(f"TEARDOWN - Unable to delete subscription: {getattr(error, 'title', str(error))}") # noqa: WPS421 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def created_order_subscription(mpt_vendor, order_subscription_factory, order_id): | ||
| # Must use this fixture for all tests to prevent api failures | ||
| subscription_data = order_subscription_factory() | ||
| orders = mpt_vendor.commerce.orders | ||
| subscriptions = orders.subscriptions(order_id) | ||
| with create_fixture_resource_and_delete(subscriptions, subscription_data) as subscription: | ||
| yield subscription | ||
|
|
||
robcsegal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def test_get_order_subscription_by_id(mpt_vendor, created_order_subscription, order_id): | ||
| subscription_id = created_order_subscription.id | ||
| subscriptions = mpt_vendor.commerce.orders.subscriptions(order_id) | ||
|
|
||
| result = subscriptions.get(subscription_id) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| def test_list_order_subscriptions(mpt_vendor, created_order_subscription, order_id): | ||
| limit = 10 | ||
| orders = mpt_vendor.commerce.orders | ||
| subscriptions = orders.subscriptions(order_id) | ||
|
|
||
| result = subscriptions.fetch_page(limit=limit) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| def test_get_order_subscription_by_id_not_found( | ||
| mpt_vendor, created_order_subscription, order_id, invalid_subscription_id | ||
| ): | ||
| orders = mpt_vendor.commerce.orders | ||
| subscriptions = orders.subscriptions(order_id) | ||
|
|
||
| with pytest.raises(MPTAPIError, match="404 Not Found"): | ||
| subscriptions.get(invalid_subscription_id) | ||
|
|
||
|
|
||
| def test_filter_order_subscriptions(mpt_vendor, created_order_subscription, order_id): | ||
| select_fields = ["-externalIds"] | ||
| subscription_id = created_order_subscription.id | ||
| subscriptions = mpt_vendor.commerce.orders.subscriptions(order_id) | ||
| filtered_subscriptions = ( | ||
| subscriptions.filter(RQLQuery(id=subscription_id)) | ||
| .filter(RQLQuery(name="E2E Created Order Subscription")) | ||
| .select(*select_fields) | ||
| ) | ||
|
|
||
| result = list(filtered_subscriptions.iterate()) | ||
|
|
||
| assert len(result) == 1 | ||
|
|
||
|
|
||
| def test_create_order_subscription(created_order_subscription): | ||
| result = created_order_subscription | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| def test_update_order_subscription(mpt_vendor, created_order_subscription, order_id): | ||
| subscription_id = created_order_subscription.id | ||
| updated_subscription_data = { | ||
| "name": "E2E Updated Order Subscription", | ||
| } | ||
| orders = mpt_vendor.commerce.orders | ||
| subscriptions = orders.subscriptions(order_id) | ||
|
|
||
| result = subscriptions.update(subscription_id, updated_subscription_data) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| def test_delete_order_subscription(mpt_vendor, created_order_subscription, order_id): | ||
| subscription_id = created_order_subscription.id | ||
| orders = mpt_vendor.commerce.orders | ||
|
|
||
| result = orders.subscriptions(order_id) | ||
|
|
||
| result.delete(subscription_id) | ||
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.