|
| 1 | +import pytest |
| 2 | + |
| 3 | +from mpt_api_client.exceptions import MPTAPIError |
| 4 | +from mpt_api_client.rql.query_builder import RQLQuery |
| 5 | +from tests.e2e.helper import assert_async_update_resource, async_create_fixture_resource_and_delete |
| 6 | + |
| 7 | +pytestmark = [pytest.mark.flaky] |
| 8 | + |
| 9 | + |
| 10 | +@pytest.fixture |
| 11 | +def async_authorizations_service(async_mpt_ops): |
| 12 | + return async_mpt_ops.catalog.authorizations |
| 13 | + |
| 14 | + |
| 15 | +@pytest.fixture |
| 16 | +async def created_authorization(async_authorizations_service, authorization_data): |
| 17 | + async with async_create_fixture_resource_and_delete( |
| 18 | + async_authorizations_service, authorization_data |
| 19 | + ) as authorization: |
| 20 | + yield authorization |
| 21 | + |
| 22 | + |
| 23 | +def test_create_authorization(created_authorization, authorization_data): # noqa: AAA01 |
| 24 | + assert created_authorization.name == authorization_data["name"] |
| 25 | + |
| 26 | + |
| 27 | +async def test_get_authorization(async_authorizations_service, authorization_id): |
| 28 | + result = await async_authorizations_service.get(authorization_id) |
| 29 | + |
| 30 | + assert result.id == authorization_id |
| 31 | + |
| 32 | + |
| 33 | +async def test_filter_authorizations(async_authorizations_service, authorization_id): |
| 34 | + select_fields = ["-description"] |
| 35 | + filtered = async_authorizations_service.filter(RQLQuery(id=authorization_id)).select( |
| 36 | + *select_fields |
| 37 | + ) |
| 38 | + |
| 39 | + result = [auth async for auth in filtered.iterate()] |
| 40 | + |
| 41 | + assert len(result) == 1 |
| 42 | + assert result[0].id == authorization_id |
| 43 | + |
| 44 | + |
| 45 | +async def test_get_authorization_not_found(async_authorizations_service): |
| 46 | + bogus_id = "AUT-0000-0000" |
| 47 | + |
| 48 | + with pytest.raises(MPTAPIError, match=r"404 Not Found"): |
| 49 | + await async_authorizations_service.get(bogus_id) |
| 50 | + |
| 51 | + |
| 52 | +async def test_update_authorization(async_authorizations_service, authorization_id, short_uuid): |
| 53 | + await assert_async_update_resource( |
| 54 | + async_authorizations_service, authorization_id, "notes", f"e2e test - {short_uuid}" |
| 55 | + ) |
0 commit comments