def match(self, request, recorded_request):
        recorded_request = deserialize_prepared_request(recorded_request)

        request_body = _parse_request_body(request)
        recorded_body = _parse_request_body(recorded_request)

        return recorded_body == request_body
Esempio n. 2
0
 def deserialize(self):
     """Turn a serialized interaction into a Response."""
     r = util.deserialize_response(self.json['response'])
     r.request = util.deserialize_prepared_request(self.json['request'])
     extract_cookies_to_jar(r.cookies, r.request, r.raw)
     self.recorded_at = datetime.strptime(self.json['recorded_at'],
                                          '%Y-%m-%dT%H:%M:%S')
     self.recorded_response = r
Esempio n. 3
0
 def deserialize(self):
     """Turn a serialized interaction into a Response."""
     r = util.deserialize_response(self.json['response'])
     r.request = util.deserialize_prepared_request(self.json['request'])
     extract_cookies_to_jar(r.cookies, r.request, r.raw)
     self.recorded_at = datetime.strptime(
         self.json['recorded_at'], '%Y-%m-%dT%H:%M:%S'
     )
     self.recorded_response = r
    def match(self, request, recorded_request):
        recorded_request = deserialize_prepared_request(recorded_request)

        request_body = request.body or b""
        recorded_body = recorded_request.body or b""

        # Don't check body for oauth workflow
        if request.url.endswith("api/v1/access_token"):
            return True

        return recorded_body == request_body
Esempio n. 5
0
    def match(self, request, recorded_request):
        recorded_request = util.deserialize_prepared_request(recorded_request)

        request_body = b''
        if request.body:
            request_body = util.coerce_content(request.body)

        recorded_body = b''
        if recorded_request.body:
            recorded_body = util.coerce_content(recorded_request.body)

        return recorded_body == request_body
Esempio n. 6
0
    def match(self, request, recorded_request):
        recorded_request = deserialize_prepared_request(recorded_request)

        if request.body:
            if isinstance(recorded_request.body, type(request.body)):
                request_body = request.body
            else:
                request_body = request.body.encode('utf-8')
        else:
            request_body = b''

        return recorded_request.body == request_body
Esempio n. 7
0
 def test_deserialize_prepared_request(self):
     s = {
         'body': 'key=value',
         'headers': {
             'User-Agent': 'betamax/test header',
         },
         'method': 'GET',
         'uri': 'http://example.com/',
     }
     p = util.deserialize_prepared_request(s)
     assert p.body == 'key=value'
     assert p.headers == CaseInsensitiveDict(
         {'User-Agent': 'betamax/test header'})
     assert p.method == 'GET'
     assert p.url == 'http://example.com/'
Esempio n. 8
0
 def test_deserialize_prepared_request(self):
     s = {
         'body': 'key=value',
         'headers': {
             'User-Agent': 'betamax/test header',
         },
         'method': 'GET',
         'uri': 'http://example.com/',
     }
     p = util.deserialize_prepared_request(s)
     assert p.body == 'key=value'
     assert p.headers == CaseInsensitiveDict(
         {'User-Agent': 'betamax/test header'}
     )
     assert p.method == 'GET'
     assert p.url == 'http://example.com/'
Esempio n. 9
0
    def match(self, request, recorded_request):
        recorded_request = util.deserialize_prepared_request(recorded_request)

        request_body = b''
        if request.body:
            request_body = util.coerce_content(request.body)

        recorded_body = b''
        if recorded_request.body:
            recorded_body = util.coerce_content(recorded_request.body)

        if recorded_body != request_body:
            diff = difflib.context_diff(recorded_body, request_body)
            log.debug('** Cassette Differences: **\n' + '\n'.join(diff))

        return recorded_body == request_body
Esempio n. 10
0
 def deserialize(self):
     """Turn a serialized interaction into a Response."""
     r = util.deserialize_response(self.data['response'])
     r.request = util.deserialize_prepared_request(self.data['request'])
     extract_cookies_to_jar(r.cookies, r.request, r.raw)
     return r
Esempio n. 11
0
 def deserialize(self):
     """Turn a serialized interaction into a Response."""
     r = util.deserialize_response(self.json['response'])
     r.request = util.deserialize_prepared_request(self.json['request'])
     extract_cookies_to_jar(r.cookies, r.request, r.raw)
     return r