From 30447030b45b446d3eb9500f76c66036d10daf5b Mon Sep 17 00:00:00 2001 From: Albert Sola Date: Tue, 30 Dec 2025 13:34:04 +0100 Subject: [PATCH] MPT-14939 E2E for audit event_types --- tests/e2e/audit/event_types/conftest.py | 32 ++++++++++++++ .../event_types/test_async_event_types.py | 44 +++++++++++++++++++ .../event_types/test_sync_event_types.py | 38 ++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 tests/e2e/audit/event_types/conftest.py create mode 100644 tests/e2e/audit/event_types/test_async_event_types.py create mode 100644 tests/e2e/audit/event_types/test_sync_event_types.py diff --git a/tests/e2e/audit/event_types/conftest.py b/tests/e2e/audit/event_types/conftest.py new file mode 100644 index 0000000..3b492fc --- /dev/null +++ b/tests/e2e/audit/event_types/conftest.py @@ -0,0 +1,32 @@ +from typing import Any + +import pytest + +from mpt_api_client import AsyncMPTClient, MPTClient +from mpt_api_client.resources.audit.event_types import ( + AsyncEventTypesService, + EventType, + EventTypesService, +) + + +@pytest.fixture +def event_types_service(mpt_vendor: MPTClient) -> EventTypesService: + return mpt_vendor.audit.event_types + + +@pytest.fixture +def async_event_types_service(async_mpt_vendor: AsyncMPTClient) -> AsyncEventTypesService: + return async_mpt_vendor.audit.event_types + + +@pytest.fixture +def event_type(event_types_service: EventTypesService) -> EventType: + return next(event_types_service.iterate()) + + +@pytest.fixture +def event_type_update_data() -> dict[str, Any]: + return { + "description": "Updated description for e2e testing", + } diff --git a/tests/e2e/audit/event_types/test_async_event_types.py b/tests/e2e/audit/event_types/test_async_event_types.py new file mode 100644 index 0000000..1dc14d8 --- /dev/null +++ b/tests/e2e/audit/event_types/test_async_event_types.py @@ -0,0 +1,44 @@ +from typing import Any + +import pytest + +from mpt_api_client.exceptions import MPTAPIError +from mpt_api_client.resources.audit.event_types import AsyncEventTypesService, EventType +from mpt_api_client.rql.query_builder import RQLQuery + +pytestmark = [pytest.mark.flaky] + + +async def test_get_event_type( + async_event_types_service: AsyncEventTypesService, event_type: EventType +) -> None: + result = await async_event_types_service.get(event_type.id) + + assert result.id == event_type.id + assert result.key == event_type.key + + +async def test_filter_event_types( + async_event_types_service: AsyncEventTypesService, event_type: EventType +) -> None: + iterator = async_event_types_service.filter(RQLQuery(id=event_type.id)).iterate() + + result = [event_type_item async for event_type_item in iterator] + + assert len(result) == 1 + assert result[0].id == event_type.id + + +async def test_update_event_type( + async_event_types_service: AsyncEventTypesService, + event_type: EventType, + event_type_update_data: dict[str, Any], +) -> None: + result = await async_event_types_service.update(event_type.id, event_type_update_data) + + assert result.id == event_type.id + + +async def test_get_event_type_not_found(async_event_types_service: AsyncEventTypesService) -> None: + with pytest.raises(MPTAPIError, match=r"404 Not Found"): + await async_event_types_service.get("EVT-000-000") diff --git a/tests/e2e/audit/event_types/test_sync_event_types.py b/tests/e2e/audit/event_types/test_sync_event_types.py new file mode 100644 index 0000000..0c0c657 --- /dev/null +++ b/tests/e2e/audit/event_types/test_sync_event_types.py @@ -0,0 +1,38 @@ +from typing import Any + +import pytest + +from mpt_api_client.exceptions import MPTAPIError +from mpt_api_client.resources.audit.event_types import EventType, EventTypesService +from mpt_api_client.rql.query_builder import RQLQuery + +pytestmark = [pytest.mark.flaky] + + +def test_get_event_type(event_types_service: EventTypesService, event_type: EventType) -> None: + result = event_types_service.get(event_type.id) + + assert result.id == event_type.id + assert result.key == event_type.key + + +def test_filter_event_types(event_types_service: EventTypesService, event_type: EventType) -> None: + result = list(event_types_service.filter(RQLQuery(id=event_type.id)).iterate()) + + assert len(result) == 1 + assert result[0].id == event_type.id + + +def test_update_event_type( + event_types_service: EventTypesService, + event_type: EventType, + event_type_update_data: dict[str, Any], +) -> None: + result = event_types_service.update(event_type.id, event_type_update_data) + + assert result.id == event_type.id + + +def test_get_event_type_not_found(event_types_service: EventTypesService) -> None: + with pytest.raises(MPTAPIError, match=r"404 Not Found"): + event_types_service.get("EVT-000-000")