"Fossies" - the Fresh Open Source Software Archive

Member "masakari-9.0.0/masakari/tests/unit/cmd/test_masakari_api.py" (13 May 2020, 2085 Bytes) of package /linux/misc/openstack/masakari-9.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "test_masakari_api.py": 8.0.0_vs_9.0.0.

    1 # Copyright 2016 NTT DATA
    2 # Licensed under the Apache License, Version 2.0 (the "License"); you may
    3 # not use this file except in compliance with the License. You may obtain
    4 # a copy of the License at
    5 #
    6 #    http://www.apache.org/licenses/LICENSE-2.0
    7 #
    8 # Unless required by applicable law or agreed to in writing, software
    9 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   10 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   11 # License for the specific language governing permissions and limitations
   12 # under the License.
   13 
   14 from unittest import mock
   15 
   16 from masakari.cmd import api
   17 from masakari import config
   18 from masakari import exception
   19 from masakari import test
   20 
   21 
   22 @mock.patch.object(config, 'parse_args', new=lambda *args, **kwargs: None)
   23 class TestMasakariAPI(test.NoDBTestCase):
   24 
   25     def test_continues_without_failure(self):
   26 
   27         fake_server = mock.MagicMock()
   28         fake_server.workers = 123
   29 
   30         def fake_service(api, **kw):
   31             return fake_server
   32 
   33         with mock.patch.object(api, 'service') as mock_service:
   34             mock_service.WSGIService.side_effect = fake_service
   35             api.main()
   36             mock_service.WSGIService.assert_has_calls([
   37                 mock.call('masakari_api', use_ssl=False),
   38             ])
   39             launcher = mock_service.process_launcher.return_value
   40             launcher.launch_service.assert_called_once_with(
   41                 fake_server, workers=123)
   42             self.assertTrue(launcher.wait.called)
   43 
   44     @mock.patch('sys.exit')
   45     def test_fails_if_all_failed(self, mock_exit):
   46         mock_exit.side_effect = exception.MasakariException
   47         with mock.patch.object(api, 'service') as mock_service:
   48             mock_service.WSGIService.side_effect = exception.PasteAppNotFound(
   49                 name='masakari_api', path='/')
   50             self.assertRaises(exception.MasakariException, api.main)
   51             mock_exit.assert_called_once_with(1)
   52             launcher = mock_service.process_launcher.return_value
   53             self.assertFalse(launcher.wait.called)