From d4360b90a5c74c3d00070b9cff7b2c8166ddb66e Mon Sep 17 00:00:00 2001 From: TerryHowe Date: Sat, 2 May 2015 08:27:48 -0600 Subject: [PATCH] Create base class for functional tests Change-Id: I88fee89a1679cc17c06b1db28de5c3817b38308c --- openstack/tests/functional/base.py | 31 +++++++++++++++++++ .../functional/compute/v2/test_flavor.py | 21 ++----------- .../functional/orchestration/v1/test_stack.py | 25 ++------------- 3 files changed, 35 insertions(+), 42 deletions(-) create mode 100644 openstack/tests/functional/base.py diff --git a/openstack/tests/functional/base.py b/openstack/tests/functional/base.py new file mode 100644 index 00000000..314c85ab --- /dev/null +++ b/openstack/tests/functional/base.py @@ -0,0 +1,31 @@ +# 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 unittest + +import os_client_config + +from openstack import connection +from openstack import user_preference + + +class BaseFunctionalTest(unittest.TestCase): + def setUp(self): + test_cloud = os_client_config.OpenStackConfig().get_one_cloud( + 'test_cloud') + + pref = user_preference.UserPreference() + pref.set_region(pref.ALL, test_cloud.region) + + self.conn = connection.Connection( + preference=pref, + **test_cloud.config['auth']) diff --git a/openstack/tests/functional/compute/v2/test_flavor.py b/openstack/tests/functional/compute/v2/test_flavor.py index 6a9b11e4..4f78a098 100644 --- a/openstack/tests/functional/compute/v2/test_flavor.py +++ b/openstack/tests/functional/compute/v2/test_flavor.py @@ -10,29 +10,12 @@ # License for the specific language governing permissions and limitations # under the License. -import unittest - -import os_client_config import six -from openstack import connection -from openstack import user_preference +from openstack.tests.functional import base -class TestFlavor(unittest.TestCase): - def setUp(self): - test_cloud = os_client_config.OpenStackConfig().get_one_cloud( - 'test_cloud') - - pref = user_preference.UserPreference() - pref.set_region(pref.ALL, test_cloud.region) - - self.conn = connection.Connection( - preference=pref, - auth_url=test_cloud.config['auth']['auth_url'], - project_name=test_cloud.config['auth']['project_name'], - username=test_cloud.config['auth']['username'], - password=test_cloud.config['auth']['password']) +class TestFlavor(base.BaseFunctionalTest): def test_flavors(self): flavors = list(self.conn.compute.list_flavors()) diff --git a/openstack/tests/functional/orchestration/v1/test_stack.py b/openstack/tests/functional/orchestration/v1/test_stack.py index bac9f853..d8c836f4 100644 --- a/openstack/tests/functional/orchestration/v1/test_stack.py +++ b/openstack/tests/functional/orchestration/v1/test_stack.py @@ -10,31 +10,10 @@ # License for the specific language governing permissions and limitations # under the License. -import unittest - -import os_client_config - -from openstack import connection -from openstack import user_preference +from openstack.tests.functional import base -class TestStack(unittest.TestCase): - def setUp(self): - test_cloud = os_client_config.OpenStackConfig().get_one_cloud( - 'test_cloud') - - pref = user_preference.UserPreference() - pref.set_region(pref.ALL, test_cloud.region) - - self.conn = connection.Connection( - preference=pref, - auth_url=test_cloud.config['auth']['auth_url'], - project_name=test_cloud.config['auth']['project_name'], - username=test_cloud.config['auth']['username'], - password=test_cloud.config['auth']['password']) - - if self.conn.compute.find_keypair('heat_key') is None: - self.conn.compute.create_keypair(name='heat_key') +class TestStack(base.BaseFunctionalTest): def test_create_stack(self): stack = self.conn.orchestration.create_stack(