Fix: TestMasakariAPI tests skipped due to missing __init__.py

__init__.py was missing in `masakari.tests.unit.cmd` package, hence
all tests under that package were skipped.

This patch fixes all failing unit tests after adding __init__.py.

Change-Id: I1a0133ff969260397158b0f3ebd7ca87439fd827
Closes-Bug: #1799634
This commit is contained in:
tpatil 2018-11-07 15:52:28 +09:00
parent 9649cd28ae
commit d8bb02ce0e
3 changed files with 9 additions and 35 deletions

View File

@ -53,18 +53,12 @@ def main():
objects.register_all()
launcher = service.process_launcher()
started = 0
try:
server = service.WSGIService("masakari_api", use_ssl=CONF.use_ssl)
launcher.launch_service(server, workers=server.workers or 1)
started += 1
except exception.PasteAppNotFound as ex:
log.warning("%s. ``enabled_apis`` includes bad values. "
"Fix to remove this warning.", six.text_type(ex))
if started == 0:
log.error('No APIs were started. '
'Check the enabled_apis config option.')
log.error("Failed to start ``masakari_api`` service. Error: %s",
six.text_type(ex))
sys.exit(1)
launcher.wait()

View File

View File

@ -22,52 +22,32 @@ from masakari import test
@mock.patch.object(config, 'parse_args', new=lambda *args, **kwargs: None)
class TestMasakariAPI(test.NoDBTestCase):
def test_continues_on_failure(self, version_cache):
count = [1, 2]
def test_continues_without_failure(self):
fake_server = mock.MagicMock()
fake_server.workers = 123
def fake_service(api, **kw):
while count:
count.pop()
raise exception.PasteAppNotFound(name=api, path='/')
return fake_server
self.flags(enabled_apis=['foo', 'bar', 'baz'])
with mock.patch.object(api, 'service') as mock_service:
mock_service.WSGIService.side_effect = fake_service
api.main()
mock_service.WSGIService.assert_has_calls([
mock.call('foo', use_ssl=False),
mock.call('bar', use_ssl=False),
mock.call('baz', use_ssl=False),
mock.call('masakari_api', use_ssl=False),
])
launcher = mock_service.process_launcher.return_value
launcher.launch_service.assert_called_once_with(
fake_server, workers=123)
self.assertFalse(version_cache.called)
self.assertTrue(launcher.wait.called)
@mock.patch('sys.exit')
def test_fails_if_none_started(self, mock_exit, version_cache):
mock_exit.side_effect = test.TestingException
self.flags(enabled_apis=[])
with mock.patch.object(api, 'service') as mock_service:
self.assertRaises(test.TestingException, api.main)
mock_exit.assert_called_once_with(1)
launcher = mock_service.process_launcher.return_value
self.assertFalse(launcher.wait.called)
self.assertFalse(version_cache.called)
@mock.patch('sys.exit')
def test_fails_if_all_failed(self, mock_exit, version_cache):
mock_exit.side_effect = test.TestingException
self.flags(enabled_apis=['foo', 'bar'])
def test_fails_if_all_failed(self, mock_exit):
mock_exit.side_effect = exception.MasakariException
with mock.patch.object(api, 'service') as mock_service:
mock_service.WSGIService.side_effect = exception.PasteAppNotFound(
name='foo', path='/')
self.assertRaises(test.TestingException, api.main)
name='masakari_api', path='/')
self.assertRaises(exception.MasakariException, api.main)
mock_exit.assert_called_once_with(1)
launcher = mock_service.process_launcher.return_value
self.assertFalse(launcher.wait.called)
self.assertFalse(version_cache.called)