Skip to content

Commit

Permalink
fix: add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nestor Acuna-Blanco committed May 10, 2024
1 parent cf04144 commit 556563f
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions utests/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,47 @@ def test_log_request(mocked_logger):
"body=%s \n " % request.body)


@mock.patch('RequestsLibrary.log.logger')
def test_log_request_with_headers(mocked_logger):
headers = {'User-Agent': 'python-requests/2.31.0',
'Accept-Encoding': 'gzip, deflate',
'Accept': '*/*',
'Connection': 'keep-alive'}
request = Request(method='get', url='http://mock.rulezz', headers=headers)
request = request.prepare()
response = mock.MagicMock()
response.history = []
response.request = request
log_request(response)
assert mocked_logger.info.call_args[0][0] == ("%s Request : " % request.method +
"url=%s \n " % request.url +
"path_url=%s \n " % request.path_url +
"headers=%s \n " % request.headers +
"body=%s \n " % request.body)


@mock.patch('RequestsLibrary.log.logger')
def test_log_request_with_headers_auth(mocked_logger):
headers = {'User-Agent': 'python-requests/2.31.0',
'Accept-Encoding': 'gzip, deflate',
'Accept': '*/*',
'Connection': 'keep-alive',
'Authorization': 'some_token'}
safe_headers = dict(headers)
safe_headers['Authorization'] = '*****'
request = Request(method='get', url='http://mock.rulezz', headers=headers)
request = request.prepare()
response = mock.MagicMock()
response.history = []
response.request = request
log_request(response)
assert mocked_logger.info.call_args[0][0] == ("%s Request : " % request.method +
"url=%s \n " % request.url +
"path_url=%s \n " % request.path_url +
"headers=%s \n " % safe_headers +
"body=%s \n " % request.body)


@mock.patch('RequestsLibrary.log.logger')
def test_log_request_with_redirect(mocked_logger):
request = Request(method='get', url='http://mock.rulezz/redirected')
Expand Down

0 comments on commit 556563f

Please sign in to comment.