-
Notifications
You must be signed in to change notification settings - Fork 0
MPT-14938 Add audit records e2e #173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
albertsola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.