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