diff options
author | Cédric Ollivier <cedric.ollivier@orange.com> | 2018-01-28 11:30:47 +0100 |
---|---|---|
committer | Cédric Ollivier <cedric.ollivier@orange.com> | 2018-01-28 11:54:16 +0100 |
commit | 52da4424869eecd428c29a41f1699e6e00767055 (patch) | |
tree | 081a4ea6045ea8b8960c64f611bcc69bb6f17bf8 /functest/tests/unit/openstack/snaps | |
parent | c6092cb676363d89f366dc9a416ba6c53eeea33f (diff) |
Fix warnings in all snaps-related modules
It also adds vping/__init__.py to stop skipping vping unit tests.
It removes the useless import os which is not required for mock (here
the mock patch was simply false).
It should be noted that the code is partially duplicated between
snaps_test_runner.py and vping_base_base.py. A small part of code has
been rewritten to fix that without multi inheritance.
Change-Id: I2e3e181ad7dab8aa41afb1e63d0b6795ff0d1610
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest/tests/unit/openstack/snaps')
-rw-r--r-- | functest/tests/unit/openstack/snaps/test_snaps.py | 301 |
1 files changed, 178 insertions, 123 deletions
diff --git a/functest/tests/unit/openstack/snaps/test_snaps.py b/functest/tests/unit/openstack/snaps/test_snaps.py index 9a360cbc..3d9e9df0 100644 --- a/functest/tests/unit/openstack/snaps/test_snaps.py +++ b/functest/tests/unit/openstack/snaps/test_snaps.py @@ -8,15 +8,15 @@ # pylint: disable=missing-docstring -import mock -import os +import logging import unittest +import mock from snaps.openstack.os_credentials import OSCreds from functest.core.testcase import TestCase -from functest.opnfv_tests.openstack.snaps import (connection_check, api_check, - health_check, smoke) +from functest.opnfv_tests.openstack.snaps import ( + connection_check, api_check, health_check, smoke) class ConnectionCheckTesting(unittest.TestCase): @@ -35,40 +35,52 @@ class ConnectionCheckTesting(unittest.TestCase): @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' 'add_openstack_client_tests') - def test_run_success(self, add_os_client_tests): - result = mock.MagicMock(name='unittest.TextTestResult') - result.testsRun = 100 - result.failures = [] - result.errors = [] - with mock.patch('unittest.TextTestRunner.run', return_value=result): - self.assertEquals(TestCase.EX_OK, self.connection_check.run()) - self.assertEquals(TestCase.EX_OK, - self.connection_check.is_successful()) + @mock.patch('unittest.TextTestRunner.run', + return_value=mock.MagicMock(name='unittest.TextTestResult')) + def test_run_success(self, *args): + args[0].return_value.testsRun = 100 + args[0].return_value.failures = [] + args[0].return_value.errors = [] + self.assertEquals(TestCase.EX_OK, self.connection_check.run()) + self.assertEquals( + TestCase.EX_OK, self.connection_check.is_successful()) + args[0].assert_called_with(mock.ANY) + args[1].assert_called_with( + ext_net_name='foo', os_creds=self.os_creds, suite=mock.ANY, + use_keystone=True) @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' 'add_openstack_client_tests') - def test_run_1_of_100_failures(self, add_os_client_tests): - result = mock.MagicMock(name='unittest.TextTestResult') - result.testsRun = 100 - result.failures = ['foo'] - result.errors = [] - with mock.patch('unittest.TextTestRunner.run', return_value=result): - self.assertEquals(TestCase.EX_OK, self.connection_check.run()) - self.assertEquals(TestCase.EX_TESTCASE_FAILED, - self.connection_check.is_successful()) + @mock.patch('unittest.TextTestRunner.run', + return_value=mock.MagicMock(name='unittest.TextTestResult')) + def test_run_1_of_100_ko(self, *args): + args[0].return_value.testsRun = 100 + args[0].return_value.failures = ['foo'] + args[0].return_value.errors = [] + self.assertEquals(TestCase.EX_OK, self.connection_check.run()) + self.assertEquals( + TestCase.EX_TESTCASE_FAILED, self.connection_check.is_successful()) + args[0].assert_called_with(mock.ANY) + args[1].assert_called_with( + ext_net_name='foo', os_creds=self.os_creds, suite=mock.ANY, + use_keystone=True) @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' 'add_openstack_client_tests') - def test_run_1_of_100_failures_within_criteria(self, add_os_client_tests): + @mock.patch('unittest.TextTestRunner.run', + return_value=mock.MagicMock(name='unittest.TextTestResult')) + def test_run_1_of_100_ko_criteria(self, *args): self.connection_check.criteria = 90 - result = mock.MagicMock(name='unittest.TextTestResult') - result.testsRun = 100 - result.failures = ['foo'] - result.errors = [] - with mock.patch('unittest.TextTestRunner.run', return_value=result): - self.assertEquals(TestCase.EX_OK, self.connection_check.run()) - self.assertEquals(TestCase.EX_OK, - self.connection_check.is_successful()) + args[0].return_value.testsRun = 100 + args[0].return_value.failures = ['foo'] + args[0].return_value.errors = [] + self.assertEquals(TestCase.EX_OK, self.connection_check.run()) + self.assertEquals( + TestCase.EX_OK, self.connection_check.is_successful()) + args[0].assert_called_with(mock.ANY) + args[1].assert_called_with( + ext_net_name='foo', os_creds=self.os_creds, suite=mock.ANY, + use_keystone=True) class APICheckTesting(unittest.TestCase): @@ -87,40 +99,52 @@ class APICheckTesting(unittest.TestCase): @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' 'add_openstack_api_tests') - def test_run_success(self, add_tests): - result = mock.MagicMock(name='unittest.TextTestResult') - result.testsRun = 100 - result.failures = [] - result.errors = [] - with mock.patch('unittest.TextTestRunner.run', return_value=result): - self.assertEquals(TestCase.EX_OK, self.api_check.run()) - self.assertEquals(TestCase.EX_OK, - self.api_check.is_successful()) + @mock.patch('unittest.TextTestRunner.run', + return_value=mock.MagicMock(name='unittest.TextTestResult')) + def test_run_success(self, *args): + args[0].return_value.testsRun = 100 + args[0].return_value.failures = [] + args[0].return_value.errors = [] + self.assertEquals(TestCase.EX_OK, self.api_check.run()) + self.assertEquals( + TestCase.EX_OK, self.api_check.is_successful()) + args[0].assert_called_with(mock.ANY) + args[1].assert_called_with( + ext_net_name='foo', image_metadata=mock.ANY, + os_creds=self.os_creds, suite=mock.ANY, use_keystone=True) @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' 'add_openstack_api_tests') - def test_run_1_of_100_failures(self, add_tests): - result = mock.MagicMock(name='unittest.TextTestResult') - result.testsRun = 100 - result.failures = ['foo'] - result.errors = [] - with mock.patch('unittest.TextTestRunner.run', return_value=result): - self.assertEquals(TestCase.EX_OK, self.api_check.run()) - self.assertEquals(TestCase.EX_TESTCASE_FAILED, - self.api_check.is_successful()) + @mock.patch('unittest.TextTestRunner.run', + return_value=mock.MagicMock(name='unittest.TextTestResult')) + def test_run_1_of_100_ko(self, *args): + args[0].return_value.testsRun = 100 + args[0].return_value.failures = ['foo'] + args[0].return_value.errors = [] + self.assertEquals(TestCase.EX_OK, self.api_check.run()) + self.assertEquals( + TestCase.EX_TESTCASE_FAILED, self.api_check.is_successful()) + args[0].assert_called_with(mock.ANY) + args[1].assert_called_with( + ext_net_name='foo', image_metadata=mock.ANY, + os_creds=self.os_creds, suite=mock.ANY, use_keystone=True) @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' 'add_openstack_api_tests') - def test_run_1_of_100_failures_within_criteria(self, add_tests): + @mock.patch('unittest.TextTestRunner.run', + return_value=mock.MagicMock(name='unittest.TextTestResult')) + def test_run_1_of_100_ko_criteria(self, *args): self.api_check.criteria = 90 - result = mock.MagicMock(name='unittest.TextTestResult') - result.testsRun = 100 - result.failures = ['foo'] - result.errors = [] - with mock.patch('unittest.TextTestRunner.run', return_value=result): - self.assertEquals(TestCase.EX_OK, self.api_check.run()) - self.assertEquals(TestCase.EX_OK, - self.api_check.is_successful()) + args[0].return_value.testsRun = 100 + args[0].return_value.failures = ['foo'] + args[0].return_value.errors = [] + self.assertEquals(TestCase.EX_OK, self.api_check.run()) + self.assertEquals( + TestCase.EX_OK, self.api_check.is_successful()) + args[0].assert_called_with(mock.ANY) + args[1].assert_called_with( + ext_net_name='foo', image_metadata=mock.ANY, + os_creds=self.os_creds, suite=mock.ANY, use_keystone=True) class HealthCheckTesting(unittest.TestCase): @@ -137,42 +161,57 @@ class HealthCheckTesting(unittest.TestCase): self.health_check = health_check.HealthCheck( os_creds=self.os_creds, ext_net_name='foo') - @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' - 'add_openstack_client_tests') - def test_run_success(self, add_tests): - result = mock.MagicMock(name='unittest.TextTestResult') - result.testsRun = 100 - result.failures = [] - result.errors = [] - with mock.patch('unittest.TextTestRunner.run', return_value=result): - self.assertEquals(TestCase.EX_OK, self.health_check.run()) - self.assertEquals(TestCase.EX_OK, - self.health_check.is_successful()) - - @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' - 'add_openstack_client_tests') - def test_run_1_of_100_failures(self, add_tests): - result = mock.MagicMock(name='unittest.TextTestResult') - result.testsRun = 100 - result.failures = ['foo'] - result.errors = [] - with mock.patch('unittest.TextTestRunner.run', return_value=result): - self.assertEquals(TestCase.EX_OK, self.health_check.run()) - self.assertEquals(TestCase.EX_TESTCASE_FAILED, - self.health_check.is_successful()) - - @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' - 'add_openstack_client_tests') - def test_run_1_of_100_failures_within_criteria(self, add_tests): + @mock.patch('snaps.openstack.tests.os_source_file_test.' + 'OSIntegrationTestCase.parameterize') + @mock.patch('unittest.TextTestRunner.run', + return_value=mock.MagicMock(name='unittest.TextTestResult')) + def test_run_success(self, *args): + args[0].return_value.testsRun = 100 + args[0].return_value.failures = [] + args[0].return_value.errors = [] + self.assertEquals(TestCase.EX_OK, self.health_check.run()) + self.assertEquals( + TestCase.EX_OK, self.health_check.is_successful()) + args[0].assert_called_with(mock.ANY) + args[1].assert_called_with( + mock.ANY, ext_net_name='foo', flavor_metadata=None, + image_metadata=mock.ANY, netconf_override=None, + os_creds=self.os_creds, use_keystone=True) + + @mock.patch('snaps.openstack.tests.os_source_file_test.' + 'OSIntegrationTestCase.parameterize') + @mock.patch('unittest.TextTestRunner.run', + return_value=mock.MagicMock(name='unittest.TextTestResult')) + def test_run_1_of_100_ko(self, *args): + args[0].return_value.testsRun = 100 + args[0].return_value.failures = ['foo'] + args[0].return_value.errors = [] + self.assertEquals(TestCase.EX_OK, self.health_check.run()) + self.assertEquals( + TestCase.EX_TESTCASE_FAILED, self.health_check.is_successful()) + args[0].assert_called_with(mock.ANY) + args[1].assert_called_with( + mock.ANY, ext_net_name='foo', flavor_metadata=None, + image_metadata=mock.ANY, netconf_override=None, + os_creds=self.os_creds, use_keystone=True) + + @mock.patch('snaps.openstack.tests.os_source_file_test.' + 'OSIntegrationTestCase.parameterize') + @mock.patch('unittest.TextTestRunner.run', + return_value=mock.MagicMock(name='unittest.TextTestResult')) + def test_run_1_of_100_ko_criteria(self, *args): self.health_check.criteria = 90 - result = mock.MagicMock(name='unittest.TextTestResult') - result.testsRun = 100 - result.failures = ['foo'] - result.errors = [] - with mock.patch('unittest.TextTestRunner.run', return_value=result): - self.assertEquals(TestCase.EX_OK, self.health_check.run()) - self.assertEquals(TestCase.EX_OK, - self.health_check.is_successful()) + args[0].return_value.testsRun = 100 + args[0].return_value.failures = ['foo'] + args[0].return_value.errors = [] + self.assertEquals(TestCase.EX_OK, self.health_check.run()) + self.assertEquals( + TestCase.EX_OK, self.health_check.is_successful()) + args[0].assert_called_with(mock.ANY) + args[1].assert_called_with( + mock.ANY, ext_net_name='foo', flavor_metadata=None, + image_metadata=mock.ANY, netconf_override=None, + os_creds=self.os_creds, use_keystone=True) class SmokeTesting(unittest.TestCase): @@ -191,40 +230,56 @@ class SmokeTesting(unittest.TestCase): @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' 'add_openstack_integration_tests') - @mock.patch('os.path.join', return_value=os.getcwd()) - def test_run_success(self, add_tests, cwd): - result = mock.MagicMock(name='unittest.TextTestResult') - result.testsRun = 100 - result.failures = [] - result.errors = [] - with mock.patch('unittest.TextTestRunner.run', return_value=result): - self.assertEquals(TestCase.EX_OK, self.smoke.run()) - self.assertEquals(TestCase.EX_OK, - self.smoke.is_successful()) + @mock.patch('unittest.TextTestRunner.run', + return_value=mock.MagicMock(name='unittest.TextTestResult')) + def test_run_success(self, *args): + args[0].return_value.testsRun = 100 + args[0].return_value.failures = [] + args[0].return_value.errors = [] + self.assertEquals(TestCase.EX_OK, self.smoke.run()) + self.assertEquals(TestCase.EX_OK, self.smoke.is_successful()) + args[0].assert_called_with(mock.ANY) + args[1].assert_called_with( + ext_net_name='foo', flavor_metadata=None, image_metadata=mock.ANY, + netconf_override=None, os_creds=self.os_creds, + suite=mock.ANY, use_floating_ips=True, use_keystone=True) @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' 'add_openstack_integration_tests') - @mock.patch('os.path.join', return_value=os.getcwd()) - def test_run_1_of_100_failures(self, add_tests, cwd): - result = mock.MagicMock(name='unittest.TextTestResult') - result.testsRun = 100 - result.failures = ['foo'] - result.errors = [] - with mock.patch('unittest.TextTestRunner.run', return_value=result): - self.assertEquals(TestCase.EX_OK, self.smoke.run()) - self.assertEquals(TestCase.EX_TESTCASE_FAILED, - self.smoke.is_successful()) + @mock.patch('unittest.TextTestRunner.run', + return_value=mock.MagicMock(name='unittest.TextTestResult')) + def test_run_1_of_100_ko(self, *args): + args[0].return_value.testsRun = 100 + args[0].return_value.failures = ['foo'] + args[0].return_value.errors = [] + self.assertEquals(TestCase.EX_OK, self.smoke.run()) + self.assertEquals( + TestCase.EX_TESTCASE_FAILED, self.smoke.is_successful()) + args[0].assert_called_with(mock.ANY) + args[1].assert_called_with( + ext_net_name='foo', flavor_metadata=None, image_metadata=mock.ANY, + netconf_override=mock.ANY, os_creds=self.os_creds, + suite=mock.ANY, use_floating_ips=True, use_keystone=True) @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' 'add_openstack_integration_tests') - @mock.patch('os.path.join', return_value=os.getcwd()) - def test_run_1_of_100_failures_within_criteria(self, add_tests, cwd): + @mock.patch('unittest.TextTestRunner.run', + return_value=mock.MagicMock(name='unittest.TextTestResult')) + def test_run_1_of_100_ko_criteria(self, *args): self.smoke.criteria = 90 - result = mock.MagicMock(name='unittest.TextTestResult') - result.testsRun = 100 - result.failures = ['foo'] - result.errors = [] - with mock.patch('unittest.TextTestRunner.run', return_value=result): - self.assertEquals(TestCase.EX_OK, self.smoke.run()) - self.assertEquals(TestCase.EX_OK, - self.smoke.is_successful()) + args[0].return_value.testsRun = 100 + args[0].return_value.failures = ['foo'] + args[0].return_value.errors = [] + self.assertEquals(TestCase.EX_OK, self.smoke.run()) + self.assertEquals( + TestCase.EX_OK, self.smoke.is_successful()) + args[0].assert_called_with(mock.ANY) + args[1].assert_called_with( + ext_net_name='foo', flavor_metadata=None, image_metadata=mock.ANY, + netconf_override=None, os_creds=self.os_creds, + suite=mock.ANY, use_floating_ips=True, use_keystone=True) + + +if __name__ == "__main__": + logging.disable(logging.CRITICAL) + unittest.main(verbosity=2) |