Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_post_with_err_handling(caplog):
# unreachable
responses.add(responses.POST, "https://someurl1", status=404)
utils.post_with_err_handling("https://someurl1", None, None)
assert 'Http Error' in caplog.text
caplog.clear()
# invalid resonse type
responses.add(responses.POST, "https://someurl2")
utils.post_with_err_handling("https://someurl2", None, None)
assert 'Did not receive a valid JSON' in caplog.text
caplog.clear()
# timeout
responses.add(responses.POST, "https://someurl3",
body=requests.exceptions.Timeout())
utils.post_with_err_handling("https://someurl3", None, None)
assert 'Timeout Error' in caplog.text
caplog.clear()
def test_post_with_err_handling(caplog):
# unreachable
responses.add(responses.POST, "https://someurl1", status=404)
utils.post_with_err_handling("https://someurl1", None, None)
assert 'Http Error' in caplog.text
caplog.clear()
# invalid resonse type
responses.add(responses.POST, "https://someurl2")
utils.post_with_err_handling("https://someurl2", None, None)
assert 'Did not receive a valid JSON' in caplog.text
caplog.clear()
# timeout
responses.add(responses.POST, "https://someurl3",
body=requests.exceptions.Timeout())
utils.post_with_err_handling("https://someurl3", None, None)
assert 'Timeout Error' in caplog.text
caplog.clear()
# unreachable
responses.add(responses.POST, "https://someurl1", status=404)
utils.post_with_err_handling("https://someurl1", None, None)
assert 'Http Error' in caplog.text
caplog.clear()
# invalid resonse type
responses.add(responses.POST, "https://someurl2")
utils.post_with_err_handling("https://someurl2", None, None)
assert 'Did not receive a valid JSON' in caplog.text
caplog.clear()
# timeout
responses.add(responses.POST, "https://someurl3",
body=requests.exceptions.Timeout())
utils.post_with_err_handling("https://someurl3", None, None)
assert 'Timeout Error' in caplog.text
caplog.clear()
>>> NumerAPI().raw_query(query, args)
{'data': {'rounds': [{'number': 104}]}}
"""
body = {'query': query,
'variables': variables}
headers = {'Content-type': 'application/json',
'Accept': 'application/json'}
if authorization:
if self.token:
public_id, secret_key = self.token
headers['Authorization'] = \
'Token {}${}'.format(public_id, secret_key)
else:
raise ValueError("API keys required for this action.")
result = utils.post_with_err_handling(
API_TOURNAMENT_URL, body, headers)
if result and "errors" in result:
err = self._handle_call_error(result['errors'])
# fail!
raise ValueError(err)
return result