Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
expect(lambda: self.response._detect_error(self.client)).to(
raise_error(NotFoundError)
)
with it('should raise a generic client error for any other 4XX error'):
self.response.status_code = 400
self.response.parsed = False
expect(lambda: self.response._detect_error(self.client)).to(
raise_error(ClientError)
)
with it('should raise a parser error if the result was not parsed'):
self.response.status_code = 200
self.response.parsed = False
expect(lambda: self.response._detect_error(self.client)).to(
raise_error(ParserError)
)
response._parse(self.client)
expect(response.body).to(equal('Hello World'))
expect(response.result).to(be(None))
expect(response.data).to(be(None))
with it('should raise a ParseError if it could not be parsed'):
with Stub() as http_response:
http_response.status_code = '200'
http_response.getheaders().returns(
[('Content-Type', 'application/json')]
)
http_response.read().returns('{')
response = Response(http_response, self.request)
expect(lambda: response._parse(self.client)).to(
raise_error(ParserError)
)
with context('Response._detect_error'):
with before.all:
http_response = Stub()
request = Stub(Request)
self.client = Stub(Client)
self.client.log_level = 'silent'
self.response = Response(http_response, request)
with it('should raise a network error if no status code was found'):
self.response.status_code = None
self.response.parsed = False
expect(lambda: self.response._detect_error(self.client)).to(
raise_error(NetworkError)
)