def test_unsuccessful_response(self): """ Tests handling a response that is not 200 """ responses.add(responses.GET, "https://securitas.dummy.com", status=404) with pytest.raises(HTTPError): handle_response(requests.get("https://securitas.dummy.com"))
def test_bad_response_xml(self): """ Tests parsing a request with invalid xml syntax """ responses.add( responses.GET, "https://securitas.dummy.com", status=200, body='<?xml version="1.0" encoding="UTF-8"?><tag>unclosed') with pytest.raises(ExpatError): handle_response(requests.get("https://securitas.dummy.com"))
def assert_result(status): responses.reset() responses.add( responses.GET, BASE_URL, status=200, body='<?xml version="1.0" encoding="UTF-8"?><PET><RES>' + status + '</RES><MSG>ERROR</MSG></PET>' ) result = handle_response(requests.get(BASE_URL)) return handle_result(result.get("RES"), result)
def test_successful_response_xml(self): """ Tests parsing a request with correct xml syntax """ responses.add(responses.GET, "https://securitas.dummy.com", status=200, body='<PET>correct</PET>') self.assertEqual( "correct", handle_response(requests.get("https://securitas.dummy.com")))
def _get(): return handle_response(self.get_or_create_session().get( BASE_URL, params=payload, timeout=self.timeout))