diff options
Diffstat (limited to 'functest/tests')
-rw-r--r-- | functest/tests/unit/ci/test_check_deployment.py | 4 | ||||
-rw-r--r-- | functest/tests/unit/ci/test_tier_builder.py | 2 | ||||
-rw-r--r-- | functest/tests/unit/vnf/epc/test_juju_epc.py | 95 |
3 files changed, 98 insertions, 3 deletions
diff --git a/functest/tests/unit/ci/test_check_deployment.py b/functest/tests/unit/ci/test_check_deployment.py index 24e3ce53..66d1b7af 100644 --- a/functest/tests/unit/ci/test_check_deployment.py +++ b/functest/tests/unit/ci/test_check_deployment.py @@ -41,7 +41,7 @@ class CheckDeploymentTesting(unittest.TestCase): def test_check_rc(self): with mock.patch('functest.ci.check_deployment.os.path.isfile', returns=True) as m, \ - mock.patch('__builtin__.open', + mock.patch('six.moves.builtins.open', mock.mock_open(read_data='OS_AUTH_URL')): self.deployment.check_rc() self.assertTrue(m.called) @@ -55,7 +55,7 @@ class CheckDeploymentTesting(unittest.TestCase): self.assertTrue(msg in context) def test_check_rc_missing_os_auth(self): - with mock.patch('__builtin__.open', + with mock.patch('six.moves.builtins.open', mock.mock_open(read_data='test')), \ self.assertRaises(Exception) as context: msg = 'OS_AUTH_URL not defined in {}.'.format(self.rc_file) diff --git a/functest/tests/unit/ci/test_tier_builder.py b/functest/tests/unit/ci/test_tier_builder.py index 700c6e91..1dec9aed 100644 --- a/functest/tests/unit/ci/test_tier_builder.py +++ b/functest/tests/unit/ci/test_tier_builder.py @@ -39,7 +39,7 @@ class TierBuilderTesting(unittest.TestCase): with mock.patch('functest.ci.tier_builder.yaml.safe_load', return_value=self.mock_yaml), \ - mock.patch('__builtin__.open', mock.mock_open()): + mock.patch('six.moves.builtins.open', mock.mock_open()): self.tierbuilder = tier_builder.TierBuilder('test_installer', 'test_scenario', 'testcases_file') diff --git a/functest/tests/unit/vnf/epc/test_juju_epc.py b/functest/tests/unit/vnf/epc/test_juju_epc.py new file mode 100644 index 00000000..2b745312 --- /dev/null +++ b/functest/tests/unit/vnf/epc/test_juju_epc.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python + +# Copyright (c) 2017 Rebaca and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 + +""" Unit test testcase for JuJu EPC Implementation""" + +import logging +import unittest + +import mock + +from functest.opnfv_tests.vnf.epc import juju_epc + + +class JujuEpcTesting(unittest.TestCase): + + """Unittest for ABoT EPC with juju orchestrator""" + + def setUp(self): + + self.tenant = 'juju_epc' + self.creds = {'username': 'user', + 'password': 'pwd'} + self.orchestrator = {'name': 'juju', + 'version': '2.0', + 'object': 'foo', + 'requirements': {'flavor': {'name': 'm1.small', + 'ram_min': 2048}, + 'pip': 'python3-pip', + 'repo_link': 'ppa:juju/stable', + 'dep_package': 'software-' + 'properties' + '-common', + 'pip3_packages': 'juju-wait'}} + self.vnf = {'name': 'juju_epc', + 'descriptor': {'version': '1', + 'file_name': '/src/epc-test/' + 'abot_charm/' + 'functest-abot-' + 'epc-bundle/bundle.yaml', + 'name': 'abot-oai-epc', + 'requirements': {'flavor': + {'name': 'm1.medium', + 'ram_min': 4096}}}} + with mock.patch('functest.opnfv_tests.vnf.epc.juju_epc.os.makedirs'), \ + mock.patch('functest.opnfv_tests.vnf.epc.juju_epc.get_config', + return_value={'tenant_images': 'foo', + 'orchestrator': self.orchestrator, + 'vnf': self.vnf, 'vnf_test_suite': '', + 'version': 'whatever'}), \ + mock.patch('functest.utils.openstack_utils.get_keystone_client', + return_value='test'), \ + mock.patch('functest.utils.openstack_utils.get_glance_client', + return_value='test'), \ + mock.patch('functest.utils.openstack_utils.get_neutron_client', + return_value='test'), \ + mock.patch('functest.utils.openstack_utils.get_nova_client', + return_value='test'): + self.epc_vnf = juju_epc.JujuEpc() + + self.images = {'image1': 'url1', + 'image2': 'url2'} + self.details = {'orchestrator': {'status': 'PASS', 'duration': 120}, + 'vnf': {}, + 'test_vnf': {}} + + @mock.patch('functest.utils.openstack_utils.get_keystone_client', + return_value='test') + @mock.patch('functest.utils.openstack_utils.get_or_create_tenant_for_vnf', + return_value=True) + @mock.patch('functest.utils.openstack_utils.get_or_create_user_for_vnf', + return_value=True) + @mock.patch('functest.utils.openstack_utils.get_credentials', + return_value={'auth_url': 'test/v1', + 'project_name': 'test_tenant'}) + @mock.patch('snaps.openstack.create_image.OpenStackImage.create') + @mock.patch('os.system') + def test_prepare_default(self, *args): + """ Unittest for Prepare testcase """ + self.epc_vnf.orchestrator = self.orchestrator + self.assertIsNone(self.epc_vnf.prepare()) + args[4].assert_called_once_with('test', + 'debayan', + 'OAI EPC deployed ' + 'with Juju') + + +if __name__ == "__main__": + logging.disable(logging.CRITICAL) + unittest.main(verbosity=2) |