add unit test for some routes
This commit is contained in:
@@ -3,7 +3,9 @@ import pytest
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from mock import patch
|
from mock import patch
|
||||||
from server import get_log_level
|
from server import get_log_level, app, ProxyState
|
||||||
|
|
||||||
|
pytest_plugins = ('pytest_asyncio',)
|
||||||
|
|
||||||
def test_get_log_level():
|
def test_get_log_level():
|
||||||
|
|
||||||
@@ -30,3 +32,47 @@ def test_get_log_level():
|
|||||||
with patch.dict(os.environ, {'LOG_LVL': 'UNKNOWN'}):
|
with patch.dict(os.environ, {'LOG_LVL': 'UNKNOWN'}):
|
||||||
log_lvl = get_log_level()
|
log_lvl = get_log_level()
|
||||||
assert log_lvl == None
|
assert log_lvl == None
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_home():
|
||||||
|
"""Test the home route."""
|
||||||
|
client = app.test_client()
|
||||||
|
response = await client.get('/')
|
||||||
|
assert response.status_code == 200
|
||||||
|
result = await response.get_data()
|
||||||
|
assert result == b"Hello, world"
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_ready():
|
||||||
|
"""Test the ready route."""
|
||||||
|
|
||||||
|
ProxyState.set_up(False)
|
||||||
|
client = app.test_client()
|
||||||
|
response = await client.get('/-/ready')
|
||||||
|
assert response.status_code == 503
|
||||||
|
result = await response.get_data()
|
||||||
|
assert result == b"Not ready"
|
||||||
|
|
||||||
|
ProxyState.set_up(True)
|
||||||
|
response = await client.get('/-/ready')
|
||||||
|
assert response.status_code == 200
|
||||||
|
result = await response.get_data()
|
||||||
|
assert result == b"Is ready"
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_healthy():
|
||||||
|
"""Test the healthy route."""
|
||||||
|
|
||||||
|
ProxyState.set_up(False)
|
||||||
|
client = app.test_client()
|
||||||
|
response = await client.get('/-/healthy')
|
||||||
|
assert response.status_code == 200
|
||||||
|
result = await response.get_data()
|
||||||
|
assert result == b"I'm fine"
|
||||||
|
|
||||||
|
ProxyState.set_up(True)
|
||||||
|
response = await client.get('/-/healthy')
|
||||||
|
assert response.status_code == 200
|
||||||
|
result = await response.get_data()
|
||||||
|
assert result == b"I'm fine"
|
||||||
|
|||||||
Reference in New Issue
Block a user