Commit 6333bac9 authored by Daniele Venzano's avatar Daniele Venzano
Browse files

More robust unit test

parent 59017890
......@@ -165,6 +165,8 @@ class APIEndpoint:
node['service_stats'][int(str_service_id)] = node['service_stats'][str_service_id]
del node['service_stats'][str_service_id]
return message
raise zoe_api.exceptions.ZoeException(message=message)
def cleanup_dead_executions(self):
"""Terminates all executions with dead "monitor" services."""
......@@ -18,6 +18,7 @@
import pytest
from zoe_api.api_endpoint import APIEndpoint
from zoe_api.exceptions import ZoeException
from zoe_api.tests.mock_master_api import MockAPIManager
from zoe_lib.state.tests.mock_sql_manager import MockSQLManager
......@@ -40,5 +41,9 @@ class TestAPIEndpoint:
def test_statistics_scheduler(self, master_api, sql_manager):
"""Test the scheduler statistics API."""
api = APIEndpoint(master_api, sql_manager)
ret = api.statistics_scheduler('nouser', 'norole')
assert ret == 'No error message' or ret is None
if master_api.fails:
with pytest.raises(ZoeException):
api.statistics_scheduler('nouser', 'norole')
ret = api.statistics_scheduler('nouser', 'norole')
assert isinstance(ret, dict)
......@@ -16,11 +16,11 @@
"""Mock master API for unit testing."""
import logging
from typing import Tuple
from typing import Tuple, Union
log = logging.getLogger(__name__)
APIReturnType = Tuple[bool, str]
APIReturnType = Tuple[bool, Union[str, dict]]
class MockAPIManager:
......@@ -55,4 +55,11 @@ class MockAPIManager:
def scheduler_statistics(self) -> APIReturnType:
"""Query scheduler statistics."""
return self._request_reply()
if self.fails:
return False, "Fake error message"
return True, {
'platform_stats': {
'nodes': []
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment