Skip to content

Commit 6738ddf

Browse files
author
Robert Segal
committed
Added sellers E2E tests
1 parent 262d20c commit 6738ddf

7 files changed

Lines changed: 302 additions & 1 deletion

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,6 @@ cython_debug/
170170

171171
# VS Code dev container
172172
.devcontainer/
173+
174+
# E2E report
175+
e2e-report.xml

e2e_config.test.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"catalog.product.id": "PRD-7255-3950"
2+
"catalog.product.id": "PRD-7255-3950",
3+
"accounts.seller.id": "SEL-7310-3075"
34
}

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ per-file-ignores =
4747
tests/unit/resources/*/test_mixins.py: WPS118 WPS202 WPS204 WPS235
4848
tests/unit/resources/accounts/test_users.py: WPS204 WPS202 WPS210
4949
tests/unit/test_mpt_client.py: WPS235
50+
tests/e2e/accounts/conftest.py: WPS430
5051

5152
tests/*:
5253
# Allow magic strings.

tests/e2e/accounts/conftest.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import datetime as dt
2+
import pathlib
3+
4+
import pytest
5+
6+
7+
@pytest.fixture(scope="session")
8+
def timestamp():
9+
return int(dt.datetime.now(tz=dt.UTC).strftime("%Y%m%d%H%M%S"))
10+
11+
12+
@pytest.fixture
13+
def account_data():
14+
return {
15+
"name": "Test Api Client Vendor",
16+
"address": {
17+
"addressLine1": "123 Test St",
18+
"city": "San Francisco",
19+
"state": "CA",
20+
"postCode": "12345",
21+
"country": "US",
22+
},
23+
"type": "Vendor",
24+
"status": "Active",
25+
}
26+
27+
28+
@pytest.fixture
29+
def account_icon():
30+
return pathlib.Path(__file__).parent / "logo.png"
31+
32+
33+
@pytest.fixture
34+
def currencies():
35+
return ["USD", "EUR"]
36+
37+
38+
@pytest.fixture
39+
def seller(currencies):
40+
def _seller(
41+
external_id: str, # Must be unique in Marketplace
42+
name="E2E Test Seller",
43+
currencies=currencies,
44+
):
45+
return {
46+
"name": name,
47+
"address": {
48+
"addressLine1": "123 Main St",
49+
"city": "Anytown",
50+
"state": "CA",
51+
"postCode": "12345",
52+
"country": "US",
53+
},
54+
"currencies": currencies,
55+
"externalId": external_id,
56+
}
57+
58+
return _seller
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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.mark.flaky
11+
async def test_get_seller_by_id(async_mpt_ops, seller_id):
12+
seller = await async_mpt_ops.accounts.sellers.get(seller_id)
13+
assert seller is not None
14+
15+
16+
async def test_list_sellers(async_mpt_ops):
17+
sellers = await async_mpt_ops.accounts.sellers.fetch_page(limit=10)
18+
assert len(sellers) > 0
19+
20+
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+
async def test_filter_sellers(async_mpt_ops, seller_id):
27+
select_fields = ["-address"]
28+
29+
async_filtered_sellers = (
30+
async_mpt_ops.accounts.sellers.filter(RQLQuery(id=seller_id))
31+
.filter(RQLQuery(name="E2E Seeded Seller"))
32+
.select(*select_fields)
33+
)
34+
35+
sellers = [filtered_seller async for filtered_seller in async_filtered_sellers.iterate()]
36+
37+
assert len(sellers) == 1
38+
39+
40+
async def test_create_seller(async_mpt_ops, seller, timestamp):
41+
seller_data = seller(external_id=f"Async Create E2E Seller - {timestamp}")
42+
created_seller = await async_mpt_ops.accounts.sellers.create(seller_data)
43+
assert created_seller is not None
44+
45+
46+
async def test_delete_seller(async_mpt_ops, seller, timestamp):
47+
seller_data = seller(external_id=f"Async Delete E2E Seller - {timestamp}")
48+
created_seller = await async_mpt_ops.accounts.sellers.create(seller_data)
49+
await async_mpt_ops.accounts.sellers.delete(created_seller.id)
50+
51+
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+
async def test_update_seller(async_mpt_ops, seller, timestamp):
58+
seller_data = seller(external_id=f"Async Update E2E Seller - {timestamp}")
59+
update_data = seller(
60+
external_id=f"Async Update E2E Seller - {timestamp}",
61+
name=f"Updated Update E2E Seller - {timestamp}",
62+
)
63+
created_seller = await async_mpt_ops.accounts.sellers.create(seller_data)
64+
updated_seller = await async_mpt_ops.accounts.sellers.update(created_seller.id, update_data)
65+
assert updated_seller is not None
66+
67+
68+
async def test_update_seller_mpt_error(async_mpt_ops, seller, timestamp, invalid_seller_id):
69+
update_data = seller(
70+
external_id=f"Async Update E2E Seller Not Found - {timestamp}",
71+
name=f"Updated Update E2E Seller Not Found - {timestamp}",
72+
)
73+
with pytest.raises(MPTAPIError):
74+
await async_mpt_ops.accounts.sellers.update(invalid_seller_id, update_data)
75+
76+
77+
async def test_activate_seller(async_mpt_ops, seller, timestamp):
78+
seller_data = seller(external_id=f"Async Activate E2E Seller - {timestamp}")
79+
created_seller = await async_mpt_ops.accounts.sellers.create(seller_data)
80+
await async_mpt_ops.accounts.sellers.deactivate(created_seller.id)
81+
activated_seller = await async_mpt_ops.accounts.sellers.activate(created_seller.id)
82+
83+
assert activated_seller is not None
84+
85+
86+
async def test_activate_seller_mpt_error(async_mpt_ops, invalid_seller_id):
87+
with pytest.raises(MPTAPIError):
88+
await async_mpt_ops.accounts.sellers.activate(invalid_seller_id)
89+
90+
91+
async def test_deactivate_seller(async_mpt_ops, seller, timestamp):
92+
seller_data = seller(external_id=f"Async Deactivate E2E Seller - {timestamp}")
93+
created_seller = await async_mpt_ops.accounts.sellers.create(seller_data)
94+
deactivated_seller = await async_mpt_ops.accounts.sellers.deactivate(created_seller.id)
95+
96+
assert deactivated_seller is not None
97+
98+
99+
async def test_deactivate_seller_mpt_error(async_mpt_ops, invalid_seller_id):
100+
with pytest.raises(MPTAPIError):
101+
await async_mpt_ops.accounts.sellers.deactivate(invalid_seller_id)
102+
103+
104+
async def test_disable_seller(async_mpt_ops, seller, timestamp):
105+
seller_data = seller(external_id=f"Async Disable E2E Seller - {timestamp}")
106+
created_seller = await async_mpt_ops.accounts.sellers.create(seller_data)
107+
disabled_seller = await async_mpt_ops.accounts.sellers.disable(created_seller.id)
108+
109+
assert disabled_seller is not None
110+
111+
112+
async def test_disable_seller_mpt_error(async_mpt_ops, invalid_seller_id):
113+
with pytest.raises(MPTAPIError):
114+
await async_mpt_ops.accounts.sellers.disable(invalid_seller_id)
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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.mark.flaky
11+
def test_get_seller_by_id(mpt_ops, seller_id):
12+
seller = mpt_ops.accounts.sellers.get(seller_id)
13+
assert seller is not None
14+
15+
16+
def test_list_sellers(mpt_ops):
17+
sellers = mpt_ops.accounts.sellers.fetch_page(limit=10)
18+
assert len(sellers) > 0
19+
20+
21+
def test_get_seller_by_id_not_found(mpt_ops, invalid_seller_id):
22+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
23+
mpt_ops.accounts.sellers.get(invalid_seller_id)
24+
25+
26+
def test_filter_sellers(mpt_ops, seller_id):
27+
select_fields = ["-address"]
28+
29+
filtered_sellers = (
30+
mpt_ops.accounts.sellers.filter(RQLQuery(id=seller_id))
31+
.filter(RQLQuery(name="E2E Seeded Seller"))
32+
.select(*select_fields)
33+
)
34+
35+
sellers = list(filtered_sellers.iterate())
36+
37+
assert len(sellers) == 1
38+
39+
40+
def test_create_seller(mpt_ops, seller, timestamp):
41+
seller_data = seller(external_id=f"Create E2E Seller - {timestamp}")
42+
created_seller = mpt_ops.accounts.sellers.create(seller_data)
43+
assert created_seller is not None
44+
45+
46+
def test_delete_seller(mpt_ops, seller, timestamp):
47+
seller_data = seller(external_id=f"Delete E2E Seller - {timestamp}")
48+
created_seller = mpt_ops.accounts.sellers.create(seller_data)
49+
mpt_ops.accounts.sellers.delete(created_seller.id)
50+
51+
52+
def test_delete_seller_not_found(mpt_ops, invalid_seller_id):
53+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
54+
mpt_ops.accounts.sellers.delete(invalid_seller_id)
55+
56+
57+
def test_update_seller(mpt_ops, seller, timestamp):
58+
seller_data = seller(external_id=f"Update E2E Seller - {timestamp}")
59+
update_data = seller(
60+
external_id=f"Update E2E Seller - {timestamp}",
61+
name=f"Updated Update E2E Seller - {timestamp}",
62+
)
63+
created_seller = mpt_ops.accounts.sellers.create(seller_data)
64+
updated_seller = mpt_ops.accounts.sellers.update(created_seller.id, update_data)
65+
assert updated_seller is not None
66+
67+
68+
def test_update_seller_mpt_error(mpt_ops, seller, timestamp, invalid_seller_id):
69+
update_data = seller(
70+
external_id=f"Async Update E2E Seller Not Found - {timestamp}",
71+
name=f"Updated Update E2E Seller Not Found - {timestamp}",
72+
)
73+
with pytest.raises(MPTAPIError):
74+
mpt_ops.accounts.sellers.update(invalid_seller_id, update_data)
75+
76+
77+
def test_activate_seller(mpt_ops, seller, timestamp):
78+
seller_data = seller(external_id=f"Activate E2E Seller - {timestamp}")
79+
created_seller = mpt_ops.accounts.sellers.create(seller_data)
80+
mpt_ops.accounts.sellers.deactivate(created_seller.id)
81+
activated_seller = mpt_ops.accounts.sellers.activate(created_seller.id)
82+
83+
assert activated_seller is not None
84+
85+
86+
def test_activate_seller_mpt_error(mpt_ops, invalid_seller_id):
87+
with pytest.raises(MPTAPIError):
88+
mpt_ops.accounts.sellers.activate(invalid_seller_id)
89+
90+
91+
def test_deactivate_seller(mpt_ops, seller, timestamp):
92+
seller_data = seller(external_id=f"Deactivate E2E Seller - {timestamp}")
93+
created_seller = mpt_ops.accounts.sellers.create(seller_data)
94+
deactivated_seller = mpt_ops.accounts.sellers.deactivate(created_seller.id)
95+
96+
assert deactivated_seller is not None
97+
98+
99+
def test_deactivate_seller_mpt_error(mpt_ops, invalid_seller_id):
100+
with pytest.raises(MPTAPIError):
101+
mpt_ops.accounts.sellers.deactivate(invalid_seller_id)
102+
103+
104+
def test_disable_seller(mpt_ops, seller, timestamp):
105+
seller_data = seller(external_id=f"Disable E2E Seller - {timestamp}")
106+
created_seller = mpt_ops.accounts.sellers.create(seller_data)
107+
disabled_seller = mpt_ops.accounts.sellers.disable(created_seller.id)
108+
109+
assert disabled_seller is not None
110+
111+
112+
def test_disable_seller_mpt_error(mpt_ops, invalid_seller_id):
113+
with pytest.raises(MPTAPIError):
114+
mpt_ops.accounts.sellers.disable(invalid_seller_id)

tests/e2e/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,13 @@ def e2e_config(project_root_path):
7878
@pytest.fixture
7979
def product_id(e2e_config):
8080
return e2e_config["catalog.product.id"]
81+
82+
83+
@pytest.fixture
84+
def invalid_seller_id():
85+
return "SEL-0000-0000"
86+
87+
88+
@pytest.fixture
89+
def seller_id(e2e_config):
90+
return e2e_config["accounts.seller.id"]

0 commit comments

Comments
 (0)