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_request_with_params(mkm_sandbox20):
"""Verifies request to an endpoint that has mandatory parameters"""
r = mkm_sandbox20.account_management.vacation(params={"onVacation": "false"})
assert r.status_code == 200
with pytest.raises(exceptions.ConnectionError) as e:
mkm_sandbox20.account_management.vacation()
assert e.value.response.status_code == 400
def test_handle_request(mocked_response):
api = Api("https://sandbox.cardmarket.com/ws/v1.1/output.json")
mocked_response.status_code = 400
with pytest.raises(exceptions.ConnectionError):
api.handle_response(mocked_response)
mocked_response.status_code = 401
with pytest.raises(exceptions.ConnectionError):
api.handle_response(mocked_response)
mocked_response.status_code = 403
with pytest.raises(exceptions.ConnectionError):
api.handle_response(mocked_response)
mocked_response.status_code = 404
with pytest.raises(exceptions.ConnectionError):
api.handle_response(mocked_response)
mocked_response.status_code = 405
with pytest.raises(exceptions.ConnectionError):
api.handle_response(mocked_response)
mocked_response.status_code = 409
with pytest.raises(exceptions.ConnectionError):
api.handle_response(mocked_response)
mocked_response.status_code = 410
with pytest.raises(exceptions.ConnectionError):
def handle_response(self, response):
"""
Check the HTTP response
Params:
`response`: Response received from the server
Return:
`response`: Returns the response received if positive or raise exception if negative
"""
# We don't automatically follow redirects so accept those responses
if 200 <= response.status_code <= 399:
return response
else:
raise exceptions.ConnectionError(response)