Remove duplicate _url() methods from functional test classes

Most of the functional tests contain a version of _url(). The
implementations don't really differ, outside of one that accepts a
protocol and another that is specific to IPV6 for a single test case.

This commit moves the common method to the functional base class and
removes the duplicated logic across the functional test implementations.

Change-Id: I0b161ad404bdb53e3c1cfe878f78a71c239cf40e
This commit is contained in:
Lance Bragstad 2021-08-31 19:50:03 +00:00 committed by Dan Smith
parent 82a8945885
commit 4e68e5da6f
9 changed files with 13 additions and 53 deletions

View File

@ -843,6 +843,9 @@ class FunctionalTest(test_utils.BaseTestCase):
self.addCleanup(self.cleanup)
self._reset_database(self.api_server.sql_connection)
def _url(self, path):
return 'http://127.0.0.1:%d%s' % (self.api_port, path)
def set_policy_rules(self, rules):
fap = open(self.policy_file, 'w')
fap.write(jsonutils.dumps(rules))
@ -1191,6 +1194,9 @@ class MultipleBackendFunctionalTest(test_utils.BaseTestCase):
self._reset_database(
self.api_server_multiple_backend.sql_connection)
def _url(self, path):
return 'http://127.0.0.1:%d%s' % (self.api_port, path)
def set_policy_rules(self, rules):
fap = open(self.policy_file, 'w')
fap.write(jsonutils.dumps(rules))

View File

@ -99,9 +99,6 @@ class TestReload(functional.FunctionalTest):
conf_filepath = os.path.join(conf_dir, '%s.conf' % service)
return conf_filepath
def _url(self, protocol, path):
return '%s://127.0.0.1:%d%s' % (protocol, self.api_port, path)
def test_reload(self):
"""Test SIGHUP picks up new config values"""
def check_pids(pre, post=None, workers=2):
@ -121,7 +118,7 @@ class TestReload(functional.FunctionalTest):
pre_pids = {}
post_pids = {}
path = self._url('http', '/')
path = self._url('/')
response = requests.get(path)
self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
del response # close socket so that process audit is reliable
@ -159,7 +156,7 @@ class TestReload(functional.FunctionalTest):
if check_pids(pre_pids['api'], post_pids['api']):
break
path = self._url('http', '/')
path = self._url('/')
response = requests.get(path)
self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
del response

View File

