Passed
Push — master ( 15e965...99a8a8 )
by Vinicius
12:21 queued 09:08
created

tests.unit.test_core.test_api_routes   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A TestAPIRoutes.test_new_async_endpoint() 0 13 1
A TestAPIRoutes.test_new_endpoint() 0 12 1
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