Skip to content

Commit a3b32fc

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

File tree

5 files changed

+226
-0
lines changed

5 files changed

+226
-0
lines changed

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: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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+
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_ops, async_created_category):
35+
service = async_mpt_ops.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_ops, async_created_category):
68+
service = async_mpt_ops.notifications.categories
69+
70+
unpublish_note_data = {"note": "Unpublishing category for async testing"}
71+
await service.unpublish(async_created_category.id, unpublish_note_data)
72+
73+
note_data = {"note": "Publishing category for async testing"}
74+
result = await service.publish(async_created_category.id, note_data)
75+
76+
assert result.id == async_created_category.id
77+
78+
79+
async def test_unpublish_category(async_mpt_ops, async_created_category):
80+
service = async_mpt_ops.notifications.categories
81+
82+
unpublish_note_data = {"note": "Unpublishing category for async testing"}
83+
result = await service.unpublish(async_created_category.id, unpublish_note_data)
84+
85+
assert result.id == async_created_category.id
86+
87+
88+
async def test_category_not_found(async_mpt_vendor):
89+
service = async_mpt_vendor.notifications.categories
90+
91+
with pytest.raises(MPTAPIError):
92+
await service.get("NCT-000-000-000")
93+
94+
95+
async def test_delete_category(async_mpt_ops, async_created_category):
96+
service = async_mpt_ops.notifications.categories
97+
98+
await service.delete(async_created_category.id)
99+
100+
await service.get(async_created_category.id)
101+
102+
103+
async def test_delete_category_not_found(async_mpt_ops, invalid_category_id):
104+
service = async_mpt_ops.notifications.categories
105+
106+
with pytest.raises(MPTAPIError):
107+
await service.delete(invalid_category_id)
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
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_client, created_category):
26+
service = mpt_client.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_ops, created_category):
35+
service = mpt_ops.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_client, created_category):
48+
service = mpt_client.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_client, created_category):
56+
service = mpt_client.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_ops, created_category):
65+
service = mpt_ops.notifications.categories
66+
67+
unpublish_note_data = {"note": "Unpublishing category for testing"}
68+
service.unpublish(created_category.id, unpublish_note_data)
69+
70+
note_data = {"note": "Publishing category for testing"}
71+
result = service.publish(created_category.id, note_data)
72+
73+
assert result.id == created_category.id
74+
75+
76+
def test_unpublish_category(mpt_ops, created_category):
77+
service = mpt_ops.notifications.categories
78+
79+
unpublish_note_data = {"note": "Unpublishing category for testing"}
80+
result = service.unpublish(created_category.id, unpublish_note_data)
81+
82+
assert result.id == created_category.id
83+
84+
85+
def test_category_not_found(mpt_client, invalid_category_id):
86+
service = mpt_client.notifications.categories
87+
88+
with pytest.raises(MPTAPIError):
89+
service.get(invalid_category_id)
90+
91+
92+
def test_delete_category(mpt_ops, created_category):
93+
service = mpt_ops.notifications.categories
94+
95+
service.delete(created_category.id)
96+
97+
service.get(created_category.id)
98+
99+
100+
def test_delete_category_not_found(mpt_ops, invalid_category_id):
101+
service = mpt_ops.notifications.categories
102+
103+
with pytest.raises(MPTAPIError):
104+
service.delete(invalid_category_id)

0 commit comments

Comments
 (0)