Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions e2e_config.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"accounts.seller.id": "SEL-7310-3075",
"accounts.user.id": "USR-9673-3314",
"accounts.user_group.id": "UGR-6822-0561",
"audit.record.id": "AUD-3748-4760-1006-3938",
"billing.journal.id": "BJO-6562-0928",
"catalog.authorization.id": "AUT-9288-6146",
"catalog.listing.id": "LST-5489-0806",
Expand Down
25 changes: 25 additions & 0 deletions tests/e2e/audit/records/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import Any

import pytest


@pytest.fixture
def record_data(account_id: str) -> dict[str, Any]:
return {
"event": "extensions.e2e.test",
"object": {"id": account_id, "name": "e2e test account"},
"details": "e2e test details",
"summary": "e2e test summary",
"actor": {
"type": "system",
"id": "system",
},
"payload": {
"key": "value",
},
}


@pytest.fixture
def audit_record_id(e2e_config):
return e2e_config["audit.record.id"]
44 changes: 44 additions & 0 deletions tests/e2e/audit/records/test_async_records.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from typing import Any

import pytest

from mpt_api_client import AsyncMPTClient
from mpt_api_client.exceptions import MPTAPIError
from mpt_api_client.resources.audit.records import Record
from mpt_api_client.rql.query_builder import RQLQuery

pytestmark = [pytest.mark.flaky]


@pytest.fixture
async def created_record(async_mpt_vendor: AsyncMPTClient, record_data: dict[str, Any]) -> Record:
service = async_mpt_vendor.audit.records
return await service.create(record_data)


def test_create_record(created_record: Record, record_data: dict[str, Any]) -> None: # noqa: AAA01
assert created_record.event == record_data["event"]
assert created_record.object.id == record_data["object"]["id"]


async def test_get_record(async_mpt_vendor: AsyncMPTClient, audit_record_id: str) -> None:
service = async_mpt_vendor.audit.records
result = await service.get(audit_record_id)

assert result.id == audit_record_id


async def test_iterate_records(async_mpt_vendor: AsyncMPTClient, product_id: str) -> None:
service = async_mpt_vendor.audit.records.filter(RQLQuery(object__id=product_id))
records = [record async for record in service.iterate()]

result = records[0]

assert result.object.id == product_id


async def test_get_record_not_found(async_mpt_vendor: AsyncMPTClient) -> None:
service = async_mpt_vendor.audit.records

with pytest.raises(MPTAPIError):
await service.get("REC-000-000-000")
45 changes: 45 additions & 0 deletions tests/e2e/audit/records/test_sync_records.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from typing import Any

import pytest

from mpt_api_client import MPTClient
from mpt_api_client.exceptions import MPTAPIError
from mpt_api_client.resources.audit.records import Record
from mpt_api_client.rql.query_builder import RQLQuery

pytestmark = [pytest.mark.flaky]


@pytest.fixture
def created_record(mpt_vendor: MPTClient, record_data: dict[str, Any]) -> Record:
service = mpt_vendor.audit.records
return service.create(record_data)


def test_create_record(created_record: Record, record_data: dict[str, Any]) -> None: # noqa: AAA01
assert created_record.event == record_data["event"]
assert created_record.object.id == record_data["object"]["id"]


def test_get_record(mpt_vendor: MPTClient, audit_record_id) -> None:
service = mpt_vendor.audit.records

result = service.get(audit_record_id)

assert result.id == audit_record_id


def test_iterate_records(mpt_vendor: MPTClient, product_id) -> None:
service = mpt_vendor.audit.records.filter(RQLQuery(object__id=product_id))
records = list(service.iterate())

result = records[0]

assert result.object.id == product_id


def test_get_record_not_found(mpt_vendor: MPTClient) -> None:
service = mpt_vendor.audit.records

with pytest.raises(MPTAPIError):
service.get("REC-000-000-000")