"Fossies" - the Fresh Open Source Software Archive

Member "tacker-2.0.0/tacker/tests/unit/base.py" (16 Oct 2019, 2271 Bytes) of package /linux/misc/openstack/tacker-2.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 "base.py": 1.0.0_vs_2.0.0.

    1 # Copyright 2016 Brocade Communications System, Inc.
    2 # All Rights Reserved.
    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 from oslo_config import cfg
   18 from oslo_config import fixture as config_fixture
   19 from requests_mock.contrib import fixture as requests_mock_fixture
   20 
   21 from tacker.tests import base
   22 from tacker.tests.unit import fixtures as tacker_fixtures
   23 
   24 CONF = cfg.CONF
   25 
   26 
   27 class TestCase(base.BaseTestCase):
   28 
   29     def setUp(self):
   30         super(TestCase, self).setUp()
   31         self.config_fixture = self.useFixture(config_fixture.Config(CONF))
   32         CONF([], default_config_files=[])
   33 
   34         # Limit the amount of DeprecationWarning messages in the unit test logs
   35         self.useFixture(tacker_fixtures.WarningsFixture())
   36 
   37     def _mock(self, target, new=mock.DEFAULT):
   38         patcher = mock.patch(target, new)
   39         return patcher.start()
   40 
   41     def compare_obj(self, expected, result, subs=None, allow_missing=None):
   42         if subs is None:
   43             subs = {}
   44         if allow_missing is None:
   45             allow_missing = []
   46 
   47         for key in expected.fields:
   48             if key in allow_missing:
   49                 continue
   50             obj_val = getattr(expected, key)
   51             db_key = subs.get(key, key)
   52             db_val = getattr(result, db_key)
   53 
   54             self.assertEqual(db_val, obj_val)
   55 
   56 
   57 class FixturedTestCase(TestCase):
   58     client_fixture_class = None
   59 
   60     def setUp(self):
   61         super(FixturedTestCase, self).setUp()
   62         if self.client_fixture_class:
   63             self.requests_mock = self.useFixture(requests_mock_fixture.
   64                                                  Fixture())
   65             fix = self.client_fixture_class(self.requests_mock)
   66             self.cs = self.useFixture(fix).client