|
| 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 | +# TODO: Handle create and teardown more gracefully with fixture that doesn't cause teardown issues |
| 10 | +@pytest.fixture |
| 11 | +async def async_created_seller(async_mpt_ops, seller): |
| 12 | + ret_seller = None |
| 13 | + |
| 14 | + async def _async_created_seller( |
| 15 | + external_id: str, |
| 16 | + name: str = "E2E Test Seller", |
| 17 | + ): |
| 18 | + nonlocal ret_seller |
| 19 | + seller_data = seller(external_id=external_id, name=name) |
| 20 | + ret_seller = await async_mpt_ops.accounts.sellers.create(seller_data) |
| 21 | + return ret_seller |
| 22 | + |
| 23 | + yield _async_created_seller |
| 24 | + |
| 25 | + if ret_seller: |
| 26 | + try: |
| 27 | + await async_mpt_ops.accounts.sellers.delete(ret_seller.id) |
| 28 | + except MPTAPIError as error: |
| 29 | + print(f"TEARDOWN - Unable to delete seller {ret_seller.id}: {error}") |
| 30 | + |
| 31 | + |
| 32 | +async def test_get_seller_by_id(async_mpt_ops, seller_id): |
| 33 | + seller = await async_mpt_ops.accounts.sellers.get(seller_id) |
| 34 | + assert seller is not None |
| 35 | + |
| 36 | + |
| 37 | +async def test_list_sellers(async_mpt_ops): |
| 38 | + sellers = await async_mpt_ops.accounts.sellers.fetch_page(limit=10) |
| 39 | + assert len(sellers) > 0 |
| 40 | + |
| 41 | + |
| 42 | +async def test_get_seller_by_id_not_found(async_mpt_ops, invalid_seller_id): |
| 43 | + with pytest.raises(MPTAPIError, match=r"404 Not Found"): |
| 44 | + await async_mpt_ops.accounts.sellers.get(invalid_seller_id) |
| 45 | + |
| 46 | + |
| 47 | +async def test_filter_sellers(async_mpt_ops, seller_id): |
| 48 | + select_fields = ["-address"] |
| 49 | + |
| 50 | + async_filtered_sellers = ( |
| 51 | + async_mpt_ops.accounts.sellers.filter(RQLQuery(id=seller_id)) |
| 52 | + .filter(RQLQuery(name="E2E Seeded Seller")) |
| 53 | + .select(*select_fields) |
| 54 | + ) |
| 55 | + |
| 56 | + sellers = [filtered_seller async for filtered_seller in async_filtered_sellers.iterate()] |
| 57 | + |
| 58 | + assert len(sellers) == 1 |
| 59 | + |
| 60 | + |
| 61 | +async def test_create_seller(async_created_seller, timestamp): |
| 62 | + seller_data = await async_created_seller(external_id=f"Async Create E2E Seller - {timestamp}") |
| 63 | + assert seller_data is not None |
| 64 | + |
| 65 | + |
| 66 | +async def test_delete_seller(async_mpt_ops, async_created_seller, timestamp): |
| 67 | + seller_data = await async_created_seller(external_id=f"Async Delete E2E Seller - {timestamp}") |
| 68 | + await async_mpt_ops.accounts.sellers.delete(seller_data.id) |
| 69 | + |
| 70 | + |
| 71 | +async def test_delete_seller_not_found(async_mpt_ops, invalid_seller_id): |
| 72 | + with pytest.raises(MPTAPIError, match=r"404 Not Found"): |
| 73 | + await async_mpt_ops.accounts.sellers.delete(invalid_seller_id) |
| 74 | + |
| 75 | + |
| 76 | +async def test_update_seller(async_mpt_ops, seller, async_created_seller, timestamp): |
| 77 | + seller_data = await async_created_seller(external_id=f"Async Update E2E Seller - {timestamp}") |
| 78 | + update_data = seller( |
| 79 | + external_id=f"Async Update E2E Seller - {timestamp}", |
| 80 | + name=f"Updated Update E2E Seller - {timestamp}", |
| 81 | + ) |
| 82 | + updated_seller = await async_mpt_ops.accounts.sellers.update(seller_data.id, update_data) |
| 83 | + assert updated_seller is not None |
| 84 | + |
| 85 | + |
| 86 | +async def test_update_seller_mpt_error(async_mpt_ops, seller, timestamp, invalid_seller_id): |
| 87 | + update_data = seller( |
| 88 | + external_id=f"Async Update E2E Seller Not Found - {timestamp}", |
| 89 | + name=f"Updated Update E2E Seller Not Found - {timestamp}", |
| 90 | + ) |
| 91 | + with pytest.raises(MPTAPIError): |
| 92 | + await async_mpt_ops.accounts.sellers.update(invalid_seller_id, update_data) |
| 93 | + |
| 94 | + |
| 95 | +async def test_activate_seller(async_mpt_ops, async_created_seller, timestamp): |
| 96 | + seller_data = await async_created_seller(external_id=f"Async Activate E2E Seller - {timestamp}") |
| 97 | + await async_mpt_ops.accounts.sellers.deactivate(seller_data.id) |
| 98 | + activated_seller = await async_mpt_ops.accounts.sellers.activate(seller_data.id) |
| 99 | + |
| 100 | + assert activated_seller is not None |
| 101 | + |
| 102 | + |
| 103 | +async def test_activate_seller_mpt_error(async_mpt_ops, invalid_seller_id): |
| 104 | + with pytest.raises(MPTAPIError): |
| 105 | + await async_mpt_ops.accounts.sellers.activate(invalid_seller_id) |
| 106 | + |
| 107 | + |
| 108 | +async def test_deactivate_seller(async_mpt_ops, async_created_seller, timestamp): |
| 109 | + seller_data = await async_created_seller( |
| 110 | + external_id=f"Async Deactivate E2E Seller - {timestamp}" |
| 111 | + ) |
| 112 | + deactivated_seller = await async_mpt_ops.accounts.sellers.deactivate(seller_data.id) |
| 113 | + |
| 114 | + assert deactivated_seller is not None |
| 115 | + |
| 116 | + |
| 117 | +async def test_deactivate_seller_mpt_error(async_mpt_ops, invalid_seller_id): |
| 118 | + with pytest.raises(MPTAPIError): |
| 119 | + await async_mpt_ops.accounts.sellers.deactivate(invalid_seller_id) |
| 120 | + |
| 121 | + |
| 122 | +async def test_disable_seller(async_mpt_ops, async_created_seller, timestamp): |
| 123 | + seller_data = await async_created_seller(external_id=f"Async Disable E2E Seller - {timestamp}") |
| 124 | + disabled_seller = await async_mpt_ops.accounts.sellers.disable(seller_data.id) |
| 125 | + |
| 126 | + assert disabled_seller is not None |
| 127 | + |
| 128 | + |
| 129 | +async def test_disable_seller_mpt_error(async_mpt_ops, invalid_seller_id): |
| 130 | + with pytest.raises(MPTAPIError): |
| 131 | + await async_mpt_ops.accounts.sellers.disable(invalid_seller_id) |
0 commit comments