Skip to content

Commit 11c0591

Browse files
committed
Eliminate uses of requests library test/integration_test.py (#7633)
1 parent fefe88b commit 11c0591

1 file changed

Lines changed: 25 additions & 24 deletions

File tree

test/integration_test.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
validate,
7171
)
7272
import opensearchpy
73-
import requests
7473
import urllib3
7574

7675
from azul import (
@@ -111,8 +110,10 @@
111110
ESClientFactory,
112111
)
113112
from azul.http import (
113+
HasCachedHttpClient,
114114
HttpClient,
115115
http_client,
116+
raise_on_status,
116117
)
117118
from azul.indexer import (
118119
Prefix,
@@ -388,7 +389,7 @@ class IndexingIntegrationTest(IntegrationTestCase):
388389

389390
def setUp(self) -> None:
390391
super().setUp()
391-
self._plain_http = http_client(log)
392+
self._plain_http = self._http_client
392393
self._http = self._plain_http
393394

394395
@contextmanager
@@ -1839,7 +1840,7 @@ def test_azul_client_error_handling(self):
18391840
self.assertEqual({expected}, cm.exception.args[1])
18401841

18411842

1842-
class OpenAPIIntegrationTest(AzulTestCase):
1843+
class OpenAPIIntegrationTest(AzulTestCase, HasCachedHttpClient):
18431844

18441845
def test_openapi(self):
18451846
for component, url in [
@@ -1848,14 +1849,14 @@ def test_openapi(self):
18481849
]:
18491850
with self.subTest(component=component):
18501851
url.set(path='/')
1851-
response = requests.get(str(url))
1852-
self.assertEqual(response.status_code, 200)
1852+
response = self._http_client.urlopen('GET', str(url))
1853+
self.assertEqual(response.status, 200)
18531854
self.assertEqual(response.headers['content-type'], 'text/html')
1854-
self.assertGreater(len(response.content), 0)
1855+
self.assertGreater(len(response.data), 0)
18551856
# validate OpenAPI spec
18561857
url.set(path='/openapi.json')
1857-
response = requests.get(str(url))
1858-
response.raise_for_status()
1858+
response = self._http_client.urlopen('GET', str(url))
1859+
raise_on_status(response)
18591860
spec = response.json()
18601861
validate(spec)
18611862

@@ -1886,21 +1887,21 @@ def tearDownClass(cls) -> None:
18861887
super().tearDownClass()
18871888

18881889
def test_local_chalice(self):
1889-
response = requests.get(str(self.url))
1890-
self.assertEqual(200, response.status_code)
1890+
response = self.http_client.urlopen('GET', str(self.url))
1891+
self.assertEqual(200, response.status)
18911892

18921893
def test_local_chalice_health_endpoint(self):
18931894
url = str(self.url.copy().set(path='health'))
1894-
response = requests.get(url)
1895-
self.assertEqual(200, response.status_code)
1895+
response = self.http_client.urlopen('GET', url)
1896+
self.assertEqual(200, response.status)
18961897

18971898
catalog = first(config.integration_test_catalogs)
18981899

18991900
def test_local_chalice_index_endpoints(self):
19001901
url = str(self.url.copy().set(path='repository/sources',
19011902
query=dict(catalog=self.catalog)))
1902-
response = requests.get(url)
1903-
self.assertEqual(200, response.status_code, response.content)
1903+
response = self.http_client.urlopen('GET', url)
1904+
self.assertEqual(200, response.status, response.data)
19041905

19051906
def test_local_filtered_index_endpoints(self):
19061907
if config.is_hca_enabled(self.catalog):
@@ -1913,11 +1914,11 @@ def test_local_filtered_index_endpoints(self):
19131914
url = str(self.url.copy().set(path='index/files',
19141915
query=dict(filters=json.dumps(filters),
19151916
catalog=self.catalog)))
1916-
response = requests.get(url)
1917-
self.assertEqual(200, response.status_code, response.content)
1917+
response = self.http_client.urlopen('GET', url)
1918+
self.assertEqual(200, response.status, response.data)
19181919

19191920

1920-
class CanBundleScriptIntegrationTest(IntegrationTestCase):
1921+
class CanBundleScriptIntegrationTest(IntegrationTestCase, HasCachedHttpClient):
19211922

19221923
def _test_catalog(self, catalog: config.Catalog):
19231924
fqid = self.bundle_fqid(catalog.name)
@@ -2056,8 +2057,8 @@ def test_version(self):
20562057
('indexer', config.indexer_endpoint)
20572058
]:
20582059
endpoint.set(path='/version')
2059-
response = requests.get(str(endpoint))
2060-
self.assertEqual(response.status_code, 200)
2060+
response = self._http_client.urlopen('GET', str(endpoint))
2061+
self.assertEqual(response.status, 200)
20612062
lambda_status = response.json()['git']
20622063
self.assertEqual(local_status, lambda_status)
20632064

@@ -2077,7 +2078,7 @@ def test(self):
20772078
es.indices.delete(index=[index_name])
20782079

20792080

2080-
class ResponseHeadersTest(AzulTestCase):
2081+
class ResponseHeadersTest(AzulTestCase, HasCachedHttpClient):
20812082

20822083
def test_response_security_headers(self):
20832084
no_cache = 'no-store'
@@ -2093,8 +2094,8 @@ def test_response_security_headers(self):
20932094
for endpoint in (config.service_endpoint, config.indexer_endpoint):
20942095
for path, cache_control in test_cases.items():
20952096
with self.subTest(endpoint=endpoint, path=path):
2096-
response = requests.get(str(endpoint / path))
2097-
response.raise_for_status()
2097+
response = self.http_client.urlopen('GET', str(endpoint / path))
2098+
raise_on_status(response)
20982099
actual_csp = response.headers['Content-Security-Policy']
20992100
parsed_csp = CSP.parse(actual_csp)
21002101
parsed_csp.validate()
@@ -2123,7 +2124,7 @@ def test_response_security_headers(self):
21232124
def test_default_4xx_response_headers(self):
21242125
for endpoint in (config.service_endpoint, config.indexer_endpoint):
21252126
with self.subTest(endpoint=endpoint):
2126-
response = requests.get(str(endpoint / 'does-not-exist'))
2127-
self.assertEqual(403, response.status_code)
2127+
response = self.http_client.urlopen('GET', str(endpoint / 'does-not-exist'))
2128+
self.assertEqual(403, response.status)
21282129
self.assertIsSubset(AzulChaliceApp.security_headers().items(),
21292130
response.headers.items())

0 commit comments

Comments
 (0)