From 4397619132a717a6820df84804c7be7cd1686136 Mon Sep 17 00:00:00 2001 From: Albert Sola Date: Thu, 4 Dec 2025 11:25:26 +0000 Subject: [PATCH] MPT-14895 E2E for catalog/authorizations --- tests/e2e/accounts/buyers/conftest.py | 5 -- tests/e2e/catalog/authorizations/conftest.py | 21 +++++++ .../test_async_authorizations.py | 55 +++++++++++++++++++ .../authorizations/test_authorizations.py | 48 ++++++++++++++++ .../e2e/catalog/pricing_policies/conftest.py | 9 +-- tests/e2e/conftest.py | 5 ++ 6 files changed, 131 insertions(+), 12 deletions(-) create mode 100644 tests/e2e/catalog/authorizations/conftest.py create mode 100644 tests/e2e/catalog/authorizations/test_async_authorizations.py create mode 100644 tests/e2e/catalog/authorizations/test_authorizations.py diff --git a/tests/e2e/accounts/buyers/conftest.py b/tests/e2e/accounts/buyers/conftest.py index ca75be6e..06c753d1 100644 --- a/tests/e2e/accounts/buyers/conftest.py +++ b/tests/e2e/accounts/buyers/conftest.py @@ -6,11 +6,6 @@ def invalid_buyer_id(): return "BUY-0000-0000" -@pytest.fixture -def buyer_account_id(e2e_config): - return e2e_config["accounts.buyer.account.id"] - - @pytest.fixture def buyer_factory(buyer_account_id): def _buyer( diff --git a/tests/e2e/catalog/authorizations/conftest.py b/tests/e2e/catalog/authorizations/conftest.py new file mode 100644 index 00000000..2e1f0417 --- /dev/null +++ b/tests/e2e/catalog/authorizations/conftest.py @@ -0,0 +1,21 @@ +import pytest + + +@pytest.fixture +def authorizations_service(mpt_ops): + return mpt_ops.catalog.authorizations + + +@pytest.fixture +def authorization_data(product_id, seller_id, account_id, short_uuid): + return { + "externalIds": {"operations": f"e2e-{short_uuid}"}, + "product": {"id": product_id}, + "owner": {"id": seller_id}, + "journal": {"firstInvoiceDate": "2025-12-01", "frequency": "1m"}, + "eligibility": {"client": True, "partner": True}, + "currency": "USD", + "notes": "e2e - please delete", + "name": "e2e - please delete", + "vendor": {"id": account_id}, + } diff --git a/tests/e2e/catalog/authorizations/test_async_authorizations.py b/tests/e2e/catalog/authorizations/test_async_authorizations.py new file mode 100644 index 00000000..83eb7012 --- /dev/null +++ b/tests/e2e/catalog/authorizations/test_async_authorizations.py @@ -0,0 +1,55 @@ +import pytest + +from mpt_api_client.exceptions import MPTAPIError +from mpt_api_client.rql.query_builder import RQLQuery +from tests.e2e.helper import assert_async_update_resource, async_create_fixture_resource_and_delete + +pytestmark = [pytest.mark.flaky] + + +@pytest.fixture +def async_authorizations_service(async_mpt_ops): + return async_mpt_ops.catalog.authorizations + + +@pytest.fixture +async def created_authorization(async_authorizations_service, authorization_data): + async with async_create_fixture_resource_and_delete( + async_authorizations_service, authorization_data + ) as authorization: + yield authorization + + +def test_create_authorization(created_authorization, authorization_data): # noqa: AAA01 + assert created_authorization.name == authorization_data["name"] + + +async def test_get_authorization(async_authorizations_service, authorization_id): + result = await async_authorizations_service.get(authorization_id) + + assert result.id == authorization_id + + +async def test_filter_authorizations(async_authorizations_service, authorization_id): + select_fields = ["-description"] + filtered = async_authorizations_service.filter(RQLQuery(id=authorization_id)).select( + *select_fields + ) + + result = [auth async for auth in filtered.iterate()] + + assert len(result) == 1 + assert result[0].id == authorization_id + + +async def test_get_authorization_not_found(async_authorizations_service): + bogus_id = "AUT-0000-0000" + + with pytest.raises(MPTAPIError, match=r"404 Not Found"): + await async_authorizations_service.get(bogus_id) + + +async def test_update_authorization(async_authorizations_service, authorization_id, short_uuid): + await assert_async_update_resource( + async_authorizations_service, authorization_id, "notes", f"e2e test - {short_uuid}" + ) diff --git a/tests/e2e/catalog/authorizations/test_authorizations.py b/tests/e2e/catalog/authorizations/test_authorizations.py new file mode 100644 index 00000000..d8631be2 --- /dev/null +++ b/tests/e2e/catalog/authorizations/test_authorizations.py @@ -0,0 +1,48 @@ +import pytest + +from mpt_api_client.exceptions import MPTAPIError +from mpt_api_client.rql.query_builder import RQLQuery +from tests.e2e.helper import assert_update_resource, create_fixture_resource_and_delete + +pytestmark = [pytest.mark.flaky] + + +@pytest.fixture +def created_authorization(authorizations_service, authorization_data): + with create_fixture_resource_and_delete( + authorizations_service, authorization_data + ) as authorization: + yield authorization + + +def test_get_authorization(authorizations_service, authorization_id): + result = authorizations_service.get(authorization_id) + + assert result.id == authorization_id + + +def test_create_authorization(created_authorization, authorization_data): # noqa: AAA01 + assert created_authorization.name == authorization_data["name"] + + +def test_filter_authorizations(authorizations_service, authorization_id): + select_fields = ["-description"] + filtered = authorizations_service.filter(RQLQuery(id=authorization_id)).select(*select_fields) + + result = list(filtered.iterate()) + + assert len(result) == 1 + assert result[0].id == authorization_id + + +def test_get_authorization_not_found(authorizations_service): + bogus_id = "AUT-0000-0000" + + with pytest.raises(MPTAPIError, match=r"404 Not Found"): + authorizations_service.get(bogus_id) + + +def test_update_authorization(authorizations_service, authorization_id, short_uuid): + assert_update_resource( + authorizations_service, authorization_id, "notes", f"e2e test - {short_uuid}" + ) # act diff --git a/tests/e2e/catalog/pricing_policies/conftest.py b/tests/e2e/catalog/pricing_policies/conftest.py index 79f069a2..546f35ab 100644 --- a/tests/e2e/catalog/pricing_policies/conftest.py +++ b/tests/e2e/catalog/pricing_policies/conftest.py @@ -4,16 +4,11 @@ @pytest.fixture -def buyer_id(e2e_config): - return e2e_config["accounts.buyer.account.id"] - - -@pytest.fixture -def pricing_policy_data(buyer_id, product_id): +def pricing_policy_data(buyer_account_id, product_id): return { "name": "e2e - pricing policy please delete", "description": "Test pricing policy description", - "client": {"id": buyer_id}, + "client": {"id": buyer_account_id}, "product": {"id": product_id}, "eligibility": {"client": True, "partner": False}, "margin": "0.20", diff --git a/tests/e2e/conftest.py b/tests/e2e/conftest.py index 754125a0..86b6efed 100644 --- a/tests/e2e/conftest.py +++ b/tests/e2e/conftest.py @@ -133,6 +133,11 @@ def buyer_id(e2e_config): return e2e_config["accounts.buyer.id"] +@pytest.fixture +def buyer_account_id(e2e_config): + return e2e_config["accounts.buyer.account.id"] + + @pytest.fixture def licensee_id(e2e_config): return e2e_config["accounts.licensee.id"]