summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Koderer <m.koderer@telekom.de>2014-05-26 14:31:41 +0200
committerMarc Koderer <m.koderer@telekom.de>2014-05-28 08:49:02 +0200
commit5a22a6e8ce94c88e9ec77f0aaaa54c114237213c (patch)
treea5b283c7ebe2e73a1d3d41b44f0f734dc3d9951e
parent14890c86dc23a548362903f90ea2df2a8bd97884 (diff)
downloadoslotest-5a22a6e8ce94c88e9ec77f0aaaa54c114237213c.tar.gz
Add unit test for olsotest base class
Oslotest base class has special logic and uses environment variables to trigger them. Change-Id: Ic18b6fe528e1d95ad4390b9806aa34c050362690
-rw-r--r--tests/unit/test_base.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/unit/test_base.py b/tests/unit/test_base.py
new file mode 100644
index 0000000..8317d28
--- /dev/null
+++ b/tests/unit/test_base.py
@@ -0,0 +1,73 @@
+# Copyright 2014 Deutsche Telekom AG
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import logging
+
+import mock
+import testtools
+
+from oslotest import base
+
+
+class TestBaseTestCase(testtools.TestCase):
+ class FakeTestCase(base.BaseTestCase):
+ def test_fake_test(self):
+ pass
+
+ @mock.patch('os.environ.get')
+ @mock.patch.object(FakeTestCase, 'useFixture')
+ @mock.patch('fixtures.Timeout')
+ def test_timeout(self, fixture_timeout_mock, fixture_mock, env_get_mock):
+ env_get_mock.return_value = 1
+ tc = self.FakeTestCase("test_fake_test")
+ tc._set_timeout()
+ env_get_mock.assert_called_once_with('OS_TEST_TIMEOUT', 0)
+ fixture_timeout_mock.assert_called_once_with(1, gentle=True)
+ self.assertEqual(fixture_mock.call_count, 1)
+
+ @mock.patch('os.environ.get')
+ @mock.patch.object(FakeTestCase, 'useFixture')
+ def test_fake_logs_default(self, fixture_mock, env_get_mock):
+ # without debug and log capture
+ env_get_mock.side_effect = lambda value: {'OS_DEBUG': 0,
+ 'OS_LOG_CAPTURE': 0}[value]
+ tc = self.FakeTestCase("test_fake_test")
+ tc._fake_logs()
+ env_get_mock.assert_any_call('OS_LOG_CAPTURE')
+ env_get_mock.assert_any_calls('OS_DEBUG')
+ self.assertEqual(fixture_mock.call_count, 0)
+
+ @mock.patch('os.environ.get')
+ @mock.patch('logging.basicConfig')
+ def test_fake_logs_with_debug(self, basic_logger_mock, env_get_mock):
+ env_get_mock.side_effect = lambda value: {'OS_DEBUG': 'True',
+ 'OS_LOG_CAPTURE': 0}[value]
+ tc = self.FakeTestCase("test_fake_test")
+ tc._fake_logs()
+ env_get_mock.assert_any_call('OS_LOG_CAPTURE')
+ env_get_mock.assert_any_calls('OS_DEBUG')
+ basic_logger_mock.assert_called_once_with(format=base._LOG_FORMAT,
+ level=logging.DEBUG)
+
+ @mock.patch('os.environ.get')
+ @mock.patch.object(FakeTestCase, 'useFixture')
+ def test_fake_logs_with_log_cap(self, fixture_mock, env_get_mock):
+ env_get_mock.side_effect = lambda value: {'OS_DEBUG': 0,
+ 'OS_LOG_CAPTURE': 'True'
+ }[value]
+ tc = self.FakeTestCase("test_fake_test")
+ tc._fake_logs()
+ env_get_mock.assert_any_call('OS_LOG_CAPTURE')
+ env_get_mock.assert_any_calls('OS_DEBUG')
+ self.assertEqual(fixture_mock.call_count, 1)