Skip to content

Commit cbed638

Browse files
author
Robert Segal
committed
Added accounts api tokens e2e tests
1 parent 316148e commit cbed638

13 files changed

Lines changed: 308 additions & 60 deletions

e2e_config.test.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"catalog.product.parameter.id": "PAR-7255-3950-0016",
1313
"catalog.product.document.id": "PDC-7255-3950-0001",
1414
"catalog.item.id": "ITM-7255-3950-0001",
15-
"catalog.unit.id": "UNT-1229"
15+
"catalog.unit.id": "UNT-1229",
16+
"accounts.api_token.id": "TKN-8857-1729"
1617
}

tests/e2e/accounts/account/test_async_account.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88

99
@pytest.fixture
10-
async def async_created_account(logger, async_mpt_ops, account, account_icon):
11-
account_data = account()
10+
async def async_created_account(logger, async_mpt_ops, account_factory, account_icon):
11+
account_data = account_factory()
1212

1313
res_account = await async_mpt_ops.accounts.accounts.create(account_data, logo=account_icon)
1414

@@ -41,8 +41,8 @@ def test_create_account(async_created_account):
4141
assert account is not None
4242

4343

44-
async def test_update_account(async_mpt_ops, async_created_account, account, account_icon):
45-
updated_data = account(name="Updated Account Name")
44+
async def test_update_account(async_mpt_ops, async_created_account, account_factory, account_icon):
45+
updated_data = account_factory(name="Updated Account Name")
4646

