update tests
This commit is contained in:
parent
c6092fe371
commit
1592ec80b4
@ -24,6 +24,7 @@ from werkzeug import wrappers
|
||||
|
||||
from teeth_rest import encoding
|
||||
|
||||
from teeth_agent import agent
|
||||
from teeth_agent import api
|
||||
from teeth_agent import base
|
||||
|
||||
@ -44,7 +45,7 @@ class TestTeethAPI(unittest.TestCase):
|
||||
return client.open(self._get_env_builder(method, path, data, query))
|
||||
|
||||
def test_get_agent_status(self):
|
||||
status = base.TeethAgentStatus('TEST_MODE', time.time(), 'v72ac9')
|
||||
status = agent.TeethAgentStatus('TEST_MODE', time.time(), 'v72ac9')
|
||||
mock_agent = mock.MagicMock()
|
||||
mock_agent.get_status.return_value = status
|
||||
api_server = api.TeethAgentAPIServer(mock_agent)
|
||||
@ -120,7 +121,7 @@ class TestTeethAPI(unittest.TestCase):
|
||||
True,
|
||||
{'test': 'result'})
|
||||
|
||||
mock_agent = mock.create_autospec(base.BaseTeethAgent)
|
||||
mock_agent = mock.create_autospec(agent.TeethAgent)
|
||||
mock_agent.list_command_results.return_value = [
|
||||
cmd_result,
|
||||
]
|
||||
@ -144,7 +145,7 @@ class TestTeethAPI(unittest.TestCase):
|
||||
serialized_cmd_result = cmd_result.serialize(
|
||||
encoding.SerializationViews.PUBLIC)
|
||||
|
||||
mock_agent = mock.create_autospec(base.BaseTeethAgent)
|
||||
mock_agent = mock.create_autospec(agent.TeethAgent)
|
||||
mock_agent.get_command_result.return_value = cmd_result
|
||||
|
||||
api_server = api.TeethAgentAPIServer(mock_agent)
|
||||
|
@ -23,6 +23,7 @@ import pkg_resources
|
||||
|
||||
from teeth_rest import encoding
|
||||
|
||||
from teeth_agent import agent
|
||||
from teeth_agent import base
|
||||
from teeth_agent import errors
|
||||
|
||||
@ -38,10 +39,15 @@ class FooTeethAgentCommandResult(base.AsyncCommandResult):
|
||||
return 'command execution succeeded'
|
||||
|
||||
|
||||
class FakeMode(base.BaseAgentMode):
|
||||
def __init__(self):
|
||||
super(FakeMode, self).__init__('FAKE')
|
||||
|
||||
|
||||
class TestHeartbeater(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.mock_agent = mock.Mock()
|
||||
self.heartbeater = base.TeethAgentHeartbeater(self.mock_agent)
|
||||
self.heartbeater = agent.TeethAgentHeartbeater(self.mock_agent)
|
||||
self.heartbeater.api = mock.Mock()
|
||||
self.heartbeater.stop_event = mock.Mock()
|
||||
|
||||
@ -108,17 +114,15 @@ class TestHeartbeater(unittest.TestCase):
|
||||
self.assertEqual(self.heartbeater.error_delay, 2.7)
|
||||
|
||||
|
||||
class TestBaseTeethAgent(unittest.TestCase):
|
||||
class TestBaseAgent(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.encoder = encoding.RESTJSONEncoder(
|
||||
encoding.SerializationViews.PUBLIC,
|
||||
indent=4)
|
||||
self.agent = base.BaseTeethAgent(None,
|
||||
9999,
|
||||
None,
|
||||
9999,
|
||||
'https://fake_api.example.org:8081/',
|
||||
'TEST_MODE')
|
||||
self.agent = agent.TeethAgent('https://fake_api.example.org:8081/',
|
||||
('localhost', 9999),
|
||||
('localhost', 9999),
|
||||
FakeMode())
|
||||
|
||||
def assertEqualEncoded(self, a, b):
|
||||
# Evidently JSONEncoder.default() can't handle None (??) so we have to
|
||||
@ -133,17 +137,14 @@ class TestBaseTeethAgent(unittest.TestCase):
|
||||
self.agent.started_at = started_at
|
||||
|
||||
status = self.agent.get_status()
|
||||
self.assertIsInstance(status, base.TeethAgentStatus)
|
||||
self.assertEqual(status.mode, 'TEST_MODE')
|
||||
self.assertIsInstance(status, agent.TeethAgentStatus)
|
||||
self.assertEqual(status.started_at, started_at)
|
||||
self.assertEqual(status.version,
|
||||
pkg_resources.get_distribution('teeth-agent').version)
|
||||
|
||||
def test_execute_command(self):
|
||||
do_something_impl = mock.Mock()
|
||||
self.agent.command_map = {
|
||||
'do_something': do_something_impl,
|
||||
}
|
||||
self.agent.mode_implementation['do_something'] = do_something_impl
|
||||
|
||||
self.agent.execute_command('do_something', foo='bar')
|
||||
do_something_impl.assert_called_once_with('do_something', foo='bar')
|
||||
@ -159,12 +160,10 @@ class TestBaseTeethAgent(unittest.TestCase):
|
||||
wsgi_server = wsgi_server_cls.return_value
|
||||
wsgi_server.start.side_effect = KeyboardInterrupt()
|
||||
|
||||
self.agent.get_api_facing_ip_address = mock.Mock()
|
||||
self.agent.get_api_facing_ip_address.return_value = '1.2.3.4'
|
||||
self.agent.heartbeater = mock.Mock()
|
||||
self.agent.run()
|
||||
|
||||
listen_addr = ('1.2.3.4', 9999)
|
||||
listen_addr = ('localhost', 9999)
|
||||
wsgi_server_cls.assert_called_once_with(listen_addr, self.agent.api)
|
||||
wsgi_server.start.assert_called_once_with()
|
||||
wsgi_server.stop.assert_called_once_with()
|
||||
|
@ -19,9 +19,9 @@ import unittest
|
||||
from teeth_agent import decom
|
||||
|
||||
|
||||
class TestBaseTeethAgent(unittest.TestCase):
|
||||
class TestDecomMode(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.agent = decom.DecomAgent(None, 9999, None, 9999, 'fake_api')
|
||||
self.agent_mode = decom.DecomMode()
|
||||
|
||||
def test_decom_mode(self):
|
||||
self.assertEqual(self.agent.mode, 'DECOM')
|
||||
self.assertEqual(self.agent_mode.name, 'DECOM')
|
||||
|
@ -22,12 +22,12 @@ from teeth_agent import errors
|
||||
from teeth_agent import standby
|
||||
|
||||
|
||||
class TestBaseTeethAgent(unittest.TestCase):
|
||||
class TestStandbyMode(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.agent = standby.StandbyAgent(None, 9999, None, 9999, 'fake_api')
|
||||
self.agent_mode = standby.StandbyMode()
|
||||
|
||||
def test_standby_mode(self):
|
||||
self.assertEqual(self.agent.mode, 'STANDBY')
|
||||
self.assertEqual(self.agent_mode.name, 'STANDBY')
|
||||
|
||||
def _build_fake_image_info(self):
|
||||
return {
|
||||
@ -41,7 +41,7 @@ class TestBaseTeethAgent(unittest.TestCase):
|
||||
}
|
||||
|
||||
def test_validate_image_info_success(self):
|
||||
self.agent._validate_image_info(self._build_fake_image_info())
|
||||
self.agent_mode._validate_image_info(self._build_fake_image_info())
|
||||
|
||||
def test_validate_image_info_missing_field(self):
|
||||
for field in ['id', 'urls', 'hashes']:
|
||||
@ -49,7 +49,7 @@ class TestBaseTeethAgent(unittest.TestCase):
|
||||
del invalid_info[field]
|
||||
|
||||
self.assertRaises(errors.InvalidCommandParamsError,
|
||||
self.agent._validate_image_info,
|
||||
self.agent_mode._validate_image_info,
|
||||
invalid_info)
|
||||
|
||||
def test_validate_image_info_invalid_urls(self):
|
||||
@ -57,7 +57,7 @@ class TestBaseTeethAgent(unittest.TestCase):
|
||||
invalid_info['urls'] = 'this_is_not_a_list'
|
||||
|
||||
self.assertRaises(errors.InvalidCommandParamsError,
|
||||
self.agent._validate_image_info,
|
||||
self.agent_mode._validate_image_info,
|
||||
invalid_info)
|
||||
|
||||
def test_validate_image_info_empty_urls(self):
|
||||
@ -73,7 +73,7 @@ class TestBaseTeethAgent(unittest.TestCase):
|
||||
invalid_info['hashes'] = 'this_is_not_a_dict'
|
||||
|
||||
self.assertRaises(errors.InvalidCommandParamsError,
|
||||
self.agent._validate_image_info,
|
||||
self.agent_mode._validate_image_info,
|
||||
invalid_info)
|
||||
|
||||
def test_validate_image_info_empty_hashes(self):
|
||||
@ -85,13 +85,13 @@ class TestBaseTeethAgent(unittest.TestCase):
|
||||
invalid_info)
|
||||
|
||||
def test_cache_images_success(self):
|
||||
result = self.agent.cache_images('cache_images',
|
||||
[self._build_fake_image_info()])
|
||||
result = self.agent_mode.cache_images('cache_images',
|
||||
[self._build_fake_image_info()])
|
||||
result.join()
|
||||
|
||||
def test_cache_images_invalid_image_list(self):
|
||||
self.assertRaises(errors.InvalidCommandParamsError,
|
||||
self.agent.cache_images,
|
||||
self.agent_mode.cache_images,
|
||||
'cache_images',
|
||||
{'foo': 'bar'})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user