Skip to content

Commit 170e5c0

Browse files
authored
MPT-19910: add e2e tests for currency endpoints (#275)
2 parents 08be40f + 6fdb67a commit 170e5c0

File tree

6 files changed

+165
-5
lines changed

6 files changed

+165
-5
lines changed

e2e_config.test.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
"commerce.agreement.subscription.line.id": "ALI-0078-7880-7436-0001",
4343
"commerce.assets.agreement.id": "AGR-2473-3299-1721",
4444
"commerce.assets.agreement.line.id": "ALI-9320-4904-7940-0001",
45-
"commerce.assets.id": "AST-0625-6526-6154",
46-
"commerce.assets.order.id": "ORD-7707-7765-8445",
4745
"commerce.assets.draft.order.agreement.id": "AGR-9320-4904-7940",
4846
"commerce.assets.draft.order.id": "ORD-9272-6817-2305",
47+
"commerce.assets.id": "AST-0625-6526-6154",
48+
"commerce.assets.order.id": "ORD-7707-7765-8445",
4949
"commerce.assets.product.item.id": "ITM-1767-7355-0002",
5050
"commerce.assets.product.template.id": "",
5151
"commerce.authorization.id": "AUT-0031-2873",
@@ -55,13 +55,16 @@
5555
"commerce.product.item.id": "ITM-1767-7355-0001",
5656
"commerce.product.listing.id": "LST-5489-0806",
5757
"commerce.product.template.id": "TPL-1767-7355-0002",
58-
"commerce.user.id": "USR-4303-2348",
5958
"commerce.subscription.agreement.id": "AGR-2473-3299-1721",
6059
"commerce.subscription.id": "SUB-3678-1831-2188",
6160
"commerce.subscription.product.item.id": "ITM-1767-7355-0001",
61+
"commerce.user.id": "USR-4303-2348",
62+
"exchange.currency.id": "CUR-6831",
63+
"helpdesk.channel.id": "CHL-5064-0262-3671",
64+
"helpdesk.chat.id": "CHT-5064-0262-3671",
6265
"notifications.batch.attachment.id": "ATT-7183-1965-7758",
6366
"notifications.batch.id": "MST-3638-2460-4825",
6467
"notifications.category.id": "NTC-6157-0397",
65-
"notifications.subscriber.id": "NTS-0829-7123-7123",
66-
"notifications.message.id": "MSG-0000-6215-1019-0139"
68+
"notifications.message.id": "MSG-0000-6215-1019-0139",
69+
"notifications.subscriber.id": "NTS-0829-7123-7123"
6770
}

tests/e2e/exchange/__init__.py

Whitespace-only changes.

tests/e2e/exchange/currencies/__init__.py

Whitespace-only changes.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import string
2+
3+
import pytest
4+
5+
from mpt_api_client.exceptions import MPTAPIError
6+
7+
8+
@pytest.fixture
9+
def currencies_service(mpt_ops):
10+
return mpt_ops.exchange.currencies
11+
12+
13+
@pytest.fixture
14+
def async_currencies_service(async_mpt_ops):
15+
return async_mpt_ops.exchange.currencies
16+
17+
18+
@pytest.fixture(scope="session")
19+
def currency_id(e2e_config):
20+
return e2e_config["exchange.currency.id"]
21+
22+
23+
@pytest.fixture
24+
def currency_data(short_uuid):
25+
digit_to_alpha = str.maketrans(string.digits, "GHIJKLMNOP")
26+
code = short_uuid[:3].translate(digit_to_alpha).upper()
27+
return {
28+
"name": f"e2e - please delete {short_uuid}",
29+
"code": code,
30+
"precision": 2,
31+
}
32+
33+
34+
@pytest.fixture
35+
def created_currency(currencies_service, currency_data, logo_fd):
36+
currency = currencies_service.create(currency_data, file=logo_fd)
37+
38+
yield currency
39+
40+
try:
41+
currencies_service.delete(currency.id)
42+
except MPTAPIError as error:
43+
print(f"TEARDOWN - Unable to delete currency {currency.id}: {error.title}") # noqa: WPS421
44+
45+
46+
@pytest.fixture
47+
async def async_created_currency(async_currencies_service, currency_data, logo_fd):
48+
currency = await async_currencies_service.create(currency_data, file=logo_fd)
49+
50+
yield currency
51+
52+
try:
53+
await async_currencies_service.delete(currency.id)
54+
except MPTAPIError as error:
55+
print(f"TEARDOWN - Unable to delete currency {currency.id}: {error.title}") # noqa: WPS421
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
from mpt_api_client.models import FileModel
5+
from tests.e2e.helper import assert_async_service_filter_with_iterate
6+
7+
pytestmark = [pytest.mark.flaky]
8+
9+
10+
def test_create_currency(async_created_currency, currency_data):
11+
result = async_created_currency.code
12+
13+
assert result == currency_data["code"]
14+
15+
16+
async def test_get_currency(async_currencies_service, currency_id):
17+
result = await async_currencies_service.get(currency_id)
18+
19+
assert result.id == currency_id
20+
21+
22+
async def test_get_currency_not_found(async_currencies_service):
23+
bogus_id = "CUR-0000-0000"
24+
25+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
26+
await async_currencies_service.get(bogus_id)
27+
28+
29+
async def test_update_currency(
30+
async_currencies_service, async_created_currency, logo_fd, short_uuid
31+
):
32+
update_data = {"name": f"e2e - please delete {short_uuid}"}
33+
34+
result = await async_currencies_service.update(
35+
async_created_currency.id, update_data, file=logo_fd
36+
)
37+
38+
assert result.name == update_data["name"]
39+
40+
41+
async def test_delete_currency(async_currencies_service, async_created_currency):
42+
await async_currencies_service.delete(async_created_currency.id) # act
43+
44+
45+
async def test_filter_currencies(async_currencies_service, currency_id):
46+
await assert_async_service_filter_with_iterate(
47+
async_currencies_service, currency_id, None
48+
) # act
49+
50+
51+
async def test_download_icon(async_currencies_service, async_created_currency):
52+
result = await async_currencies_service.download_icon(async_created_currency.id)
53+
54+
assert isinstance(result, FileModel)
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.models import FileModel
5+
from tests.e2e.helper import assert_service_filter_with_iterate
6+
7+
pytestmark = [pytest.mark.flaky]
8+
9+
10+
def test_create_currency(created_currency, currency_data):
11+
result = created_currency.code
12+
13+
assert result == currency_data["code"]
14+
15+
16+
def test_get_currency(currencies_service, currency_id):
17+
result = currencies_service.get(currency_id)
18+
19+
assert result.id == currency_id
20+
21+
22+
def test_get_currency_not_found(currencies_service):
23+
bogus_id = "CUR-0000-0000"
24+
25+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
26+
currencies_service.get(bogus_id)
27+
28+
29+
def test_update_currency(currencies_service, created_currency, logo_fd, short_uuid):
30+
update_data = {"name": f"e2e - please delete {short_uuid}"}
31+
32+
result = currencies_service.update(created_currency.id, update_data, file=logo_fd)
33+
34+
assert result.name == update_data["name"]
35+
36+
37+
def test_delete_currency(currencies_service, created_currency):
38+
currencies_service.delete(created_currency.id) # act
39+
40+
41+
def test_filter_currencies(currencies_service, currency_id):
42+
assert_service_filter_with_iterate(currencies_service, currency_id, None) # act
43+
44+
45+
def test_download_icon(currencies_service, created_currency):
46+
result = currencies_service.download_icon(created_currency.id)
47+
48+
assert isinstance(result, FileModel)

0 commit comments

Comments
 (0)