|
| 1 | +import pytest |
| 2 | + |
| 3 | +from http import HTTPStatus |
| 4 | + |
| 5 | +from app.objects.c_plugin import Plugin |
| 6 | +from app.utility.base_service import BaseService |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture |
| 10 | +def test_plugin(loop, api_v2_client): |
| 11 | + plugin = Plugin(name="test_plugin", enabled=True, description="a test plugin", address="test_address") |
| 12 | + loop.run_until_complete(BaseService.get_service('data_svc').store(plugin)) |
| 13 | + return plugin |
| 14 | + |
| 15 | + |
| 16 | +@pytest.fixture |
| 17 | +def expected_test_plugin_dump(test_plugin): |
| 18 | + return test_plugin.display_schema.dump(test_plugin) |
| 19 | + |
| 20 | + |
| 21 | +class TestPluginsApi: |
| 22 | + async def test_get_plugins(self, api_v2_client, api_cookies, test_plugin, expected_test_plugin_dump): |
| 23 | + resp = await api_v2_client.get('/api/v2/plugins', cookies=api_cookies) |
| 24 | + plugins_list = await resp.json() |
| 25 | + assert len(plugins_list) == 1 |
| 26 | + plugin_dict = plugins_list[0] |
| 27 | + assert plugin_dict == expected_test_plugin_dump |
| 28 | + |
| 29 | + async def test_unauthorized_get_plugins(self, api_v2_client, test_plugin): |
| 30 | + resp = await api_v2_client.get('/api/v2/plugins') |
| 31 | + assert resp.status == HTTPStatus.UNAUTHORIZED |
| 32 | + |
| 33 | + async def test_get_plugin_by_id(self, api_v2_client, api_cookies, test_plugin, expected_test_plugin_dump): |
| 34 | + resp = await api_v2_client.get(f'/api/v2/plugins/{test_plugin.name}', cookies=api_cookies) |
| 35 | + plugin_dict = await resp.json() |
| 36 | + assert plugin_dict == expected_test_plugin_dump |
| 37 | + |
| 38 | + async def test_unauthorized_get_plugin_by_id(self, api_v2_client, test_plugin): |
| 39 | + resp = await api_v2_client.get(f'/api/v2/plugins/{test_plugin.name}') |
| 40 | + assert resp.status == HTTPStatus.UNAUTHORIZED |
| 41 | + |
| 42 | + async def test_get_nonexistent_plugin_by_id(self, api_v2_client, api_cookies): |
| 43 | + resp = await api_v2_client.get('/api/v2/plugins/999', cookies=api_cookies) |
| 44 | + assert resp.status == HTTPStatus.NOT_FOUND |
0 commit comments