diff options
-rw-r--r-- | functest/tests/unit/openstack/snaps/test_snaps.py | 163 | ||||
-rw-r--r-- | upper-constraints.txt | 2 |
2 files changed, 101 insertions, 64 deletions
diff --git a/functest/tests/unit/openstack/snaps/test_snaps.py b/functest/tests/unit/openstack/snaps/test_snaps.py index 14bc38596..db8e3e04a 100644 --- a/functest/tests/unit/openstack/snaps/test_snaps.py +++ b/functest/tests/unit/openstack/snaps/test_snaps.py @@ -40,36 +40,45 @@ class APICheckTesting(unittest.TestCase): mock_shade.assert_called() mock_new_project.assert_called() + @mock.patch('xtesting.core.unit.Suite.generate_html') + @mock.patch('xtesting.core.unit.Suite.generate_xunit') + @mock.patch('xtesting.core.unit.Suite.generate_stats') + @mock.patch('os.path.isdir', return_value=True) + @mock.patch('unittest.TestLoader') @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' 'add_openstack_client_tests') @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' 'add_openstack_api_tests') - @mock.patch('unittest.TextTestRunner.run', - return_value=mock.MagicMock(name='unittest.TextTestResult')) + @mock.patch('subunit.run.SubunitTestRunner.run') 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.TestCase.EX_OK, self.api_check.run()) - self.assertEquals( + args[0].return_value = mock.Mock( + decorated=mock.Mock( + testsRun=100, errors=[], failures=[])) + with mock.patch('six.moves.builtins.open', mock.mock_open()): + self.assertEqual(testcase.TestCase.EX_OK, self.api_check.run()) + self.assertEqual( testcase.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('xtesting.core.unit.Suite.generate_html') + @mock.patch('xtesting.core.unit.Suite.generate_xunit') + @mock.patch('xtesting.core.unit.Suite.generate_stats') + @mock.patch('os.path.isdir', return_value=True) @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' 'add_openstack_client_tests') @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' 'add_openstack_api_tests') - @mock.patch('unittest.TextTestRunner.run', - return_value=mock.MagicMock(name='unittest.TextTestResult')) + @mock.patch('subunit.run.SubunitTestRunner.run') 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.TestCase.EX_OK, self.api_check.run()) - self.assertEquals( + args[0].return_value = mock.Mock( + decorated=mock.Mock( + testsRun=100, errors=[], failures=['foo'])) + with mock.patch('six.moves.builtins.open', mock.mock_open()): + self.assertEqual(testcase.TestCase.EX_OK, self.api_check.run()) + self.assertEqual( testcase.TestCase.EX_TESTCASE_FAILED, self.api_check.is_successful()) args[0].assert_called_with(mock.ANY) @@ -77,19 +86,23 @@ class APICheckTesting(unittest.TestCase): ext_net_name='foo', image_metadata=mock.ANY, os_creds=self.os_creds, suite=mock.ANY, use_keystone=True) + @mock.patch('xtesting.core.unit.Suite.generate_html') + @mock.patch('xtesting.core.unit.Suite.generate_xunit') + @mock.patch('xtesting.core.unit.Suite.generate_stats') + @mock.patch('os.path.isdir', return_value=True) @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' 'add_openstack_client_tests') @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' 'add_openstack_api_tests') - @mock.patch('unittest.TextTestRunner.run', - return_value=mock.MagicMock(name='unittest.TextTestResult')) + @mock.patch('subunit.run.SubunitTestRunner.run') def test_run_1_of_100_ko_criteria(self, *args): self.api_check.criteria = 90 - args[0].return_value.testsRun = 100 - args[0].return_value.failures = ['foo'] - args[0].return_value.errors = [] - self.assertEquals(testcase.TestCase.EX_OK, self.api_check.run()) - self.assertEquals( + args[0].return_value = mock.Mock( + decorated=mock.Mock( + testsRun=100, errors=[], failures=['foo'])) + with mock.patch('six.moves.builtins.open', mock.mock_open()): + self.assertEqual(testcase.TestCase.EX_OK, self.api_check.run()) + self.assertEqual( testcase.TestCase.EX_OK, self.api_check.is_successful()) args[0].assert_called_with(mock.ANY) args[1].assert_called_with( @@ -117,16 +130,20 @@ class HealthCheckTesting(unittest.TestCase): mock_shade.assert_called() mock_new_project.assert_called() + @mock.patch('xtesting.core.unit.Suite.generate_html') + @mock.patch('xtesting.core.unit.Suite.generate_xunit') + @mock.patch('xtesting.core.unit.Suite.generate_stats') + @mock.patch('os.path.isdir', return_value=True) @mock.patch('snaps.openstack.tests.os_source_file_test.' 'OSIntegrationTestCase.parameterize') - @mock.patch('unittest.TextTestRunner.run', - return_value=mock.MagicMock(name='unittest.TextTestResult')) + @mock.patch('subunit.run.SubunitTestRunner.run') 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.TestCase.EX_OK, self.health_check.run()) - self.assertEquals( + args[0].return_value = mock.Mock( + decorated=mock.Mock( + testsRun=100, errors=[], failures=[])) + with mock.patch('six.moves.builtins.open', mock.mock_open()): + self.assertEqual(testcase.TestCase.EX_OK, self.health_check.run()) + self.assertEqual( testcase.TestCase.EX_OK, self.health_check.is_successful()) args[0].assert_called_with(mock.ANY) args[1].assert_called_with( @@ -134,16 +151,20 @@ class HealthCheckTesting(unittest.TestCase): image_metadata=mock.ANY, netconf_override=None, os_creds=self.os_creds, use_keystone=True) + @mock.patch('xtesting.core.unit.Suite.generate_html') + @mock.patch('xtesting.core.unit.Suite.generate_xunit') + @mock.patch('xtesting.core.unit.Suite.generate_stats') + @mock.patch('os.path.isdir', return_value=True) @mock.patch('snaps.openstack.tests.os_source_file_test.' 'OSIntegrationTestCase.parameterize') - @mock.patch('unittest.TextTestRunner.run', - return_value=mock.MagicMock(name='unittest.TextTestResult')) + @mock.patch('subunit.run.SubunitTestRunner.run') 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.TestCase.EX_OK, self.health_check.run()) - self.assertEquals( + args[0].return_value = mock.Mock( + decorated=mock.Mock( + testsRun=100, errors=[], failures=['foo'])) + with mock.patch('six.moves.builtins.open', mock.mock_open()): + self.assertEqual(testcase.TestCase.EX_OK, self.health_check.run()) + self.assertEqual( testcase.TestCase.EX_TESTCASE_FAILED, self.health_check.is_successful()) args[0].assert_called_with(mock.ANY) @@ -152,17 +173,21 @@ class HealthCheckTesting(unittest.TestCase): image_metadata=mock.ANY, netconf_override=None, os_creds=self.os_creds, use_keystone=True) + @mock.patch('xtesting.core.unit.Suite.generate_html') + @mock.patch('xtesting.core.unit.Suite.generate_xunit') + @mock.patch('xtesting.core.unit.Suite.generate_stats') + @mock.patch('os.path.isdir', return_value=True) @mock.patch('snaps.openstack.tests.os_source_file_test.' 'OSIntegrationTestCase.parameterize') - @mock.patch('unittest.TextTestRunner.run', - return_value=mock.MagicMock(name='unittest.TextTestResult')) + @mock.patch('subunit.run.SubunitTestRunner.run') def test_run_1_of_100_ko_criteria(self, *args): self.health_check.criteria = 90 - args[0].return_value.testsRun = 100 - args[0].return_value.failures = ['foo'] - args[0].return_value.errors = [] - self.assertEquals(testcase.TestCase.EX_OK, self.health_check.run()) - self.assertEquals( + args[0].return_value = mock.Mock( + decorated=mock.Mock( + testsRun=100, errors=[], failures=['foo'])) + with mock.patch('six.moves.builtins.open', mock.mock_open()): + self.assertEqual(testcase.TestCase.EX_OK, self.health_check.run()) + self.assertEqual( testcase.TestCase.EX_OK, self.health_check.is_successful()) args[0].assert_called_with(mock.ANY) args[1].assert_called_with( @@ -191,16 +216,20 @@ class SmokeTesting(unittest.TestCase): mock_shade.assert_called() mock_new_project.assert_called() + @mock.patch('xtesting.core.unit.Suite.generate_html') + @mock.patch('xtesting.core.unit.Suite.generate_xunit') + @mock.patch('xtesting.core.unit.Suite.generate_stats') + @mock.patch('os.path.isdir', return_value=True) @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' 'add_openstack_integration_tests') - @mock.patch('unittest.TextTestRunner.run', - return_value=mock.MagicMock(name='unittest.TextTestResult')) + @mock.patch('subunit.run.SubunitTestRunner.run') 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.TestCase.EX_OK, self.smoke.run()) - self.assertEquals(testcase.TestCase.EX_OK, self.smoke.is_successful()) + args[0].return_value = mock.Mock( + decorated=mock.Mock( + testsRun=100, errors=[], failures=[])) + with mock.patch('six.moves.builtins.open', mock.mock_open()): + self.assertEqual(testcase.TestCase.EX_OK, self.smoke.run()) + self.assertEqual(testcase.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=mock.ANY, @@ -208,16 +237,20 @@ class SmokeTesting(unittest.TestCase): os_creds=self.os_creds, suite=mock.ANY, use_floating_ips=True, use_keystone=True) + @mock.patch('xtesting.core.unit.Suite.generate_html') + @mock.patch('xtesting.core.unit.Suite.generate_xunit') + @mock.patch('xtesting.core.unit.Suite.generate_stats') + @mock.patch('os.path.isdir', return_value=True) @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' 'add_openstack_integration_tests') - @mock.patch('unittest.TextTestRunner.run', - return_value=mock.MagicMock(name='unittest.TextTestResult')) + @mock.patch('subunit.run.SubunitTestRunner.run') 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.TestCase.EX_OK, self.smoke.run()) - self.assertEquals( + args[0].return_value = mock.Mock( + decorated=mock.Mock( + testsRun=100, errors=[], failures=['foo'])) + with mock.patch('six.moves.builtins.open', mock.mock_open()): + self.assertEqual(testcase.TestCase.EX_OK, self.smoke.run()) + self.assertEqual( testcase.TestCase.EX_TESTCASE_FAILED, self.smoke.is_successful()) args[0].assert_called_with(mock.ANY) args[1].assert_called_with( @@ -226,17 +259,21 @@ class SmokeTesting(unittest.TestCase): os_creds=self.os_creds, suite=mock.ANY, use_floating_ips=True, use_keystone=True) + @mock.patch('xtesting.core.unit.Suite.generate_html') + @mock.patch('xtesting.core.unit.Suite.generate_xunit') + @mock.patch('xtesting.core.unit.Suite.generate_stats') + @mock.patch('os.path.isdir', return_value=True) @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.' 'add_openstack_integration_tests') - @mock.patch('unittest.TextTestRunner.run', - return_value=mock.MagicMock(name='unittest.TextTestResult')) + @mock.patch('subunit.run.SubunitTestRunner.run') def test_run_1_of_100_ko_criteria(self, *args): self.smoke.criteria = 90 - args[0].return_value.testsRun = 100 - args[0].return_value.failures = ['foo'] - args[0].return_value.errors = [] - self.assertEquals(testcase.TestCase.EX_OK, self.smoke.run()) - self.assertEquals( + args[0].return_value = mock.Mock( + decorated=mock.Mock( + testsRun=100, errors=[], failures=['foo'])) + with mock.patch('six.moves.builtins.open', mock.mock_open()): + self.assertEqual(testcase.TestCase.EX_OK, self.smoke.run()) + self.assertEqual( testcase.TestCase.EX_OK, self.smoke.is_successful()) args[0].assert_called_with(mock.ANY) args[1].assert_called_with( diff --git a/upper-constraints.txt b/upper-constraints.txt index 16200d0b7..7683b04f4 100644 --- a/upper-constraints.txt +++ b/upper-constraints.txt @@ -16,6 +16,6 @@ robotframework-httplibrary===0.4.2 robotframework-requests===0.4.7 robotframework-sshlibrary===2.1.3;python_version=='2.7' ansible===2.3.2.0 -xtesting===0.60.0 +xtesting===0.61.0 git+https://git.openstack.org/openstack/networking-bgpvpn#egg=networking_bgpvpn git+https://git.openstack.org/openstack/networking-sfc#egg=networking_sfc |