tests: Define constants in '_IntegratedTestBase'
Use a slightly more consistent naming scheme for variables, including documentation, and add some variables that should always be defined. Change-Id: Id30e10eab6697e9543d432a8feb2f50d454b6ac8 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
parent
af5a6aae45
commit
c558b58619
|
@ -65,7 +65,7 @@ class ApiSampleTestBaseV21(testscenarios.WithScenarios,
|
|||
# Note that API sample tests also use this in substitutions to validate
|
||||
# that URLs in responses (e.g. location of a server just created) are
|
||||
# correctly constructed.
|
||||
_use_project_id = True
|
||||
USE_PROJECT_ID = True
|
||||
# Availability zones for the API samples tests. Can be overridden by
|
||||
# sub-classes. If set, the AvailabilityZoneFilter is not used.
|
||||
availability_zones = ['us-west']
|
||||
|
@ -80,7 +80,7 @@ class ApiSampleTestBaseV21(testscenarios.WithScenarios,
|
|||
# test v2.18 code without project id
|
||||
('v2_1_noproject_id', {
|
||||
'api_major_version': 'v2.1',
|
||||
'_use_project_id': False,
|
||||
'USE_PROJECT_ID': False,
|
||||
'_additional_fixtures': [
|
||||
api_paste_fixture.ApiPasteNoProjectId]})
|
||||
]
|
||||
|
|
|
@ -43,7 +43,7 @@ class TestCompareResult(test.NoDBTestCase):
|
|||
|
||||
# required by ApiSampleTestBase
|
||||
ast_instance.api_major_version = 'v2'
|
||||
ast_instance._use_project_id = 'True'
|
||||
ast_instance.USE_PROJECT_ID = 'True'
|
||||
|
||||
# automagically create magic methods usually handled by test classes
|
||||
ast_instance.compute = mock.MagicMock()
|
||||
|
|
|
@ -71,10 +71,11 @@ class SimpleTenantUsageSampleJsonTest(test_servers.ServersSampleBase):
|
|||
|
||||
|
||||
class SimpleTenantUsageV240Test(test_servers.ServersSampleBase):
|
||||
USE_PROJECT_ID = False
|
||||
|
||||
sample_dir = 'os-simple-tenant-usage'
|
||||
microversion = '2.40'
|
||||
scenarios = [('v2_40', {'api_major_version': 'v2.1'})]
|
||||
_use_project_id = False
|
||||
|
||||
def setUp(self):
|
||||
super(SimpleTenantUsageV240Test, self).setUp()
|
||||
|
|
|
@ -30,8 +30,9 @@ class VersionsSampleJsonTest(api_sample_base.ApiSampleTestBaseV21):
|
|||
# pipelines that *don't* authenticate.)
|
||||
STUB_KEYSTONE = False
|
||||
|
||||
USE_PROJECT_ID = False
|
||||
|
||||
sample_dir = 'versions'
|
||||
_use_project_id = False
|
||||
# NOTE(gmann): Setting empty scenario for 'version' API testing
|
||||
# as those does not send request on particular endpoint and running
|
||||
# its tests alone is enough.
|
||||
|
|
|
@ -347,14 +347,14 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
|
|||
|
||||
url_re = self._get_host() + r"/v(2|2\.1)/" + project_id_exp
|
||||
new_url = self._get_host() + "/" + self.api_major_version
|
||||
if self._use_project_id:
|
||||
if self.USE_PROJECT_ID:
|
||||
new_url += "/" + self.project_id
|
||||
updated_data = re.sub(url_re, new_url, sample_data)
|
||||
|
||||
# replace unversioned urls
|
||||
url_re = self._get_host() + "/" + project_id_exp
|
||||
new_url = self._get_host()
|
||||
if self._use_project_id:
|
||||
if self.USE_PROJECT_ID:
|
||||
new_url += "/" + self.project_id
|
||||
updated_data = re.sub(url_re, new_url, updated_data)
|
||||
return updated_data
|
||||
|
@ -489,7 +489,7 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
|
|||
def _get_compute_endpoint(self):
|
||||
# NOTE(sdague): "openstack" is stand in for project_id, it
|
||||
# should be more generic in future.
|
||||
if self._use_project_id:
|
||||
if self.USE_PROJECT_ID:
|
||||
return '%s/%s' % (self._get_host(), self.project_id)
|
||||
else:
|
||||
return self._get_host()
|
||||
|
@ -497,7 +497,7 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
|
|||
def _get_vers_compute_endpoint(self):
|
||||
# NOTE(sdague): "openstack" is stand in for project_id, it
|
||||
# should be more generic in future.
|
||||
if self._use_project_id:
|
||||
if self.USE_PROJECT_ID:
|
||||
return '%s/%s/%s' % (self._get_host(), self.api_major_version,
|
||||
self.project_id)
|
||||
else:
|
||||
|
|
|
@ -440,14 +440,29 @@ class InstanceHelperMixin(object):
|
|||
|
||||
|
||||
class _IntegratedTestBase(test.TestCase, InstanceHelperMixin):
|
||||
#: Whether the test requires global external locking being configured for
|
||||
#: them. New tests should set this to False.
|
||||
REQUIRES_LOCKING = True
|
||||
|
||||
#: Whether to use admin credentials for all nova API requests.
|
||||
ADMIN_API = False
|
||||
# This indicates whether to include the project ID in the URL for API
|
||||
# requests through OSAPIFixture. Overridden by subclasses.
|
||||
_use_project_id = False
|
||||
# Override this in subclasses to avoid stubbing keystonemiddleware and
|
||||
# NovaKeystoneContext, thus making those middlewares behave as they would
|
||||
# in real life (i.e. try to do real authentication).
|
||||
|
||||
# TODO(stephenfin): Rename to API_MAJOR_VERSION
|
||||
#: The default API major version to use for all nova API requests.
|
||||
api_major_version = 'v2.1'
|
||||
|
||||
# TODO(stephenfin): Rename to API_MICRO_VERSION
|
||||
#: The default microversion to use for all nova API requests; requires API
|
||||
#: major version 2.1
|
||||
microversion = None
|
||||
|
||||
#: Whether to include the project ID in the URL for API requests through
|
||||
#: OSAPIFixture.
|
||||
USE_PROJECT_ID = False
|
||||
|
||||
#: Whether to stub keystonemiddleware and NovaKeystoneContext; override to
|
||||
#: making those middlewares behave as they would in real life, i.e. try to
|
||||
#: do real authentication.
|
||||
STUB_KEYSTONE = True
|
||||
|
||||
def setUp(self):
|
||||
|
@ -488,7 +503,7 @@ class _IntegratedTestBase(test.TestCase, InstanceHelperMixin):
|
|||
self.api_fixture = self.useFixture(
|
||||
nova_fixtures.OSAPIFixture(
|
||||
api_version=self.api_major_version,
|
||||
use_project_id_in_urls=self._use_project_id,
|
||||
use_project_id_in_urls=self.USE_PROJECT_ID,
|
||||
stub_keystone=self.STUB_KEYSTONE))
|
||||
|
||||
# if the class needs to run as admin, make the api endpoint
|
||||
|
@ -499,7 +514,7 @@ class _IntegratedTestBase(test.TestCase, InstanceHelperMixin):
|
|||
self.api = self.api_fixture.api
|
||||
self.admin_api = self.api_fixture.admin_api
|
||||
|
||||
if hasattr(self, 'microversion'):
|
||||
if self.microversion:
|
||||
self.api.microversion = self.microversion
|
||||
|
||||
if not self.ADMIN_API:
|
||||
|
|
|
@ -43,7 +43,7 @@ class TestCORSMiddleware(api_sample_base.ApiSampleTestBaseV21):
|
|||
|
||||
# With the project_id in the URL, we get the 300 'multiple choices'
|
||||
# response from nova.api.openstack.compute.versions.Versions.
|
||||
self.exp_version_status = 300 if self._use_project_id else 200
|
||||
self.exp_version_status = 300 if self.USE_PROJECT_ID else 200
|
||||
|
||||
# Initialize the application after all the config overrides are in
|
||||
# place.
|
||||
|
|
Loading…
Reference in New Issue