|
| 1 | +import pytest |
| 2 | + |
| 3 | +from mpt_api_client.exceptions import MPTAPIError |
| 4 | +from mpt_api_client.rql.query_builder import RQLQuery |
| 5 | + |
| 6 | +pytestmark = [pytest.mark.flaky] |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture |
| 10 | +async def created_user_group(async_mpt_ops, user_group): |
| 11 | + new_user_group_request_data = user_group() |
| 12 | + created_user_group = await async_mpt_ops.accounts.user_groups.create( |
| 13 | + new_user_group_request_data |
| 14 | + ) |
| 15 | + |
| 16 | + yield created_user_group |
| 17 | + |
| 18 | + try: |
| 19 | + await async_mpt_ops.accounts.user_groups.delete(created_user_group.id) |
| 20 | + except MPTAPIError as error: |
| 21 | + print(f"TEARDOWN - Unable to delete user group: {error.title}") # noqa: WPS421 |
| 22 | + |
| 23 | + |
| 24 | +async def test_get_user_group_by_id(async_mpt_ops, user_group_id): |
| 25 | + user_group = await async_mpt_ops.accounts.user_groups.get(user_group_id) |
| 26 | + assert user_group is not None |
| 27 | + |
| 28 | + |
| 29 | +async def test_list_user_groups(async_mpt_ops): |
| 30 | + limit = 10 |
| 31 | + user_groups = await async_mpt_ops.accounts.user_groups.fetch_page(limit=limit) |
| 32 | + assert len(user_groups) > 0 |
| 33 | + |
| 34 | + |
| 35 | +async def test_get_user_group_by_id_not_found(async_mpt_ops, invalid_user_group_id): |
| 36 | + with pytest.raises(MPTAPIError, match=r"404 Not Found"): |
| 37 | + await async_mpt_ops.accounts.user_groups.get(invalid_user_group_id) |
| 38 | + |
| 39 | + |
| 40 | +async def test_filter_user_groups(async_mpt_ops, user_group_id): |
| 41 | + select_fields = ["-name"] |
| 42 | + |
| 43 | + filtered_user_groups = ( |
| 44 | + async_mpt_ops.accounts.user_groups.filter(RQLQuery(id=user_group_id)) |
| 45 | + .filter(RQLQuery(name="E2E Seeded User Group")) |
| 46 | + .select(*select_fields) |
| 47 | + ) |
| 48 | + |
| 49 | + user_groups = [ |
| 50 | + filtered_user_group async for filtered_user_group in filtered_user_groups.iterate() |
| 51 | + ] |
| 52 | + |
| 53 | + assert len(user_groups) == 1 |
| 54 | + |
| 55 | + |
| 56 | +def test_create_user_group(created_user_group): |
| 57 | + new_user_group = created_user_group |
| 58 | + assert new_user_group is not None |
| 59 | + |
| 60 | + |
| 61 | +async def test_delete_user_group(async_mpt_ops, created_user_group): |
| 62 | + await async_mpt_ops.accounts.user_groups.delete(created_user_group.id) |
| 63 | + |
| 64 | + |
| 65 | +async def test_delete_user_group_not_found(async_mpt_ops, invalid_user_group_id): |
| 66 | + with pytest.raises(MPTAPIError, match=r"404 Not Found"): |
| 67 | + await async_mpt_ops.accounts.user_groups.delete(invalid_user_group_id) |
| 68 | + |
| 69 | + |
| 70 | +async def test_update_user_group(async_mpt_ops, user_group, created_user_group): |
| 71 | + updated_user_group_data = user_group(name="E2E Updated User Group") |
| 72 | + |
| 73 | + updated_user_group = await async_mpt_ops.accounts.user_groups.update( |
| 74 | + created_user_group.id, updated_user_group_data |
| 75 | + ) |
| 76 | + |
| 77 | + assert updated_user_group is not None |
| 78 | + |
| 79 | + |
| 80 | +async def test_update_user_group_not_found(async_mpt_ops, user_group, invalid_user_group_id): |
| 81 | + updated_user_group_data = user_group(name="Nonexistent User Group") |
| 82 | + |
| 83 | + with pytest.raises(MPTAPIError, match=r"404 Not Found"): |
| 84 | + await async_mpt_ops.accounts.user_groups.update( |
| 85 | + invalid_user_group_id, updated_user_group_data |
| 86 | + ) |
0 commit comments