"Fossies" - the Fresh Open Source Software Archive

Member "monasca-api-3.1.0/monasca_api/tests/test_metrics_db_health_check.py" (27 Sep 2019, 2052 Bytes) of package /linux/misc/openstack/monasca-api-3.1.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 last Fossies "Diffs" side-by-side code changes report for "test_metrics_db_health_check.py": 3.1.0_vs_4.0.0.

    1 # Copyright 2017 FUJITSU LIMITED
    2 # (C) Copyright 2017 Hewlett Packard Enterprise Development LP
    3 #
    4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
    5 # not use this file except in compliance with the License. You may obtain
    6 # a copy of the License at
    7 #
    8 #      http://www.apache.org/licenses/LICENSE-2.0
    9 #
   10 # Unless required by applicable law or agreed to in writing, software
   11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   13 # License for the specific language governing permissions and limitations
   14 # under the License.
   15 
   16 import mock
   17 
   18 from monasca_common.simport import simport
   19 
   20 from monasca_api import config
   21 from monasca_api.healthcheck import metrics_db_check as tdc
   22 from monasca_api.tests import base
   23 
   24 CONF = config.CONF
   25 
   26 
   27 class TestMetricsDbHealthCheck(base.BaseTestCase):
   28 
   29     @mock.patch("monasca_api.healthcheck.metrics_db_check.simport")
   30     def test_health_check(self, simport_mock):
   31         metrics_repo_mock = simport_mock.load.return_value
   32         metrics_repo_mock.check_status.return_value = (True, 'OK')
   33         db_health = tdc.MetricsDbCheck()
   34 
   35         result = db_health.health_check()
   36 
   37         self.assertTrue(result.healthy)
   38 
   39         self.assertEqual(result.message, 'OK')
   40 
   41     @mock.patch("monasca_api.healthcheck.metrics_db_check.simport")
   42     def test_health_check_failed(self, simport_mock):
   43         metrics_repo_mock = simport_mock.load.return_value
   44         metrics_repo_mock.check_status.return_value = (False, 'Error')
   45         db_health = tdc.MetricsDbCheck()
   46 
   47         result = db_health.health_check()
   48 
   49         self.assertFalse(result.healthy)
   50         self.assertEqual(result.message, 'Error')
   51 
   52     @mock.patch("monasca_api.healthcheck.metrics_db_check.simport")
   53     def test_health_check_load_failed(self, simport_mock):
   54         simport_mock.load.side_effect = simport.ImportFailed(
   55             "Failed to import 'foo'. Error: bar")
   56         self.assertRaises(simport.ImportFailed, tdc.MetricsDbCheck)