diff options
author | Lance Bragstad <lbragstad@gmail.com> | 2021-08-31 19:50:03 +0000 |
---|---|---|
committer | Dan Smith <dansmith@redhat.com> | 2021-09-10 08:14:52 -0700 |
commit | 4e68e5da6f4c787e9fc6af76847602a69b0feb96 (patch) | |
tree | d2ac96ab797340e9a7fd3955b1c4e6e4c13035b5 | |
parent | 82a894588517a212228bb9ce1808326ba4bdf359 (diff) | |
download | glance-4e68e5da6f4c787e9fc6af76847602a69b0feb96.tar.gz |
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
-rw-r--r-- | glance/tests/functional/__init__.py | 6 | ||||
-rw-r--r-- | glance/tests/functional/test_reload.py | 7 | ||||
-rw-r--r-- | glance/tests/functional/v2/test_images.py | 35 | ||||
-rw-r--r-- | glance/tests/functional/v2/test_metadef_namespaces.py | 3 | ||||
-rw-r--r-- | glance/tests/functional/v2/test_metadef_objects.py | 3 | ||||
-rw-r--r-- | glance/tests/functional/v2/test_metadef_properties.py | 3 | ||||
-rw-r--r-- | glance/tests/functional/v2/test_metadef_resourcetypes.py | 3 | ||||
-rw-r--r-- | glance/tests/functional/v2/test_metadef_tags.py | 3 | ||||
-rw-r--r-- | glance/tests/functional/v2/test_tasks.py | 3 |
9 files changed, 13 insertions, 53 deletions
diff --git a/glance/tests/functional/__init__.py b/glance/tests/functional/__init__.py index a492b6b71..5c4a5f870 100644 --- a/glance/tests/functional/__init__.py +++ b/glance/tests/functional/__init__.py @@ -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)) diff --git a/glance/tests/functional/test_reload.py b/glance/tests/functional/test_reload.py index d10df9f27..c8e3fd09b 100644 --- a/glance/tests/functional/test_reload.py +++ b/glance/tests/functional/test_reload.py @@ -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 diff --git a/glance/tests/functional/v2/test_images.py b/glance/tests/functional/v2/test_images.py index 4bdbcc0db..6ad8cfdb6 100644 --- a/glance/tests/functional/v2/test_images.py +++ b/glance/tests/functional/v2/test_images.py @@ -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', diff --git a/glance/tests/functional/v2/test_metadef_namespaces.py b/glance/tests/functional/v2/test_metadef_namespaces.py index aa4fed316..8d9ec4365 100644 --- a/glance/tests/functional/v2/test_metadef_namespaces.py +++ b/glance/tests/functional/v2/test_metadef_namespaces.py @@ -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', diff --git a/glance/tests/functional/v2/test_metadef_objects.py b/glance/tests/functional/v2/test_metadef_objects.py index 7d0bd4030..4340c937a 100644 --- a/glance/tests/functional/v2/test_metadef_objects.py +++ b/glance/tests/functional/v2/test_metadef_objects.py @@ -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', diff --git a/glance/tests/functional/v2/test_metadef_properties.py b/glance/tests/functional/v2/test_metadef_properties.py index bd7b26da2..4e6218231 100644 --- a/glance/tests/functional/v2/test_metadef_properties.py +++ b/glance/tests/functional/v2/test_metadef_properties.py @@ -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', diff --git a/glance/tests/functional/v2/test_metadef_resourcetypes.py b/glance/tests/functional/v2/test_metadef_resourcetypes.py index b1769747a..0b17a3720 100644 --- a/glance/tests/functional/v2/test_metadef_resourcetypes.py +++ b/glance/tests/functional/v2/test_metadef_resourcetypes.py @@ -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', diff --git a/glance/tests/functional/v2/test_metadef_tags.py b/glance/tests/functional/v2/test_metadef_tags.py index 632a8724e..912de1fba 100644 --- a/glance/tests/functional/v2/test_metadef_tags.py +++ b/glance/tests/functional/v2/test_metadef_tags.py @@ -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', diff --git a/glance/tests/functional/v2/test_tasks.py b/glance/tests/functional/v2/test_tasks.py index a980ed0d0..971735a61 100644 --- a/glance/tests/functional/v2/test_tasks.py +++ b/glance/tests/functional/v2/test_tasks.py @@ -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', |