def test_add_urllib3_response(self): r = Response() r.status_code = 200 r.headers = {} util.add_urllib3_response( {'body': { 'string': decode('foo'), 'encoding': 'utf-8' }}, r, HTTPHeaderDict()) assert isinstance(r.raw, urllib3.response.HTTPResponse) assert r.content == b'foo' assert isinstance(r.raw._original_response, mock_response.MockHTTPResponse)
def test_add_urllib3_response(self): r = Response() r.status_code = 200 r.headers = {} util.add_urllib3_response({ 'body': { 'string': decode('foo'), 'encoding': 'utf-8' } }, r, HTTPHeaderDict()) assert isinstance(r.raw, urllib3.response.HTTPResponse) assert r.content == b'foo' assert isinstance(r.raw._original_response, mock_response.MockHTTPResponse)
def test_serialize_response(self): r = Response() r.status_code = 200 r.reason = 'OK' r.encoding = 'utf-8' r.headers = CaseInsensitiveDict() r.url = 'http://example.com' util.add_urllib3_response( {'body': { 'string': decode('foo'), 'encoding': 'utf-8' }}, r, HTTPHeaderDict()) serialized = util.serialize_response(r, False) assert serialized is not None assert serialized != {} assert serialized['body']['encoding'] == 'utf-8' assert serialized['body']['string'] == 'foo' assert serialized['headers'] == {} assert serialized['url'] == 'http://example.com' assert serialized['status'] == {'code': 200, 'message': 'OK'}
def test_serialize_response(self): r = Response() r.status_code = 200 r.reason = 'OK' r.encoding = 'utf-8' r.headers = CaseInsensitiveDict() r.url = 'http://example.com' util.add_urllib3_response({ 'body': { 'string': decode('foo'), 'encoding': 'utf-8' } }, r, HTTPHeaderDict()) serialized = util.serialize_response(r, False) assert serialized is not None assert serialized != {} assert serialized['body']['encoding'] == 'utf-8' assert serialized['body']['string'] == 'foo' assert serialized['headers'] == {} assert serialized['url'] == 'http://example.com' assert serialized['status'] == {'code': 200, 'message': 'OK'}
def setUp(self): # Make a new serializer to test with self.test_serializer = Serializer() serializers.serializer_registry['test'] = self.test_serializer # Instantiate the cassette to test with self.cassette = cassette.Cassette(TestCassette.cassette_name, 'test', record_mode='once') # Create a new object to serialize r = Response() r.status_code = 200 r.reason = 'OK' r.encoding = 'utf-8' r.headers = CaseInsensitiveDict({'Content-Type': decode('foo')}) r.url = 'http://example.com' util.add_urllib3_response( {'body': { 'string': decode('foo'), 'encoding': 'utf-8' }}, r, HTTPHeaderDict({'Content-Type': decode('foo')})) self.response = r # Create an associated request r = Request() r.method = 'GET' r.url = 'http://example.com' r.headers = {} r.data = {'key': 'value'} self.response.request = r.prepare() self.response.request.headers.update( {'User-Agent': 'betamax/test header'}) # Expected serialized cassette data. self.json = { 'request': { 'body': { 'encoding': 'utf-8', 'string': 'key=value', }, 'headers': { 'User-Agent': ['betamax/test header'], 'Content-Length': ['9'], 'Content-Type': ['application/x-www-form-urlencoded'], }, 'method': 'GET', 'uri': 'http://example.com/', }, 'response': { 'body': { 'string': decode('foo'), 'encoding': 'utf-8', }, 'headers': { 'Content-Type': [decode('foo')] }, 'status': { 'code': 200, 'message': 'OK' }, 'url': 'http://example.com', }, 'recorded_at': '2013-08-31T00:00:00', } self.date = datetime(2013, 8, 31) self.cassette.save_interaction(self.response, self.response.request) self.interaction = self.cassette.interactions[0]
def setUp(self): # Make a new serializer to test with self.test_serializer = Serializer() serializers.serializer_registry['test'] = self.test_serializer # Instantiate the cassette to test with self.cassette = cassette.Cassette( TestCassette.cassette_name, 'test', record_mode='once' ) # Create a new object to serialize r = Response() r.status_code = 200 r.reason = 'OK' r.encoding = 'utf-8' r.headers = CaseInsensitiveDict({'Content-Type': decode('foo')}) r.url = 'http://example.com' util.add_urllib3_response({ 'body': { 'string': decode('foo'), 'encoding': 'utf-8' } }, r, HTTPHeaderDict({'Content-Type': decode('foo')})) self.response = r # Create an associated request r = Request() r.method = 'GET' r.url = 'http://example.com' r.headers = {} r.data = {'key': 'value'} self.response.request = r.prepare() self.response.request.headers.update( {'User-Agent': 'betamax/test header'} ) # Expected serialized cassette data. self.json = { 'request': { 'body': { 'encoding': 'utf-8', 'string': 'key=value', }, 'headers': { 'User-Agent': ['betamax/test header'], 'Content-Length': ['9'], 'Content-Type': ['application/x-www-form-urlencoded'], }, 'method': 'GET', 'uri': 'http://example.com/', }, 'response': { 'body': { 'string': decode('foo'), 'encoding': 'utf-8', }, 'headers': {'Content-Type': [decode('foo')]}, 'status': {'code': 200, 'message': 'OK'}, 'url': 'http://example.com', }, 'recorded_at': '2013-08-31T00:00:00', } self.date = datetime(2013, 8, 31) self.cassette.save_interaction(self.response, self.response.request) self.interaction = self.cassette.interactions[0]