| Total Complexity | 2 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | """Test kytos.core.api_server routes with Flask test_client.""" |
||
| 2 | import asyncio |
||
| 3 | |||
| 4 | KYTOS_CORE_API = "http://127.0.0.1:8181/api/kytos/core" |
||
| 5 | |||
| 6 | |||
| 7 | class TestAPIRoutes: |
||
| 8 | """TestAPIRoutes.""" |
||
| 9 | |||
| 10 | def test_new_endpoint(self, controller, api_client) -> None: |
||
| 11 | """Test new core endpoint.""" |
||
| 12 | |||
| 13 | def handler(): |
||
| 14 | return "response", 200 |
||
| 15 | |||
| 16 | endpoint = "prefix/resource" |
||
| 17 | controller.api_server.register_core_endpoint(endpoint, handler) |
||
| 18 | url = f"{KYTOS_CORE_API}/{endpoint}" |
||
| 19 | response = api_client.get(url) |
||
| 20 | assert response.status_code == 200 |
||
| 21 | assert response.get_data() == b"response" |
||
| 22 | |||
| 23 | def test_new_async_endpoint(self, controller, api_client) -> None: |
||
| 24 | """Test new core async endpoint.""" |
||
| 25 | |||
| 26 | async def handler(): |
||
| 27 | await asyncio.sleep(0) |
||
| 28 | return "response", 200 |
||
| 29 | |||
| 30 | endpoint = "prefix/resource" |
||
| 31 | controller.api_server.register_core_endpoint(endpoint, handler) |
||
| 32 | url = f"{KYTOS_CORE_API}/{endpoint}" |
||
| 33 | response = api_client.get(url) |
||
| 34 | assert response.status_code == 200 |
||
| 35 | assert response.get_data() == b"response" |
||
| 36 |