Skip to content

Commit 5a3c4ad

Browse files
committed
Eliminate uses of requests library in test/service/test_app_logging.py (#7633)
1 parent c52fff3 commit 5a3c4ad

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

test/service/test_app_logging.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@
1111
patch,
1212
)
1313

14-
import requests
15-
1614
from azul import (
1715
Config,
1816
)
1917
from azul.chalice import (
2018
AzulChaliceApp,
21-
log,
19+
log as chalice_log,
2220
)
2321
from azul.logging import (
2422
configure_test_logging,
23+
get_test_logger,
2524
)
2625
from azul.types import (
2726
JSON,
@@ -39,6 +38,9 @@ def setUpModule():
3938
configure_test_logging()
4039

4140

41+
log = get_test_logger(__name__)
42+
43+
4244
class TestServiceAppLogging(DCP1CannedBundleTestCase, WebServiceTestCase):
4345

4446
@classmethod
@@ -57,9 +59,10 @@ def app_name(cls) -> str:
5759

5860
def test_request_logs(self):
5961
prefix_len = 1024
62+
http = self._http_client
6063

6164
def filter_body(organ: str) -> JSON:
62-
return {'filters': json.dumps({'organ': {'is': [organ]}})}
65+
return {"filters": json.dumps({'organ': {'is': [organ]}})}
6366

6467
for debug, authenticated, body_json in product(
6568
[0, 1, 2],
@@ -77,25 +80,23 @@ def filter_body(organ: str) -> JSON:
7780
url = self.base_url.set(path='/index/projects')
7881
request_headers = {'authorization': 'Bearer foo_token'} if authenticated else {}
7982
level = [INFO, DEBUG, DEBUG][debug]
80-
with self.assertLogs(logger=log, level=level) as logs:
83+
with self.assertLogs(logger=chalice_log, level=level) as logs:
8184
with patch.object(Config, 'debug', new=PropertyMock(return_value=debug)):
8285
if body:
8386
request_headers = {
8487
'content-length': str(len(body)),
8588
'content-type': 'application/json',
8689
**request_headers
8790
}
88-
response = requests.get(str(url),
91+
response = http.request('GET', str(url),
8992
headers=request_headers,
9093
json=body_json)
9194
logs = [(r.levelno, r.getMessage()) for r in logs.records]
9295
body_log_level, body_log_message = logs.pop() # asserted separately
9396
request_headers = {
9497
'host': url.netloc,
95-
'user-agent': 'python-requests/2.32.5',
96-
'accept-encoding': 'gzip, deflate',
97-
'accept': '*/*',
98-
'connection': 'keep-alive',
98+
'accept-encoding': 'identity',
99+
'user-agent': 'python-urllib3/2.6.3',
99100
**request_headers,
100101
}
101102
response_headers = {
@@ -146,7 +147,7 @@ def filter_body(organ: str) -> JSON:
146147
],
147148
logs
148149
)
149-
body = json.dumps(response.json())
150+
body = json.dumps(json.loads(response.data))
150151
self.assertGreater(len(body), prefix_len)
151152
if debug == 0:
152153
expected_log = "… with a response body of type (<class 'dict'>)"
@@ -158,4 +159,4 @@ def filter_body(organ: str) -> JSON:
158159
assert False
159160
self.assertEqual(expected_log, body_log_message)
160161
self.assertEqual(INFO, body_log_level)
161-
self.assertEqual(200, response.status_code)
162+
self.assertEqual(200, response.status)

0 commit comments

Comments
 (0)