From 31f281426a1cf49fbba4bfb12746aa2be4f89c85 Mon Sep 17 00:00:00 2001 From: Albert Sola Date: Thu, 2 Apr 2026 16:47:21 +0100 Subject: [PATCH 1/2] MPT-19910: add e2e tests for currency endpoints Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- e2e_config.test.json | 13 +++-- tests/e2e/exchange/__init__.py | 0 tests/e2e/exchange/currencies/__init__.py | 0 tests/e2e/exchange/currencies/conftest.py | 51 ++++++++++++++++++ .../currencies/test_async_currencies.py | 54 +++++++++++++++++++ .../currencies/test_sync_currencies.py | 48 +++++++++++++++++ 6 files changed, 161 insertions(+), 5 deletions(-) create mode 100644 tests/e2e/exchange/__init__.py create mode 100644 tests/e2e/exchange/currencies/__init__.py create mode 100644 tests/e2e/exchange/currencies/conftest.py create mode 100644 tests/e2e/exchange/currencies/test_async_currencies.py create mode 100644 tests/e2e/exchange/currencies/test_sync_currencies.py diff --git a/e2e_config.test.json b/e2e_config.test.json index f7661d9f..d947efc9 100644 --- a/e2e_config.test.json +++ b/e2e_config.test.json @@ -42,10 +42,10 @@ "commerce.agreement.subscription.line.id": "ALI-0078-7880-7436-0001", "commerce.assets.agreement.id": "AGR-2473-3299-1721", "commerce.assets.agreement.line.id": "ALI-9320-4904-7940-0001", - "commerce.assets.id": "AST-0625-6526-6154", - "commerce.assets.order.id": "ORD-7707-7765-8445", "commerce.assets.draft.order.agreement.id": "AGR-9320-4904-7940", "commerce.assets.draft.order.id": "ORD-9272-6817-2305", + "commerce.assets.id": "AST-0625-6526-6154", + "commerce.assets.order.id": "ORD-7707-7765-8445", "commerce.assets.product.item.id": "ITM-1767-7355-0002", "commerce.assets.product.template.id": "", "commerce.authorization.id": "AUT-0031-2873", @@ -55,13 +55,16 @@ "commerce.product.item.id": "ITM-1767-7355-0001", "commerce.product.listing.id": "LST-5489-0806", "commerce.product.template.id": "TPL-1767-7355-0002", - "commerce.user.id": "USR-4303-2348", "commerce.subscription.agreement.id": "AGR-2473-3299-1721", "commerce.subscription.id": "SUB-3678-1831-2188", "commerce.subscription.product.item.id": "ITM-1767-7355-0001", + "commerce.user.id": "USR-4303-2348", + "exchange.currency.id": "CUR-6831", + "helpdesk.channel.id": "CHL-5064-0262-3671", + "helpdesk.chat.id": "CHT-5064-0262-3671", "notifications.batch.attachment.id": "ATT-7183-1965-7758", "notifications.batch.id": "MST-3638-2460-4825", "notifications.category.id": "NTC-6157-0397", - "notifications.subscriber.id": "NTS-0829-7123-7123", - "notifications.message.id": "MSG-0000-6215-1019-0139" + "notifications.message.id": "MSG-0000-6215-1019-0139", + "notifications.subscriber.id": "NTS-0829-7123-7123" } diff --git a/tests/e2e/exchange/__init__.py b/tests/e2e/exchange/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/e2e/exchange/currencies/__init__.py b/tests/e2e/exchange/currencies/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/e2e/exchange/currencies/conftest.py b/tests/e2e/exchange/currencies/conftest.py new file mode 100644 index 00000000..2b6f9be1 --- /dev/null +++ b/tests/e2e/exchange/currencies/conftest.py @@ -0,0 +1,51 @@ +import pytest + +from mpt_api_client.exceptions import MPTAPIError + + +@pytest.fixture +def currencies_service(mpt_ops): + return mpt_ops.exchange.currencies + + +@pytest.fixture +def async_currencies_service(async_mpt_ops): + return async_mpt_ops.exchange.currencies + + +@pytest.fixture(scope="session") +def currency_id(e2e_config): + return e2e_config["exchange.currency.id"] + + +@pytest.fixture +def currency_data(): + return { + "name": "e2e - please delete", + "code": "E2E", + "precision": 2, + } + + +@pytest.fixture +def created_currency(currencies_service, currency_data, logo_fd): + currency = currencies_service.create(currency_data, file=logo_fd) + + yield currency + + try: + currencies_service.delete(currency.id) + except MPTAPIError as error: + print(f"TEARDOWN - Unable to delete currency {currency.id}: {error.title}") # noqa: WPS421 + + +@pytest.fixture +async def async_created_currency(async_currencies_service, currency_data, logo_fd): + currency = await async_currencies_service.create(currency_data, file=logo_fd) + + yield currency + + try: + await async_currencies_service.delete(currency.id) + except MPTAPIError as error: + print(f"TEARDOWN - Unable to delete currency {currency.id}: {error.title}") # noqa: WPS421 diff --git a/tests/e2e/exchange/currencies/test_async_currencies.py b/tests/e2e/exchange/currencies/test_async_currencies.py new file mode 100644 index 00000000..0a155687 --- /dev/null +++ b/tests/e2e/exchange/currencies/test_async_currencies.py @@ -0,0 +1,54 @@ +import pytest + +from mpt_api_client.exceptions import MPTAPIError +from mpt_api_client.models import FileModel +from tests.e2e.helper import assert_async_service_filter_with_iterate + +pytestmark = [pytest.mark.flaky] + + +def test_create_currency(async_created_currency, currency_data): + result = async_created_currency.code + + assert result == currency_data["code"] + + +async def test_get_currency(async_currencies_service, currency_id): + result = await async_currencies_service.get(currency_id) + + assert result.id == currency_id + + +async def test_get_currency_not_found(async_currencies_service): + bogus_id = "CUR-0000-0000" + + with pytest.raises(MPTAPIError, match=r"404 Not Found"): + await async_currencies_service.get(bogus_id) + + +async def test_update_currency( + async_currencies_service, async_created_currency, logo_fd, short_uuid +): + update_data = {"name": f"e2e - please delete {short_uuid}"} + + result = await async_currencies_service.update( + async_created_currency.id, update_data, file=logo_fd + ) + + assert result.name == update_data["name"] + + +async def test_delete_currency(async_currencies_service, async_created_currency): + await async_currencies_service.delete(async_created_currency.id) # act + + +async def test_filter_currencies(async_currencies_service, currency_id): + await assert_async_service_filter_with_iterate( + async_currencies_service, currency_id, None + ) # act + + +async def test_download_icon(async_currencies_service, async_created_currency): + result = await async_currencies_service.download_icon(async_created_currency.id) + + assert isinstance(result, FileModel) diff --git a/tests/e2e/exchange/currencies/test_sync_currencies.py b/tests/e2e/exchange/currencies/test_sync_currencies.py new file mode 100644 index 00000000..7e25578e --- /dev/null +++ b/tests/e2e/exchange/currencies/test_sync_currencies.py @@ -0,0 +1,48 @@ +import pytest + +from mpt_api_client.exceptions import MPTAPIError +from mpt_api_client.models import FileModel +from tests.e2e.helper import assert_service_filter_with_iterate + +pytestmark = [pytest.mark.flaky] + + +def test_create_currency(created_currency, currency_data): + result = created_currency.code + + assert result == currency_data["code"] + + +def test_get_currency(currencies_service, currency_id): + result = currencies_service.get(currency_id) + + assert result.id == currency_id + + +def test_get_currency_not_found(currencies_service): + bogus_id = "CUR-0000-0000" + + with pytest.raises(MPTAPIError, match=r"404 Not Found"): + currencies_service.get(bogus_id) + + +def test_update_currency(currencies_service, created_currency, logo_fd, short_uuid): + update_data = {"name": f"e2e - please delete {short_uuid}"} + + result = currencies_service.update(created_currency.id, update_data, file=logo_fd) + + assert result.name == update_data["name"] + + +def test_delete_currency(currencies_service, created_currency): + currencies_service.delete(created_currency.id) # act + + +def test_filter_currencies(currencies_service, currency_id): + assert_service_filter_with_iterate(currencies_service, currency_id, None) # act + + +def test_download_icon(currencies_service, created_currency): + result = currencies_service.download_icon(created_currency.id) + + assert isinstance(result, FileModel) From 6fdb67a182f39ea10b7a81f91971aadde93b51df Mon Sep 17 00:00:00 2001 From: Albert Sola Date: Thu, 2 Apr 2026 17:03:07 +0100 Subject: [PATCH 2/2] MPT-19910: add currency e2e tests - use delta format and valid code --- tests/e2e/exchange/currencies/conftest.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/e2e/exchange/currencies/conftest.py b/tests/e2e/exchange/currencies/conftest.py index 2b6f9be1..adb87541 100644 --- a/tests/e2e/exchange/currencies/conftest.py +++ b/tests/e2e/exchange/currencies/conftest.py @@ -1,3 +1,5 @@ +import string + import pytest from mpt_api_client.exceptions import MPTAPIError @@ -19,10 +21,12 @@ def currency_id(e2e_config): @pytest.fixture -def currency_data(): +def currency_data(short_uuid): + digit_to_alpha = str.maketrans(string.digits, "GHIJKLMNOP") + code = short_uuid[:3].translate(digit_to_alpha).upper() return { - "name": "e2e - please delete", - "code": "E2E", + "name": f"e2e - please delete {short_uuid}", + "code": code, "precision": 2, }