Skip to content

Commit 4e3afe1

Browse files
committed
feat(tests): add sync and async E2E tests for notification categories
1 parent 9976f92 commit 4e3afe1

5 files changed

Lines changed: 211 additions & 0 deletions

File tree

tests/e2e/notifications/__init__.py

Whitespace-only changes.

tests/e2e/notifications/categories/__init__.py

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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_vendor, category_data):
11+
service = async_mpt_vendor.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+
async def test_create_category(async_created_category, category_data):
21+
assert async_created_category.name == category_data["name"]
22+
assert async_created_category.description == category_data["description"]
23+
24+
25+
async def test_get_category(async_mpt_vendor, async_created_category):
26+
service = async_mpt_vendor.notifications.categories
27+
28+
result = await service.get(async_created_category.id)
29+
30+
assert result.id == async_created_category.id
31+
assert result.name == async_created_category.name
32+
33+
34+
async def test_update_category(async_mpt_vendor, async_created_category):
35+
service = async_mpt_vendor.notifications.categories
36+
update_data = {
37+
"name": "e2e-async-updated-category",
38+
"description": "Async updated description",
39+
}
40+
41+
result = await service.update(async_created_category.id, update_data)
42+
43+
assert result.name == "e2e-async-updated-category"
44+
assert result.description == "Async updated description"
45+
46+
47+
async def test_list_categories(async_mpt_vendor, async_created_category):
48+
service = async_mpt_vendor.notifications.categories
49+
50+
result = [category async for category in service.iterate()]
51+
52+
assert any(category.id == async_created_category.id for category in result)
53+
54+
55+
async def test_filter_categories(async_mpt_vendor, async_created_category):
56+
service = async_mpt_vendor.notifications.categories
57+
58+
result = [
59+
category
60+
async for category in service.filter(RQLQuery(id=async_created_category.id)).iterate()
61+
]
62+
63+
assert len(result) == 1
64+
assert result[0].id == async_created_category.id
65+
66+
67+
async def test_publish_category(async_mpt_vendor, async_created_category):
68+
service = async_mpt_vendor.notifications.categories
69+
note_data = {"note": "Publishing category for async testing"}
70+
71+
result = await service.publish(async_created_category.id, note_data)
72+
73+
assert result.id == async_created_category.id
74+
75+
76+
async def test_unpublish_category(async_mpt_vendor, async_created_category):
77+
service = async_mpt_vendor.notifications.categories
78+
# First publish
79+
publish_note_data = {"note": "Publishing category"}
80+
await service.publish(async_created_category.id, publish_note_data)
81+
82+
# Then unpublish
83+
unpublish_note_data = {"note": "Unpublishing category for async testing"}
84+
result = await service.unpublish(async_created_category.id, unpublish_note_data)
85+
86+
assert result.id == async_created_category.id
87+
88+
89+
async def test_category_not_found(async_mpt_vendor):
90+
service = async_mpt_vendor.notifications.categories
91+
92+
with pytest.raises(MPTAPIError):
93+
await service.get("NCT-000-000-000")
94+
95+
96+
async def test_delete_category(async_mpt_vendor, async_created_category):
97+
service = async_mpt_vendor.notifications.categories
98+
99+
await service.delete(async_created_category.id)
100+
101+
with pytest.raises(MPTAPIError):
102+
await service.get(async_created_category.id)
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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_vendor, category_data):
11+
service = mpt_vendor.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+
def test_create_category(created_category, category_data):
21+
assert created_category.name == category_data["name"]
22+
assert created_category.description == category_data["description"]
23+
24+
25+
def test_get_category(mpt_vendor, created_category):
26+
service = mpt_vendor.notifications.categories
27+
28+
result = service.get(created_category.id)
29+
30+
assert result.id == created_category.id
31+
assert result.name == created_category.name
32+
33+
34+
def test_update_category(mpt_vendor, created_category):
35+
service = mpt_vendor.notifications.categories
36+
update_data = {
37+
"name": "e2e-updated-category",
38+
"description": "Updated description",
39+
}
40+
41+
result = service.update(created_category.id, update_data)
42+
43+
assert result.name == "e2e-updated-category"
44+
assert result.description == "Updated description"
45+
46+
47+
def test_list_categories(mpt_vendor, created_category):
48+
service = mpt_vendor.notifications.categories
49+
50+
result = list(service.iterate())
51+
52+
assert any(category.id == created_category.id for category in result)
53+
54+
55+
def test_filter_categories(mpt_vendor, created_category):
56+
service = mpt_vendor.notifications.categories
57+
58+
result = list(service.filter(RQLQuery(id=created_category.id)).iterate())
59+
60+
assert len(result) == 1
61+
assert result[0].id == created_category.id
62+
63+
64+
def test_publish_category(mpt_vendor, created_category):
65+
service = mpt_vendor.notifications.categories
66+
note_data = {"note": "Publishing category for testing"}
67+
68+
result = service.publish(created_category.id, note_data)
69+
70+
assert result.id == created_category.id
71+
72+
73+
def test_unpublish_category(mpt_vendor, created_category):
74+
service = mpt_vendor.notifications.categories
75+
# First publish
76+
publish_note_data = {"note": "Publishing category"}
77+
service.publish(created_category.id, publish_note_data)
78+
79+
# Then unpublish
80+
unpublish_note_data = {"note": "Unpublishing category for testing"}
81+
result = service.unpublish(created_category.id, unpublish_note_data)
82+
83+
assert result.id == created_category.id
84+
85+
86+
def test_category_not_found(mpt_vendor):
87+
service = mpt_vendor.notifications.categories
88+
89+
with pytest.raises(MPTAPIError):
90+
service.get("NCT-000-000-000")
91+
92+
93+
def test_delete_category(mpt_vendor, created_category):
94+
service = mpt_vendor.notifications.categories
95+
96+
service.delete(created_category.id)
97+
98+
with pytest.raises(MPTAPIError):
99+
service.get(created_category.id)

0 commit comments

Comments
 (0)