def test_to_dict_body(self): response = Response() response.body = Body() response_dict = response.to_dict() self.assertTrue(response_dict['body']) response.body.close() response = Response() response.body = NotImplemented response_dict = response.to_dict() self.assertFalse(response_dict['body'])
def test_to_dict(self): request = Request('ftp://foofle.com') request_dict = request.to_dict() self.assertEqual('ftp://foofle.com', request_dict['url']) self.assertEqual('ftp', request_dict['protocol']) response = Response() response.request = request response.reply = Reply(code=200, text='Success') response_dict = response.to_dict() self.assertEqual('ftp://foofle.com', response_dict['request']['url']) self.assertEqual('ftp', response_dict['protocol']) self.assertEqual(200, response_dict['reply']['code']) self.assertEqual(200, response_dict['response_code']) self.assertEqual('Success', response_dict['reply']['text']) self.assertEqual('Success', response_dict['response_message'])