def setUp(self): self.cassette = cassette.Cassette( TestCassette.cassette_name, 'json', 'w+' ) r = Response() r.status_code = 200 r.encoding = 'utf-8' r.headers = CaseInsensitiveDict({'Content-Type': decode('foo')}) r.url = 'http://example.com' cassette.add_urllib3_response({ 'body': { 'string': decode('foo'), 'encoding': 'utf-8' } }, r) self.response = r 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'} ) self.json = { 'request': { 'body': '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, '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] self.interaction.recorded_at = self.date
def test_add_urllib3_response(self): r = Response() r.status_code = 200 r.headers = {} cassette.add_urllib3_response({ 'body': { 'string': decode('foo'), 'encoding': 'utf-8' } }, r) assert isinstance(r.raw, urllib3.response.HTTPResponse) assert r.content == b'foo' assert isinstance(r.raw._original_response, cassette.MockHTTPResponse)
def test_serialize_response(self): r = Response() r.status_code = 200 r.encoding = 'utf-8' r.headers = CaseInsensitiveDict() r.url = 'http://example.com' cassette.add_urllib3_response({ 'body': { 'string': decode('foo'), 'encoding': 'utf-8' } }, r) serialized = cassette.serialize_response(r, 'json') assert serialized is not None assert serialized != {} assert serialized['status_code'] == 200 assert serialized['body']['encoding'] == 'utf-8' assert serialized['body']['string'] == 'foo' assert serialized['headers'] == {} assert serialized['url'] == 'http://example.com'