|
8 | 8 | from mpt_api_client import RQLQuery |
9 | 9 | from mpt_api_client.exceptions import MPTAPIError |
10 | 10 | from mpt_api_client.http import AsyncService, Service |
11 | | -from mpt_api_client.http.mixins import ( |
| 11 | +from mpt_api_client.http.mixins import ( # noqa: WPS235 |
| 12 | + AsyncDisableMixin, |
| 13 | + AsyncEnableMixin, |
12 | 14 | AsyncFilesOperationsMixin, |
13 | 15 | AsyncManagedResourceMixin, |
14 | 16 | AsyncModifiableResourceMixin, |
15 | 17 | AsyncUpdateFileMixin, |
| 18 | + DisableMixin, |
| 19 | + EnableMixin, |
16 | 20 | FilesOperationsMixin, |
17 | 21 | ManagedResourceMixin, |
18 | 22 | ModifiableResourceMixin, |
@@ -67,6 +71,24 @@ class DummyAsyncUpdateFileService( |
67 | 71 | _upload_data_key = "document" |
68 | 72 |
|
69 | 73 |
|
| 74 | +class EnableDisableSercice( |
| 75 | + EnableMixin[DummyModel], |
| 76 | + DisableMixin[DummyModel], |
| 77 | + Service[DummyModel], |
| 78 | +): |
| 79 | + _endpoint = "/public/v1/dummy" |
| 80 | + _model_class = DummyModel |
| 81 | + |
| 82 | + |
| 83 | +class AsyncEnableDisableSercice( |
| 84 | + AsyncEnableMixin[DummyModel], |
| 85 | + AsyncDisableMixin[DummyModel], |
| 86 | + AsyncService[DummyModel], |
| 87 | +): |
| 88 | + _endpoint = "/public/v1/dummy" |
| 89 | + _model_class = DummyModel |
| 90 | + |
| 91 | + |
70 | 92 | @pytest.fixture |
71 | 93 | def dummy_file_operations_service(http_client): |
72 | 94 | """Fixture for DummyFileOperationsService.""" |
@@ -1277,3 +1299,63 @@ async def test_async_update_file_no_file(async_update_file_service): # noqa: WP |
1277 | 1299 | assert "multipart/form-data" in request.headers["Content-Type"] |
1278 | 1300 | assert result.to_dict() == response_expected_data |
1279 | 1301 | assert isinstance(result, DummyModel) |
| 1302 | + |
| 1303 | + |
| 1304 | +def test_enable_mixin(http_client): |
| 1305 | + service = EnableDisableSercice(http_client=http_client) |
| 1306 | + resource_data = {"name": "Test Resource", "status": "active"} |
| 1307 | + response = httpx.Response(httpx.codes.OK, json=resource_data) |
| 1308 | + with respx.mock: |
| 1309 | + mock_route = respx.post("https://api.example.com/public/v1/dummy/RES-123/enable").mock( |
| 1310 | + return_value=response |
| 1311 | + ) |
| 1312 | + |
| 1313 | + result = service.enable("RES-123", {}) # act |
| 1314 | + |
| 1315 | + assert mock_route.call_count == 1 |
| 1316 | + assert result.to_dict() == resource_data |
| 1317 | + |
| 1318 | + |
| 1319 | +def test_disable_mixin(http_client): |
| 1320 | + service = EnableDisableSercice(http_client=http_client) |
| 1321 | + resource_data = {"name": "Test Resource", "status": "disabled"} |
| 1322 | + response = httpx.Response(httpx.codes.OK, json=resource_data) |
| 1323 | + with respx.mock: |
| 1324 | + mock_route = respx.post("https://api.example.com/public/v1/dummy/RES-123/disable").mock( |
| 1325 | + return_value=response |
| 1326 | + ) |
| 1327 | + |
| 1328 | + result = service.disable("RES-123", {}) # act |
| 1329 | + |
| 1330 | + assert mock_route.call_count == 1 |
| 1331 | + assert result.to_dict() == resource_data |
| 1332 | + |
| 1333 | + |
| 1334 | +async def test_async_disable_mixin(async_http_client): |
| 1335 | + service = AsyncEnableDisableSercice(http_client=async_http_client) |
| 1336 | + resource_data = {"name": "Test Resource", "status": "disabled"} |
| 1337 | + response = httpx.Response(httpx.codes.OK, json=resource_data) |
| 1338 | + with respx.mock: |
| 1339 | + mock_route = respx.post("https://api.example.com/public/v1/dummy/RES-123/disable").mock( |
| 1340 | + return_value=response |
| 1341 | + ) |
| 1342 | + |
| 1343 | + result = await service.disable("RES-123", {}) # act |
| 1344 | + |
| 1345 | + assert mock_route.call_count == 1 |
| 1346 | + assert result.to_dict() == resource_data |
| 1347 | + |
| 1348 | + |
| 1349 | +async def test_async_enable_mixin(async_http_client): |
| 1350 | + service = AsyncEnableDisableSercice(http_client=async_http_client) |
| 1351 | + resource_data = {"name": "Test Resource", "status": "active"} |
| 1352 | + response = httpx.Response(httpx.codes.OK, json=resource_data) |
| 1353 | + with respx.mock: |
| 1354 | + mock_route = respx.post("https://api.example.com/public/v1/dummy/RES-123/enable").mock( |
| 1355 | + return_value=response |
| 1356 | + ) |
| 1357 | + |
| 1358 | + result = await service.enable("RES-123", {}) # act |
| 1359 | + |
| 1360 | + assert mock_route.call_count == 1 |
| 1361 | + assert result.to_dict() == resource_data |
0 commit comments