Skip to content

Commit ca6e2ce

Browse files
authored
[MPT-14048] Added audit records endpoints (#67)
Added audit records endpoints https://softwareone.atlassian.net/browse/MPT-14048
2 parents e149493 + 054a48d commit ca6e2ce

File tree

5 files changed

+132
-0
lines changed

5 files changed

+132
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
2+
from mpt_api_client.resources.audit.records import AsyncRecordsService, RecordsService
3+
4+
5+
class Audit:
6+
"""Audit MPT API Module."""
7+
8+
def __init__(self, *, http_client: HTTPClient):
9+
self.http_client = http_client
10+
11+
@property
12+
def records(self) -> RecordsService:
13+
"""Records service."""
14+
return RecordsService(http_client=self.http_client)
15+
16+
17+
class AsyncAudit:
18+
"""Async Audit MPT API Module."""
19+
20+
def __init__(self, *, http_client: AsyncHTTPClient):
21+
self.http_client = http_client
22+
23+
@property
24+
def records(self) -> AsyncRecordsService:
25+
"""Records service."""
26+
return AsyncRecordsService(http_client=self.http_client)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from mpt_api_client.http import AsyncService, Service
2+
from mpt_api_client.http.mixins import (
3+
AsyncCreateMixin,
4+
CreateMixin,
5+
)
6+
from mpt_api_client.models import Model
7+
8+
9+
class Record(Model):
10+
"""Record resource."""
11+
12+
13+
class RecordsServiceConfig:
14+
"""Records service configuration."""
15+
16+
_endpoint = "/public/v1/audit/records"
17+
_model_class = Record
18+
_collection_key = "data"
19+
20+
21+
class RecordsService(CreateMixin[Record], Service[Record], RecordsServiceConfig):
22+
"""Records service."""
23+
24+
25+
class AsyncRecordsService(AsyncCreateMixin[Record], AsyncService[Record], RecordsServiceConfig):
26+
"""Async records service."""

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ extend-ignore =
3232

3333

3434
per-file-ignores =
35+
mpt_api_client/resources/audit/*.py: WPS215
3536
mpt_api_client/resources/billing/*.py: WPS215 WPS202 WPS214 WPS204
3637
mpt_api_client/resources/catalog/*.py: WPS110 WPS215 WPS214
3738
mpt_api_client/resources/commerce/*.py: WPS215
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.audit.audit import AsyncAudit, Audit
4+
from mpt_api_client.resources.audit.records import AsyncRecordsService, RecordsService
5+
6+
7+
@pytest.fixture
8+
def audit(http_client):
9+
return Audit(http_client=http_client)
10+
11+
12+
@pytest.fixture
13+
def async_audit(async_http_client):
14+
return AsyncAudit(http_client=async_http_client)
15+
16+
17+
@pytest.mark.parametrize(
18+
("property_name", "expected_service_class"),
19+
[
20+
("records", RecordsService),
21+
],
22+
)
23+
def test_audit_properties(audit, property_name, expected_service_class):
24+
"""Test that Audit properties return correct instances."""
25+
service = getattr(audit, property_name)
26+
27+
assert isinstance(service, expected_service_class)
28+
assert service.http_client is audit.http_client
29+
30+
31+
@pytest.mark.parametrize(
32+
("property_name", "expected_service_class"),
33+
[
34+
("records", AsyncRecordsService),
35+
],
36+
)
37+
def test_async_audit_properties(async_audit, property_name, expected_service_class):
38+
"""Test that AsyncAudit properties return correct instances."""
39+
service = getattr(async_audit, property_name)
40+
41+
assert isinstance(service, expected_service_class)
42+
assert service.http_client is async_audit.http_client
43+
44+
45+
def test_audit_initialization(http_client):
46+
audit = Audit(http_client=http_client)
47+
48+
assert audit.http_client is http_client
49+
assert isinstance(audit, Audit)
50+
51+
52+
def test_async_audit_initialization(async_http_client):
53+
async_audit = AsyncAudit(http_client=async_http_client)
54+
55+
assert async_audit.http_client is async_http_client
56+
assert isinstance(async_audit, AsyncAudit)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.audit.records import AsyncRecordsService, RecordsService
4+
5+
6+
@pytest.fixture
7+
def records_service(http_client):
8+
return RecordsService(http_client=http_client)
9+
10+
11+
@pytest.fixture
12+
def async_records_service(async_http_client):
13+
return AsyncRecordsService(http_client=async_http_client)
14+
15+
16+
@pytest.mark.parametrize("method", ["get", "create"])
17+
def test_mixins_present(records_service, method):
18+
assert hasattr(records_service, method)
19+
20+
21+
@pytest.mark.parametrize("method", ["get", "create"])
22+
def test_async_mixins_present(async_records_service, method):
23+
assert hasattr(async_records_service, method)

0 commit comments

Comments
 (0)