Skip to content

Commit 78d5e8f

Browse files
authored
MPT-14939 E2E for audit event_types (#175)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Added comprehensive end-to-end tests (sync and async) for event type operations: retrieval, filtering, updates, and 404 error handling. * Added supporting fixtures to supply synchronous and asynchronous test services and sample event type data for the new e2e tests. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 5306629 + 3044703 commit 78d5e8f

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from typing import Any
2+
3+
import pytest
4+
5+
from mpt_api_client import AsyncMPTClient, MPTClient
6+
from mpt_api_client.resources.audit.event_types import (
7+
AsyncEventTypesService,
8+
EventType,
9+
EventTypesService,
10+
)
11+
12+
13+
@pytest.fixture
14+
def event_types_service(mpt_vendor: MPTClient) -> EventTypesService:
15+
return mpt_vendor.audit.event_types
16+
17+
18+
@pytest.fixture
19+
def async_event_types_service(async_mpt_vendor: AsyncMPTClient) -> AsyncEventTypesService:
20+
return async_mpt_vendor.audit.event_types
21+
22+
23+
@pytest.fixture
24+
def event_type(event_types_service: EventTypesService) -> EventType:
25+
return next(event_types_service.iterate())
26+
27+
28+
@pytest.fixture
29+
def event_type_update_data() -> dict[str, Any]:
30+
return {
31+
"description": "Updated description for e2e testing",
32+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from typing import Any
2+
3+
import pytest
4+
5+
from mpt_api_client.exceptions import MPTAPIError
6+
from mpt_api_client.resources.audit.event_types import AsyncEventTypesService, EventType
7+
from mpt_api_client.rql.query_builder import RQLQuery
8+
9+
pytestmark = [pytest.mark.flaky]
10+
11+
12+
async def test_get_event_type(
13+
async_event_types_service: AsyncEventTypesService, event_type: EventType
14+
) -> None:
15+
result = await async_event_types_service.get(event_type.id)
16+
17+
assert result.id == event_type.id
18+
assert result.key == event_type.key
19+
20+
21+
async def test_filter_event_types(
22+
async_event_types_service: AsyncEventTypesService, event_type: EventType
23+
) -> None:
24+
iterator = async_event_types_service.filter(RQLQuery(id=event_type.id)).iterate()
25+
26+
result = [event_type_item async for event_type_item in iterator]
27+
28+
assert len(result) == 1
29+
assert result[0].id == event_type.id
30+
31+
32+
async def test_update_event_type(
33+
async_event_types_service: AsyncEventTypesService,
34+
event_type: EventType,
35+
event_type_update_data: dict[str, Any],
36+
) -> None:
37+
result = await async_event_types_service.update(event_type.id, event_type_update_data)
38+
39+
assert result.id == event_type.id
40+
41+
42+
async def test_get_event_type_not_found(async_event_types_service: AsyncEventTypesService) -> None:
43+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
44+
await async_event_types_service.get("EVT-000-000")
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from typing import Any
2+
3+
import pytest
4+
5+
from mpt_api_client.exceptions import MPTAPIError
6+
from mpt_api_client.resources.audit.event_types import EventType, EventTypesService
7+
from mpt_api_client.rql.query_builder import RQLQuery
8+
9+
pytestmark = [pytest.mark.flaky]
10+
11+
12+
def test_get_event_type(event_types_service: EventTypesService, event_type: EventType) -> None:
13+
result = event_types_service.get(event_type.id)
14+
15+
assert result.id == event_type.id
16+
assert result.key == event_type.key
17+
18+
19+
def test_filter_event_types(event_types_service: EventTypesService, event_type: EventType) -> None:
20+
result = list(event_types_service.filter(RQLQuery(id=event_type.id)).iterate())
21+
22+
assert len(result) == 1
23+
assert result[0].id == event_type.id
24+
25+
26+
def test_update_event_type(
27+
event_types_service: EventTypesService,
28+
event_type: EventType,
29+
event_type_update_data: dict[str, Any],
30+
) -> None:
31+
result = event_types_service.update(event_type.id, event_type_update_data)
32+
33+
assert result.id == event_type.id
34+
35+
36+
def test_get_event_type_not_found(event_types_service: EventTypesService) -> None:
37+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
38+
event_types_service.get("EVT-000-000")

0 commit comments

Comments
 (0)