aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'functest/tests/unit')
-rw-r--r--functest/tests/unit/openstack/snaps/test_snaps.py301
-rw-r--r--functest/tests/unit/openstack/vping/__init__.py0
-rw-r--r--functest/tests/unit/openstack/vping/test_vping.py29
3 files changed, 197 insertions, 133 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)
diff --git a/functest/tests/unit/openstack/vping/__init__.py b/functest/tests/unit/openstack/vping/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/functest/tests/unit/openstack/vping/__init__.py
diff --git a/functest/tests/unit/openstack/vping/test_vping.py b/functest/tests/unit/openstack/vping/test_vping.py
index d494a795..42650dea 100644
--- a/functest/tests/unit/openstack/vping/test_vping.py
+++ b/functest/tests/unit/openstack/vping/test_vping.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
#
# All rights reserved. This program and the accompanying materials
@@ -8,6 +10,7 @@
# pylint: disable=missing-docstring
+import logging
import unittest
import mock
@@ -46,21 +49,25 @@ class VPingUserdataTesting(unittest.TestCase):
os_creds=self.os_creds)
@mock.patch('snaps.openstack.utils.deploy_utils.create_vm_instance')
- @mock.patch('functest.opnfv_tests.openstack.vping.vping_base.os.'
- 'path.exists', return_value=True)
+ @mock.patch('os.path.exists', return_value=True)
@mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create',
return_value=None)
@mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
'get_port_ip', return_value='10.0.0.1')
@mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
'vm_active', return_value=True)
- def test_vping_userdata(self, deploy_vm, path_exists, create_flavor,
- get_port_ip, vm_active):
+ @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
+ 'get_ext_net_name', return_value='foo')
+ def test_vping_userdata(self, *args):
+ # pylint: disable=unused-argument
with mock.patch('snaps.openstack.utils.deploy_utils.create_image',
return_value=OpenStackImage(self.os_creds, None)), \
mock.patch('snaps.openstack.utils.deploy_utils.create_network',
return_value=OpenStackNetwork(
self.os_creds, NetworkConfig(name='foo'))), \
+ mock.patch('snaps.openstack.utils.deploy_utils.create_router',
+ return_value=OpenStackRouter(
+ self.os_creds, RouterConfig(name='foo'))), \
mock.patch('snaps.openstack.utils.deploy_utils.'
'create_vm_instance',
return_value=OpenStackVmInstance(
@@ -91,8 +98,7 @@ class VPingSSHTesting(unittest.TestCase):
os_creds=self.os_creds)
@mock.patch('snaps.openstack.utils.deploy_utils.create_vm_instance')
- @mock.patch('functest.opnfv_tests.openstack.vping.vping_base.os.'
- 'path.exists', return_value=True)
+ @mock.patch('os.path.exists', return_value=True)
@mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create',
return_value=None)
@mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
@@ -110,10 +116,8 @@ class VPingSSHTesting(unittest.TestCase):
'VPingSSH._do_vping_ssh', return_value=TestCase.EX_OK)
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
'get_ext_net_name', return_value='foo')
- def test_vping_ssh(self, create_vm, path_exists,
- flavor_create, get_port_ip, vm_active, ssh_active,
- ssh_client, scp_client, trans_script, do_vping_ssh,
- ext_net_name):
+ def test_vping_ssh(self, *args):
+ # pylint: disable=unused-argument
os_vm_inst = mock.MagicMock(name='get_console_output')
os_vm_inst.get_console_output.return_value = 'vPing OK'
ssh_client = mock.MagicMock(name='get_transport')
@@ -159,3 +163,8 @@ class VPingSSHTesting(unittest.TestCase):
'OpenStackVmInstance.'
'ssh_client', return_value=ssh_client):
self.assertEquals(TestCase.EX_OK, self.vping_ssh.run())
+
+
+if __name__ == "__main__":
+ logging.disable(logging.CRITICAL)
+ unittest.main(verbosity=2)