|
| 1 | +import pytest |
| 2 | + |
| 3 | +from mpt_api_client.exceptions import MPTAPIError |
| 4 | +from mpt_api_client.rql.query_builder import RQLQuery |
| 5 | + |
| 6 | +pytestmark = [pytest.mark.flaky] |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture |
| 10 | +async def created_subscription(async_mpt_vendor, subscription_factory): |
| 11 | + subscription_data = subscription_factory() |
| 12 | + |
| 13 | + subscription = await async_mpt_vendor.commerce.subscriptions.create(subscription_data) |
| 14 | + |
| 15 | + yield subscription |
| 16 | + |
| 17 | + try: |
| 18 | + await async_mpt_vendor.commerce.subscriptions.terminate(subscription.id) |
| 19 | + except MPTAPIError as error: |
| 20 | + print(f"TEARDOWN - Unable to terminate subscription: {getattr(error, 'title', str(error))}") # noqa: WPS421 |
| 21 | + |
| 22 | + |
| 23 | +async def test_get_subscription_by_id(async_mpt_vendor, subscription_id): |
| 24 | + result = await async_mpt_vendor.commerce.subscriptions.get(subscription_id) |
| 25 | + |
| 26 | + assert result is not None |
| 27 | + |
| 28 | + |
| 29 | +async def test_list_subscriptions(async_mpt_vendor): |
| 30 | + limit = 10 |
| 31 | + |
| 32 | + result = await async_mpt_vendor.commerce.subscriptions.fetch_page(limit=limit) |
| 33 | + |
| 34 | + assert result is not None |
| 35 | + |
| 36 | + |
| 37 | +async def test_get_subscription_by_id_not_found(async_mpt_vendor, invalid_subscription_id): |
| 38 | + with pytest.raises(MPTAPIError, match="404 Not Found"): |
| 39 | + await async_mpt_vendor.commerce.subscriptions.get(invalid_subscription_id) |
| 40 | + |
| 41 | + |
| 42 | +async def test_filter_subscriptions(async_mpt_vendor, subscription_id): |
| 43 | + select_fields = ["-externalIds"] |
| 44 | + filtered_subscriptions = ( |
| 45 | + async_mpt_vendor.commerce.subscriptions.filter(RQLQuery(id=subscription_id)) |
| 46 | + .filter(RQLQuery(name="E2E Seeded Subscription")) |
| 47 | + .select(*select_fields) |
| 48 | + ) |
| 49 | + |
| 50 | + result = [subscription async for subscription in filtered_subscriptions.iterate()] |
| 51 | + |
| 52 | + assert len(result) == 1 |
| 53 | + |
| 54 | + |
| 55 | +def test_create_subscription(created_subscription): |
| 56 | + result = created_subscription |
| 57 | + |
| 58 | + assert result is not None |
| 59 | + |
| 60 | + |
| 61 | +async def test_update_subscription(async_mpt_vendor, created_subscription): |
| 62 | + updated_subscription_data = { |
| 63 | + "name": "E2E Updated Subscription", |
| 64 | + } |
| 65 | + |
| 66 | + result = await async_mpt_vendor.commerce.subscriptions.update( |
| 67 | + created_subscription.id, updated_subscription_data |
| 68 | + ) |
| 69 | + |
| 70 | + assert result is not None |
| 71 | + |
| 72 | + |
| 73 | +async def test_terminate_subscription(async_mpt_vendor, created_subscription): |
| 74 | + result = await async_mpt_vendor.commerce.subscriptions.terminate(created_subscription.id) |
| 75 | + |
| 76 | + assert result is not None |
| 77 | + |
| 78 | + |
| 79 | +async def test_render_subscription(async_mpt_vendor, created_subscription): |
| 80 | + result = await async_mpt_vendor.commerce.subscriptions.render(created_subscription.id) |
| 81 | + |
| 82 | + assert result is not None |
0 commit comments