4747
updated_account = await async_mpt_ops.accounts.accounts.update(
4848
async_created_account.id, updated_data, logo=account_icon
@@ -52,26 +52,28 @@ async def test_update_account(async_mpt_ops, async_created_account, account, acc
5252

5353

5454
async def test_update_account_invalid_data(
55-
async_mpt_ops, account, async_created_account, account_icon
55+
async_mpt_ops, account_factory, async_created_account, account_icon
5656
):
57-
updated_data = account(name="")
57+
updated_data = account_factory(name="")
5858

5959
with pytest.raises(MPTAPIError, match=r"400 Bad Request"):
6060
await async_mpt_ops.accounts.accounts.update(
6161
async_created_account.id, updated_data, logo=account_icon
6262
)
6363

6464

65-
async def test_update_account_not_found(async_mpt_ops, account, invalid_account_id, account_icon):
66-
non_existent_account = account(name="Non Existent Account")
65+
async def test_update_account_not_found(
66+
async_mpt_ops, account_factory, invalid_account_id, account_icon
67+
):
68+
non_existent_account = account_factory(name="Non Existent Account")
6769

6870
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
6971
await async_mpt_ops.accounts.accounts.update(
7072
invalid_account_id, non_existent_account, logo=account_icon
7173
)
7274

7375

74-
async def test_account_enable(async_mpt_ops, account, async_created_account):
76+
async def test_account_enable(async_mpt_ops, account_factory, async_created_account):
7577
await async_mpt_ops.accounts.accounts.disable(async_created_account.id)
7678

7779
account = await async_mpt_ops.accounts.accounts.enable(async_created_account.id)

tests/e2e/accounts/account/test_sync_account.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88

99
@pytest.fixture
10-
def created_account(logger, mpt_ops, account, account_icon):
11-
account_data = account()
10+
def created_account(logger, mpt_ops, account_factory, account_icon):
11+
account_data = account_factory()
1212

1313
res_account = mpt_ops.accounts.accounts.create(account_data, logo=account_icon)
1414

@@ -41,8 +41,8 @@ def test_create_account(created_account):
4141
assert account is not None
4242

4343

44-
def test_update_account(mpt_ops, created_account, account, account_icon):
45-
updated_data = account(name="Updated Account Name")
44+
def test_update_account(mpt_ops, created_account, account_factory, account_icon):
45+
updated_data = account_factory(name="Updated Account Name")
4646

4747
updated_account = mpt_ops.accounts.accounts.update(
4848
created_account.id, updated_data, logo=account_icon
@@ -51,23 +51,23 @@ def test_update_account(mpt_ops, created_account, account, account_icon):
5151
assert updated_account is not None
5252

5353

54-
def test_update_account_invalid_data(mpt_ops, account, created_account, account_icon):
55-
updated_data = account(name="")
54+
def test_update_account_invalid_data(mpt_ops, account_factory, created_account, account_icon):
55+
updated_data = account_factory(name="")
5656

5757
with pytest.raises(MPTAPIError, match=r"400 Bad Request"):
5858
mpt_ops.accounts.accounts.update(created_account.id, updated_data, logo=account_icon)
5959

6060

61-
def test_update_account_not_found(mpt_ops, account, invalid_account_id, account_icon):
62-
non_existent_account = account(name="Non Existent Account")
61+
def test_update_account_not_found(mpt_ops, account_factory, invalid_account_id, account_icon):
62+
non_existent_account = account_factory(name="Non Existent Account")
6363

6464
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
6565
mpt_ops.accounts.accounts.update(
6666
invalid_account_id, non_existent_account, logo=account_icon
6767
)
6868

6969

70-
def test_account_enable(mpt_ops, account, created_account):
70+
def test_account_enable(mpt_ops, account_factory, created_account):
7171
mpt_ops.accounts.accounts.disable(created_account.id)
7272

7373
account = mpt_ops.accounts.accounts.enable(created_account.id)
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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_api_token(async_mpt_vendor, api_token_factory):
11+
new_api_token_request_data = api_token_factory()
12+
created_api_token = await async_mpt_vendor.accounts.api_tokens.create(
13+
new_api_token_request_data
14+
)
15+
16+
yield created_api_token
17+
18+
try:
19+
await async_mpt_vendor.accounts.api_tokens.delete(created_api_token.id)
20+
except MPTAPIError as error:
21+
print(f"TEARDOWN - Unable to delete api token: {error.title}") # noqa: WPS421
22+
23+
24+
async def test_get_api_token_by_id(async_mpt_vendor, api_token_id):
25+
api_token = await async_mpt_vendor.accounts.api_tokens.get(api_token_id)
26+
assert api_token is not None
27+
28+
29+
async def test_list_api_tokens(async_mpt_vendor):
30+
limit = 10
31+
api_tokens = await async_mpt_vendor.accounts.api_tokens.fetch_page(limit=limit)
32+
assert len(api_tokens) > 0
33+
34+
35+
async def test_get_api_token_by_id_not_found(async_mpt_vendor, invalid_api_token_id):
36+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
37+
await async_mpt_vendor.accounts.api_tokens.get(invalid_api_token_id)
38+
39+
40+
async def test_filter_api_tokens(async_mpt_vendor, api_token_id):
41+
select_fields = ["-description"]
42+
43+
filtered_api_tokens = (
44+
async_mpt_vendor.accounts.api_tokens.filter(RQLQuery(id=api_token_id))
45+
.filter(RQLQuery(name="E2E Seeded Token"))
46+
.select(*select_fields)
47+
)
48+
49+
api_tokens = [filtered_api_token async for filtered_api_token in filtered_api_tokens.iterate()]
50+
51+
assert len(api_tokens) == 1
52+
53+
54+
def test_create_api_token(created_api_token):
55+
new_api_token = created_api_token
56+
assert new_api_token is not None
57+
58+
59+
async def test_delete_api_token(async_mpt_vendor, created_api_token):
60+
await async_mpt_vendor.accounts.api_tokens.delete(created_api_token.id)
61+
62+
63+
async def test_delete_api_token_not_found(async_mpt_vendor, invalid_api_token_id):
64+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
65+
await async_mpt_vendor.accounts.api_tokens.delete(invalid_api_token_id)
66+
67+
68+
async def test_update_api_token(async_mpt_vendor, api_token_factory, created_api_token):
69+
updated_api_token_data = api_token_factory(name="E2E Updated API Token")
70+
71+
updated_api_token = await async_mpt_vendor.accounts.api_tokens.update(
72+
created_api_token.id, updated_api_token_data
73+
)
74+
75+
assert updated_api_token is not None
76+
77+
78+
async def test_update_api_token_not_found(
79+
async_mpt_vendor, api_token_factory, invalid_api_token_id
80+
):
81+
updated_api_token_data = api_token_factory(name="Nonexistent API Token")
82+
83+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
84+
await async_mpt_vendor.accounts.api_tokens.update(
85+
invalid_api_token_id, updated_api_token_data
86+
)
87+
88+
89+
async def test_api_token_disable(async_mpt_vendor, created_api_token):
90+
disabled_api_token = await async_mpt_vendor.accounts.api_tokens.disable(created_api_token.id)
91+
92+
assert disabled_api_token is not None
93+
94+
95+
async def test_api_token_disable_not_found(async_mpt_vendor, invalid_api_token_id):
96+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
97+
await async_mpt_vendor.accounts.api_tokens.disable(invalid_api_token_id)
98+
99+
100+
async def test_api_token_enable(async_mpt_vendor, created_api_token):
101+
await async_mpt_vendor.accounts.api_tokens.disable(created_api_token.id)
102+
103+
enabled_api_token = await async_mpt_vendor.accounts.api_tokens.enable(created_api_token.id)
104+
105+
assert enabled_api_token is not None
106+
107+
108+
async def test_api_token_enable_not_found(async_mpt_vendor, invalid_api_token_id):
109+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
110+
await async_mpt_vendor.accounts.api_tokens.enable(invalid_api_token_id)
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
def created_api_token(mpt_vendor, api_token_factory):
11+
new_api_token_request_data = api_token_factory()
12+
created_api_token = mpt_vendor.accounts.api_tokens.create(new_api_token_request_data)
13+
14+
yield created_api_token
15+
16+
try:
17+
mpt_vendor.accounts.api_tokens.delete(created_api_token.id)
18+
except MPTAPIError as error:
19+
print(f"TEARDOWN - Unable to delete api token: {error.title}") # noqa: WPS421
20+
21+
22+
def test_get_api_token_by_id(mpt_vendor, api_token_id):
23+
api_token = mpt_vendor.accounts.api_tokens.get(api_token_id)
24+
assert api_token is not None
25+
26+
27+
def test_list_api_tokens(mpt_vendor):
28+
limit = 10
29+
api_tokens = mpt_vendor.accounts.api_tokens.fetch_page(limit=limit)
30+
assert len(api_tokens) > 0
31+
32+
33+
def test_get_api_token_by_id_not_found(mpt_vendor, invalid_api_token_id):
34+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
35+
mpt_vendor.accounts.api_tokens.get(invalid_api_token_id)
36+
37+
38+
def test_filter_api_tokens(mpt_vendor, api_token_id):
39+
select_fields = ["-name"]
40+
41+
filtered_api_tokens = (
42+
mpt_vendor.accounts.api_tokens.filter(RQLQuery(id=api_token_id))
43+
.filter(RQLQuery(name="E2E Seeded Token"))
44+
.select(*select_fields)
45+
)
46+
47+
api_tokens = list(filtered_api_tokens.iterate())
48+
49+
assert len(api_tokens) == 1
50+
51+
52+
def test_create_api_token(created_api_token):
53+
new_api_token = created_api_token
54+
assert new_api_token is not None
55+
56+
57+
def test_delete_api_token(mpt_vendor, created_api_token):
58+
mpt_vendor.accounts.api_tokens.delete(created_api_token.id)
59+
60+
61+
def test_delete_api_token_not_found(mpt_vendor, invalid_api_token_id):
62+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
63+
mpt_vendor.accounts.api_tokens.delete(invalid_api_token_id)
64+
65+
66+
def test_update_api_token(mpt_vendor, api_token_factory, created_api_token):
67+
updated_api_token_data = api_token_factory(name="E2E Updated API Token")
68+
69+
updated_api_token = mpt_vendor.accounts.api_tokens.update(
70+
created_api_token.id, updated_api_token_data
71+
)
72+
73+
assert updated_api_token is not None
74+
75+
76+
def test_update_api_token_not_found(mpt_vendor, api_token_factory, invalid_api_token_id):
77+
updated_api_token_data = api_token_factory(name="Nonexistent API Token")
78+
79+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
80+
mpt_vendor.accounts.api_tokens.update(invalid_api_token_id, updated_api_token_data)
81+
82+
83+
def test_api_token_disable(mpt_vendor, created_api_token):
84+
disabled_api_token = mpt_vendor.accounts.api_tokens.disable(created_api_token.id)
85+
86+
assert disabled_api_token is not None
87+
88+
89+
def test_api_token_disable_not_found(mpt_vendor, invalid_api_token_id):
90+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
91+
mpt_vendor.accounts.api_tokens.disable(invalid_api_token_id)
92+
93+
94+
def test_api_token_enable(mpt_vendor, created_api_token):
95+
mpt_vendor.accounts.api_tokens.disable(created_api_token.id)
96+
97+
enabled_api_token = mpt_vendor.accounts.api_tokens.enable(created_api_token.id)
98+
99+
assert enabled_api_token is not None
100+
101+
102+
def test_api_token_enable_not_found(mpt_vendor, invalid_api_token_id):
103+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
104+
mpt_vendor.accounts.api_tokens.enable(invalid_api_token_id)

tests/e2e/accounts/buyers/test_async_buyers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88

99
@pytest.fixture
10-
async def async_created_buyer(async_mpt_ops, buyer, buyer_account_id, account_icon):
11-
new_buyer_request_data = buyer(
10+
async def async_created_buyer(async_mpt_ops, buyer_factory, buyer_account_id, account_icon):
11+
new_buyer_request_data = buyer_factory(
1212
name="E2E Created Buyer",
1313
account_id=buyer_account_id,
1414
)
@@ -69,9 +69,9 @@ async def test_delete_buyer_not_found(async_mpt_ops, invalid_buyer_id):
6969

7070

7171
async def test_update_buyer(
72-
async_mpt_ops, buyer, buyer_account_id, account_icon, async_created_buyer
72+
async_mpt_ops, buyer_factory, buyer_account_id, account_icon, async_created_buyer
7373
):
74-
updated_buyer_data = buyer(name="E2E Updated Buyer", account_id=buyer_account_id)
74+
updated_buyer_data = buyer_factory(name="E2E Updated Buyer", account_id=buyer_account_id)
7575

7676
updated_buyer = await async_mpt_ops.accounts.buyers.update(
7777
async_created_buyer.id, updated_buyer_data, logo=account_icon
@@ -81,9 +81,9 @@ async def test_update_buyer(
8181

8282

8383
async def test_update_buyer_not_found(
84-
async_mpt_ops, buyer, buyer_account_id, account_icon, invalid_buyer_id
84+
async_mpt_ops, buyer_factory, buyer_account_id, account_icon, invalid_buyer_id
8585
):
86-
updated_buyer_data = buyer(name="Nonexistent Buyer", account_id=buyer_account_id)
86+
updated_buyer_data = buyer_factory(name="Nonexistent Buyer", account_id=buyer_account_id)
8787

8888
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
8989
await async_mpt_ops.accounts.buyers.update(

0 commit comments

Comments
 (0)