|
| 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 | +async def test_get_subscriber_by_id(async_mpt_client, subscriber_id): |
| 10 | + result = await async_mpt_client.notifications.subscribers.get(subscriber_id) |
| 11 | + |
| 12 | + assert result is not None |
| 13 | + |
| 14 | + |
| 15 | +async def test_list_subscribers(async_mpt_client): |
| 16 | + limit = 10 |
| 17 | + |
| 18 | + result = await async_mpt_client.notifications.subscribers.fetch_page(limit=limit) |
| 19 | + |
| 20 | + assert len(result) > 0 |
| 21 | + |
| 22 | + |
| 23 | +async def test_get_subscriber_by_id_not_found(async_mpt_client, invalid_subscriber_id): |
| 24 | + with pytest.raises(MPTAPIError, match=r"404 Not Found"): |
| 25 | + await async_mpt_client.notifications.subscribers.get(invalid_subscriber_id) |
| 26 | + |
| 27 | + |
| 28 | +async def test_filter_subscribers(async_mpt_client, subscriber_id): |
| 29 | + select_fields = ["-config"] |
| 30 | + async_filtered_subscribers = async_mpt_client.notifications.subscribers.filter( |
| 31 | + RQLQuery(id=subscriber_id) |
| 32 | + ).select(*select_fields) |
| 33 | + |
| 34 | + result = [ |
| 35 | + filtered_subscriber async for filtered_subscriber in async_filtered_subscribers.iterate() |
| 36 | + ] |
| 37 | + |
| 38 | + assert len(result) > 0 |
| 39 | + |
| 40 | + |
| 41 | +async def test_update_subscriber_not_found( |
| 42 | + async_mpt_client, subscriber_factory, invalid_subscriber_id, user_group_id, recipients_factory |
| 43 | +): |
| 44 | + updated_subscriber_data = subscriber_factory(recipients=recipients_factory()) |
| 45 | + |
| 46 | + with pytest.raises(MPTAPIError): |
| 47 | + await async_mpt_client.notifications.subscribers.update( |
| 48 | + invalid_subscriber_id, updated_subscriber_data |
| 49 | + ) |
| 50 | + |
| 51 | + |
| 52 | +async def test_disable_subscriber(async_mpt_client, subscriber_id): |
| 53 | + result = await async_mpt_client.notifications.subscribers.disable(subscriber_id) |
| 54 | + |
| 55 | + assert result is not None |
| 56 | + assert result.status == "disabled" |
| 57 | + |
| 58 | + |
| 59 | +async def test_disable_subscriber_not_found(async_mpt_client, invalid_subscriber_id): |
| 60 | + with pytest.raises(MPTAPIError, match=r"404 Not Found"): |
| 61 | + await async_mpt_client.notifications.subscribers.disable(invalid_subscriber_id) |
| 62 | + |
| 63 | + |
| 64 | +async def test_enable_subscriber(async_mpt_client, subscriber_id): |
| 65 | + result = await async_mpt_client.notifications.subscribers.enable(subscriber_id) |
| 66 | + |
| 67 | + assert result is not None |
| 68 | + assert result.status == "enabled" |
| 69 | + |
| 70 | + |
| 71 | +async def test_enable_subscriber_not_found(async_mpt_client, invalid_subscriber_id): |
| 72 | + with pytest.raises(MPTAPIError, match=r"404 Not Found"): |
| 73 | + await async_mpt_client.notifications.subscribers.enable(invalid_subscriber_id) |
0 commit comments