Skip to content

Commit ff6b291

Browse files
authored
MPT-14895 E2E for catalog/authorizations (#147)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Added comprehensive end-to-end tests for authorization workflows (create, retrieve, filter, update, error handling), including asynchronous variants. * Reorganized and expanded test fixtures to centralize account-id handling and support new authorization tests. * Removed and renamed some existing fixtures as part of the reorganization, which may require updating dependent tests. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 0637ffc + 4397619 commit ff6b291

File tree

6 files changed

+131
-12
lines changed

6 files changed

+131
-12
lines changed

tests/e2e/accounts/buyers/conftest.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ def invalid_buyer_id():
66
return "BUY-0000-0000"
77

88

9-
@pytest.fixture
10-
def buyer_account_id(e2e_config):
11-
return e2e_config["accounts.buyer.account.id"]
12-
13-
149
@pytest.fixture
1510
def buyer_factory(buyer_account_id):
1611
def _buyer(
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pytest
2+
3+
4+
@pytest.fixture
5+
def authorizations_service(mpt_ops):
6+
return mpt_ops.catalog.authorizations
7+
8+
9+
@pytest.fixture
10+
def authorization_data(product_id, seller_id, account_id, short_uuid):
11+
return {
12+
"externalIds": {"operations": f"e2e-{short_uuid}"},
13+
"product": {"id": product_id},
14+
"owner": {"id": seller_id},
15+
"journal": {"firstInvoiceDate": "2025-12-01", "frequency": "1m"},
16+
"eligibility": {"client": True, "partner": True},
17+
"currency": "USD",
18+
"notes": "e2e - please delete",
19+
"name": "e2e - please delete",
20+
"vendor": {"id": account_id},
21+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
from mpt_api_client.rql.query_builder import RQLQuery
5+
from tests.e2e.helper import assert_async_update_resource, async_create_fixture_resource_and_delete
6+
7+
pytestmark = [pytest.mark.flaky]
8+
9+
10+
@pytest.fixture
11+
def async_authorizations_service(async_mpt_ops):
12+
return async_mpt_ops.catalog.authorizations
13+
14+
15+
@pytest.fixture
16+
async def created_authorization(async_authorizations_service, authorization_data):
17+
async with async_create_fixture_resource_and_delete(
18+
async_authorizations_service, authorization_data
19+
) as authorization:
20+
yield authorization
21+
22+
23+
def test_create_authorization(created_authorization, authorization_data): # noqa: AAA01
24+
assert created_authorization.name == authorization_data["name"]
25+
26+
27+
async def test_get_authorization(async_authorizations_service, authorization_id):
28+
result = await async_authorizations_service.get(authorization_id)
29+
30+
assert result.id == authorization_id
31+
32+
33+
async def test_filter_authorizations(async_authorizations_service, authorization_id):
34+
select_fields = ["-description"]
35+
filtered = async_authorizations_service.filter(RQLQuery(id=authorization_id)).select(
36+
*select_fields
37+
)
38+
39+
result = [auth async for auth in filtered.iterate()]
40+
41+
assert len(result) == 1
42+
assert result[0].id == authorization_id
43+
44+
45+
async def test_get_authorization_not_found(async_authorizations_service):
46+
bogus_id = "AUT-0000-0000"
47+
48+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
49+
await async_authorizations_service.get(bogus_id)
50+
51+
52+
async def test_update_authorization(async_authorizations_service, authorization_id, short_uuid):
53+
await assert_async_update_resource(
54+
async_authorizations_service, authorization_id, "notes", f"e2e test - {short_uuid}"
55+
)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
from mpt_api_client.rql.query_builder import RQLQuery
5+
from tests.e2e.helper import assert_update_resource, create_fixture_resource_and_delete
6+
7+
pytestmark = [pytest.mark.flaky]
8+
9+
10+
@pytest.fixture
11+
def created_authorization(authorizations_service, authorization_data):
12+
with create_fixture_resource_and_delete(
13+
authorizations_service, authorization_data
14+
) as authorization:
15+
yield authorization
16+
17+
18+
def test_get_authorization(authorizations_service, authorization_id):
19+
result = authorizations_service.get(authorization_id)
20+
21+
assert result.id == authorization_id
22+
23+
24+
def test_create_authorization(created_authorization, authorization_data): # noqa: AAA01
25+
assert created_authorization.name == authorization_data["name"]
26+
27+
28+
def test_filter_authorizations(authorizations_service, authorization_id):
29+
select_fields = ["-description"]
30+
filtered = authorizations_service.filter(RQLQuery(id=authorization_id)).select(*select_fields)
31+
32+
result = list(filtered.iterate())
33+
34+
assert len(result) == 1
35+
assert result[0].id == authorization_id
36+
37+
38+
def test_get_authorization_not_found(authorizations_service):
39+
bogus_id = "AUT-0000-0000"
40+
41+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
42+
authorizations_service.get(bogus_id)
43+
44+
45+
def test_update_authorization(authorizations_service, authorization_id, short_uuid):
46+
assert_update_resource(
47+
authorizations_service, authorization_id, "notes", f"e2e test - {short_uuid}"
48+
) # act

tests/e2e/catalog/pricing_policies/conftest.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@
44

55

66
@pytest.fixture
7-
def buyer_id(e2e_config):
8-
return e2e_config["accounts.buyer.account.id"]
9-
10-
11-
@pytest.fixture
12-
def pricing_policy_data(buyer_id, product_id):
7+
def pricing_policy_data(buyer_account_id, product_id):
138
return {
149
"name": "e2e - pricing policy please delete",
1510
"description": "Test pricing policy description",
16-
"client": {"id": buyer_id},
11+
"client": {"id": buyer_account_id},
1712
"product": {"id": product_id},
1813
"eligibility": {"client": True, "partner": False},
1914
"margin": "0.20",

tests/e2e/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ def buyer_id(e2e_config):
133133
return e2e_config["accounts.buyer.id"]
134134

135135

136+
@pytest.fixture
137+
def buyer_account_id(e2e_config):
138+
return e2e_config["accounts.buyer.account.id"]
139+
140+
136141
@pytest.fixture
137142
def licensee_id(e2e_config):
138143
return e2e_config["accounts.licensee.id"]

0 commit comments

Comments
 (0)