@ -85,9 +85,6 @@ class TestImages(functional.FunctionalTest):
super(TestImages, self).tearDown()
def _url(self, path):
return 'http://127.0.0.1:%d%s' % (self.api_port, path)
def _headers(self, custom_headers=None):
base_headers = {
'X-Identity-Status': 'Confirmed',
@ -3735,9 +3732,6 @@ class TestImagesIPv6(functional.FunctionalTest):
test_utils.get_unused_port_and_socket = (
test_utils.get_unused_port_and_socket_ipv4)
def _url(self, path):
return "http://[::1]:%d%s" % (self.api_port, path)
def _headers(self, custom_headers=None):
base_headers = {
'X-Identity-Status': 'Confirmed',
@ -3756,10 +3750,12 @@ class TestImagesIPv6(functional.FunctionalTest):
self.api_server.send_identity_credentials = True
self.start_servers(**self.__dict__.copy())
requests.get(self._url('/'), headers=self._headers())
url = f'http://[::1]:{self.api_port}'
path = '/'
requests.get(url + path, headers=self._headers())
path = self._url('/v2/images')
response = requests.get(path, headers=self._headers())
path = '/v2/images'
response = requests.get(url + path, headers=self._headers())
self.assertEqual(200, response.status_code)
images = jsonutils.loads(response.text)['images']
self.assertEqual(0, len(images))
@ -3773,9 +3769,6 @@ class TestImageDirectURLVisibility(functional.FunctionalTest):
self.include_scrubber = False
self.api_server.deployment_flavor = 'noauth'
def _url(self, path):
return 'http://127.0.0.1:%d%s' % (self.api_port, path)
def _headers(self, custom_headers=None):
base_headers = {
'X-Identity-Status': 'Confirmed',
@ -3974,9 +3967,6 @@ class TestImageLocationSelectionStrategy(functional.FunctionalTest):
super(TestImageLocationSelectionStrategy, self).tearDown()
def _url(self, path):
return 'http://127.0.0.1:%d%s' % (self.api_port, path)
def _headers(self, custom_headers=None):
base_headers = {
'X-Identity-Status': 'Confirmed',
@ -4057,9 +4047,6 @@ class TestImageMembers(functional.FunctionalTest):
self.api_server.deployment_flavor = 'fakeauth'
self.start_servers(**self.__dict__.copy())
def _url(self, path):
return 'http://127.0.0.1:%d%s' % (self.api_port, path)
def _headers(self, custom_headers=None):
base_headers = {
'X-Identity-Status': 'Confirmed',
@ -4420,9 +4407,6 @@ class TestQuotas(functional.FunctionalTest):
self.user_storage_quota = 100
self.start_servers(**self.__dict__.copy())
def _url(self, path):
return 'http://127.0.0.1:%d%s' % (self.api_port, path)
def _headers(self, custom_headers=None):
base_headers = {
'X-Identity-Status': 'Confirmed',
@ -4509,9 +4493,6 @@ class TestImagesMultipleBackend(functional.MultipleBackendFunctionalTest):
super(TestImagesMultipleBackend, self).tearDown()
def _url(self, path):
return 'http://127.0.0.1:%d%s' % (self.api_port, path)
def _headers(self, custom_headers=None):
base_headers = {
'X-Identity-Status': 'Confirmed',
@ -6367,9 +6348,6 @@ class TestMultiStoreImageMembers(functional.MultipleBackendFunctionalTest):
super(TestMultiStoreImageMembers, self).tearDown()
def _url(self, path):
return 'http://127.0.0.1:%d%s' % (self.api_port, path)
def _headers(self, custom_headers=None):
base_headers = {
'X-Identity-Status': 'Confirmed',
@ -6768,9 +6746,6 @@ class TestCopyImagePermissions(functional.MultipleBackendFunctionalTest):
self.include_scrubber = False
self.api_server_multiple_backend.deployment_flavor = 'noauth'
def _url(self, path):
return 'http://127.0.0.1:%d%s' % (self.api_port, path)
def _headers(self, custom_headers=None):
base_headers = {
'X-Identity-Status': 'Confirmed',

View File

@ -28,9 +28,6 @@ class TestNamespaces(metadef_base.MetadefFunctionalTestBase):
self.api_server.deployment_flavor = 'noauth'
self.start_servers(**self.__dict__.copy())
def _url(self, path):
return 'http://127.0.0.1:%d%s' % (self.api_port, path)
def _headers(self, custom_headers=None):
base_headers = {
'X-Identity-Status': 'Confirmed',

View File

@ -28,9 +28,6 @@ class TestMetadefObjects(metadef_base.MetadefFunctionalTestBase):
self.api_server.deployment_flavor = 'noauth'
self.start_servers(**self.__dict__.copy())
def _url(self, path):
return 'http://127.0.0.1:%d%s' % (self.api_port, path)
def _headers(self, custom_headers=None):
base_headers = {
'X-Identity-Status': 'Confirmed',

View File

@ -28,9 +28,6 @@ class TestNamespaceProperties(metadef_base.MetadefFunctionalTestBase):
self.api_server.deployment_flavor = 'noauth'
self.start_servers(**self.__dict__.copy())
def _url(self, path):
return 'http://127.0.0.1:%d%s' % (self.api_port, path)
def _headers(self, custom_headers=None):
base_headers = {
'X-Identity-Status': 'Confirmed',

View File

@ -28,9 +28,6 @@ class TestMetadefResourceTypes(metadef_base.MetadefFunctionalTestBase):
self.api_server.deployment_flavor = 'noauth'
self.start_servers(**self.__dict__.copy())
def _url(self, path):
return 'http://127.0.0.1:%d%s' % (self.api_port, path)
def _headers(self, custom_headers=None):
base_headers = {
'X-Identity-Status': 'Confirmed',

View File

@ -28,9 +28,6 @@ class TestMetadefTags(metadef_base.MetadefFunctionalTestBase):
self.api_server.deployment_flavor = 'noauth'
self.start_servers(**self.__dict__.copy())
def _url(self, path):
return 'http://127.0.0.1:%d%s' % (self.api_port, path)
def _headers(self, custom_headers=None):
base_headers = {
'X-Identity-Status': 'Confirmed',

View File

@ -36,9 +36,6 @@ class TestTasks(functional.FunctionalTest):
self.cleanup()
self.api_server.deployment_flavor = 'noauth'
def _url(self, path):
return 'http://127.0.0.1:%d%s' % (self.api_port, path)
def _headers(self, custom_headers=None):
base_headers = {
'X-Identity-Status': 'Confirmed',