Skip to content

Commit 1003ee5

Browse files
authored
Merge pull request #137
MPT-14932 add sync and async E2E tests for notification categories
2 parents 557ae6f + 6769a91 commit 1003ee5

5 files changed

Lines changed: 243 additions & 0 deletions

File tree

tests/e2e/notifications/__init__.py

Whitespace-only changes.

tests/e2e/notifications/categories/__init__.py

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
3+
4+
@pytest.fixture
5+
def category_data(short_uuid):
6+
return {
7+
"name": f"e2e-category-{short_uuid}",
8+
"description": "E2E test category - please delete",
9+
"externalId": f"e2e-cat-{short_uuid}",
10+
}
11+
12+
13+
@pytest.fixture
14+
def invalid_category_id():
15+
return "NCT-000-000-000"
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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 async_created_category(async_mpt_ops, category_data):
11+
service = async_mpt_ops.notifications.categories
12+
category = await service.create(category_data)
13+
yield category
14+
try:
15+
await service.delete(category.id)
16+
except MPTAPIError as error:
17+
print(f"TEARDOWN - Unable to delete category {category.id}: {error.title}") # noqa: WPS421
18+
19+
20+
@pytest.mark.skip(reason="async_created_category kills performance due to MPT-13785") # noqa: AAA01
21+
def test_create_category(async_created_category, category_data):
22+
assert async_created_category.name == category_data["name"]
23+
assert async_created_category.description == category_data["description"]
24+
25+
26+
@pytest.mark.skip(reason="async_created_category kills performance due to MPT-13785")
27+
async def test_get_category(async_mpt_vendor, async_created_category):
28+
service = async_mpt_vendor.notifications.categories
29+
30+
result = await service.get(async_created_category.id)
31+
32+
assert result.id == async_created_category.id
33+
assert result.name == async_created_category.name
34+
35+
36+
@pytest.mark.skip(reason="async_created_category kills performance due to MPT-13785")
37+
async def test_update_category(async_mpt_ops, async_created_category):
38+
service = async_mpt_ops.notifications.categories
39+
update_data = {
40+
"name": "e2e-async-updated-category",
41+
"description": "Async updated description",
42+
}
43+
44+
result = await service.update(async_created_category.id, update_data)
45+
46+
assert result.name == "e2e-async-updated-category"
47+
assert result.description == "Async updated description"
48+
49+
50+
@pytest.mark.skip(reason="async_created_category kills performance due to MPT-13785")
51+
async def test_list_categories(async_mpt_vendor, async_created_category):
52+
service = async_mpt_vendor.notifications.categories
53+
54+
result = [category async for category in service.iterate()]
55+
56+
assert any(category.id == async_created_category.id for category in result)
57+
58+
59+
@pytest.mark.skip(reason="async_created_category kills performance due to MPT-13785")
60+
async def test_filter_categories(async_mpt_vendor, async_created_category):
61+
service = async_mpt_vendor.notifications.categories
62+
63+
result = [
64+
category
65+
async for category in service.filter(RQLQuery(id=async_created_category.id)).iterate()
66+
]
67+
68+
assert len(result) == 1
69+
assert result[0].id == async_created_category.id
70+
71+
72+
@pytest.mark.skip(reason="async_created_category kills performance due to MPT-13785")
73+
async def test_publish_category(async_mpt_ops, async_created_category):
74+
service = async_mpt_ops.notifications.categories
75+
unpublish_note_data = {"note": "Unpublishing category for async testing"}
76+
await service.unpublish(async_created_category.id, unpublish_note_data)
77+
note_data = {"note": "Publishing category for async testing"}
78+
79+
result = await service.publish(async_created_category.id, note_data)
80+
81+
assert result.id == async_created_category.id
82+
83+
84+
@pytest.mark.skip(reason="async_created_category kills performance due to MPT-13785")
85+
async def test_unpublish_category(async_mpt_ops, async_created_category):
86+
service = async_mpt_ops.notifications.categories
87+
unpublish_note_data = {"note": "Unpublishing category for async testing"}
88+
89+
result = await service.unpublish(async_created_category.id, unpublish_note_data)
90+
91+
assert result.id == async_created_category.id
92+
93+
94+
async def test_category_not_found(async_mpt_vendor, invalid_category_id):
95+
service = async_mpt_vendor.notifications.categories
96+
97+
with pytest.raises(MPTAPIError):
98+
await service.get(invalid_category_id)
99+
100+
101+
@pytest.mark.skip(reason="async_created_category kills performance due to MPT-13785")
102+
async def test_delete_category(async_mpt_ops, async_created_category):
103+
service = async_mpt_ops.notifications.categories
104+
105+
await service.delete(async_created_category.id)
106+
107+
with pytest.raises(MPTAPIError):
108+
await service.get(async_created_category.id)
109+
110+
111+
async def test_delete_category_not_found(async_mpt_ops, invalid_category_id):
112+
service = async_mpt_ops.notifications.categories
113+
114+
with pytest.raises(MPTAPIError):
115+
await service.delete(invalid_category_id)
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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_category(mpt_ops, category_data):
11+
service = mpt_ops.notifications.categories
12+
category = service.create(category_data)
13+
yield category
14+
try:
15+
service.delete(category.id)
16+
except MPTAPIError as error:
17+
print(f"TEARDOWN - Unable to delete category {category.id}: {error.title}") # noqa: WPS421
18+
19+
20+
@pytest.mark.skip(reason="created_category kills performance due to MPT-13785")
21+
def test_create_category(created_category, category_data):
22+
assert created_category.name == category_data["name"] # act
23+
24+
assert created_category.description == category_data["description"]
25+
26+
27+
@pytest.mark.skip(reason="created_category kills performance due to MPT-13785")
28+
def test_get_category(mpt_client, created_category):
29+
service = mpt_client.notifications.categories
30+
31+
result = service.get(created_category.id)
32+
33+
assert result.id == created_category.id
34+
assert result.name == created_category.name
35+
36+
37+
@pytest.mark.skip(reason="created_category kills performance due to MPT-13785")
38+
def test_update_category(mpt_ops, created_category):
39+
service = mpt_ops.notifications.categories
40+
update_data = {
41+
"name": "e2e-updated-category",
42+
"description": "Updated description",
43+
}
44+
45+
result = service.update(created_category.id, update_data)
46+
47+
assert result.name == "e2e-updated-category"
48+
assert result.description == "Updated description"
49+
50+
51+
@pytest.mark.skip(reason="created_category kills performance due to MPT-13785")
52+
def test_list_categories(mpt_client, created_category):
53+
service = mpt_client.notifications.categories
54+
55+
result = list(service.iterate())
56+
57+
assert any(category.id == created_category.id for category in result)
58+
59+
60+
@pytest.mark.skip(reason="created_category kills performance due to MPT-13785")
61+
def test_filter_categories(mpt_client, created_category):
62+
service = mpt_client.notifications.categories
63+
64+
result = list(service.filter(RQLQuery(id=created_category.id)).iterate())
65+
66+
assert len(result) == 1
67+
assert result[0].id == created_category.id
68+
69+
70+
@pytest.mark.skip(reason="created_category kills performance due to MPT-13785")
71+
def test_publish_category(mpt_ops, created_category):
72+
service = mpt_ops.notifications.categories
73+
unpublish_note_data = {"note": "Unpublishing category for testing"}
74+
service.unpublish(created_category.id, unpublish_note_data)
75+
note_data = {"note": "Publishing category for testing"}
76+
77+
result = service.publish(created_category.id, note_data)
78+
79+
assert result.id == created_category.id
80+
81+
82+
@pytest.mark.skip(reason="created_category kills performance due to MPT-13785")
83+
def test_unpublish_category(mpt_ops, created_category):
84+
service = mpt_ops.notifications.categories
85+
unpublish_note_data = {"note": "Unpublishing category for testing"}
86+
87+
result = service.unpublish(created_category.id, unpublish_note_data)
88+
89+
assert result.id == created_category.id
90+
91+
92+
def test_category_not_found(mpt_client, invalid_category_id):
93+
service = mpt_client.notifications.categories
94+
95+
with pytest.raises(MPTAPIError):
96+
service.get(invalid_category_id)
97+
98+
99+
@pytest.mark.skip(reason="created_category kills performance due to MPT-13785")
100+
def test_delete_category(mpt_ops, created_category):
101+
service = mpt_ops.notifications.categories
102+
103+
service.delete(created_category.id) # act
104+
105+
with pytest.raises(MPTAPIError):
106+
service.get(created_category.id)
107+
108+
109+
def test_delete_category_not_found(mpt_ops, invalid_category_id):
110+
service = mpt_ops.notifications.categories
111+
112+
with pytest.raises(MPTAPIError):
113+
service.delete(invalid_category_id)

0 commit comments

Comments
 (0)