mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-08 16:53:23 +00:00
Replaced yaml dump of Request object with plain dict dump
This commit is contained in:
8
tests/fixtures/migration/new_cassette.yaml
vendored
8
tests/fixtures/migration/new_cassette.yaml
vendored
@@ -1,9 +1,7 @@
|
||||
- request: !!python/object:vcr.request.Request
|
||||
- request:
|
||||
body: null
|
||||
headers: !!python/object/apply:__builtin__.frozenset
|
||||
- - !!python/tuple [Accept-Encoding, 'gzip, deflate, compress']
|
||||
- !!python/tuple [User-Agent, python-requests/2.2.1 CPython/2.6.1 Darwin/10.8.0]
|
||||
- !!python/tuple [Accept, '*/*']
|
||||
headers: {Accept: '*/*', Accept-Encoding: 'gzip, deflate, compress', User-Agent: python-requests/2.2.1
|
||||
CPython/2.6.1 Darwin/10.8.0}
|
||||
method: GET
|
||||
uri: http://httpbin.org:80/ip
|
||||
response:
|
||||
|
||||
14
tests/fixtures/wild/domain_redirect.yaml
vendored
14
tests/fixtures/wild/domain_redirect.yaml
vendored
@@ -1,9 +1,6 @@
|
||||
- request: !!python/object:vcr.request.Request
|
||||
- request:
|
||||
body: null
|
||||
headers: !!python/object/apply:__builtin__.frozenset
|
||||
- - !!python/tuple [Accept-Encoding, 'gzip, deflate, compress']
|
||||
- !!python/tuple [User-Agent, vcrpy-test]
|
||||
- !!python/tuple [Accept, '*/*']
|
||||
headers: {Accept: '*/*', Accept-Encoding: 'gzip, deflate, compress', User-Agent: vcrpy-test}
|
||||
method: GET
|
||||
uri: http://seomoz.org:80/
|
||||
response:
|
||||
@@ -11,12 +8,9 @@
|
||||
headers: ["Location: http://moz.com/\r\n", "Server: BigIP\r\n", "Connection: Keep-Alive\r\n",
|
||||
"Content-Length: 0\r\n"]
|
||||
status: {code: 301, message: Moved Permanently}
|
||||
- request: !!python/object:vcr.request.Request
|
||||
- request:
|
||||
body: null
|
||||
headers: !!python/object/apply:__builtin__.frozenset
|
||||
- - !!python/tuple [Accept-Encoding, 'gzip, deflate, compress']
|
||||
- !!python/tuple [User-Agent, vcrpy-test]
|
||||
- !!python/tuple [Accept, '*/*']
|
||||
headers: {Accept: '*/*', Accept-Encoding: 'gzip, deflate, compress', User-Agent: vcrpy-test}
|
||||
method: GET
|
||||
uri: http://moz.com:80/
|
||||
response:
|
||||
|
||||
@@ -8,7 +8,8 @@ from vcr.errors import UnhandledHTTPRequestError
|
||||
def test_cassette_load(tmpdir):
|
||||
a_file = tmpdir.join('test_cassette.yml')
|
||||
a_file.write(yaml.dump([
|
||||
{'request': 'foo', 'response': 'bar'}
|
||||
{'request': {'body': '', 'uri': 'foo', 'method': 'GET', 'headers': {}},
|
||||
'response': 'bar'}
|
||||
]))
|
||||
a_cassette = Cassette.load(str(a_file))
|
||||
assert len(a_cassette) == 1
|
||||
|
||||
@@ -71,7 +71,7 @@ class Request(object):
|
||||
'method': self.method,
|
||||
'uri': self.uri,
|
||||
'body': self.body,
|
||||
'headers': self.headers,
|
||||
'headers': dict(self.headers),
|
||||
}
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
from vcr.request import Request
|
||||
from . import compat
|
||||
|
||||
# Use the libYAML versions if possible
|
||||
@@ -21,25 +22,9 @@ Deserializing: string (yaml converts from utf-8) -> bytestring
|
||||
"""
|
||||
|
||||
|
||||
def _restore_frozenset():
|
||||
"""
|
||||
Restore __builtin__.frozenset for cassettes serialized in python2 but
|
||||
deserialized in python3 and builtins.frozenset for cassettes serialized
|
||||
in python3 and deserialized in python2
|
||||
"""
|
||||
|
||||
if '__builtin__' not in sys.modules:
|
||||
import builtins
|
||||
sys.modules['__builtin__'] = builtins
|
||||
|
||||
if 'builtins' not in sys.modules:
|
||||
sys.modules['builtins'] = sys.modules['__builtin__']
|
||||
|
||||
|
||||
def deserialize(cassette_string):
|
||||
_restore_frozenset()
|
||||
data = yaml.load(cassette_string, Loader=Loader)
|
||||
requests = [r['request'] for r in data]
|
||||
requests = [Request._from_dict(r['request']) for r in data]
|
||||
responses = [r['response'] for r in data]
|
||||
responses = [compat.convert_to_bytes(r['response']) for r in data]
|
||||
return requests, responses
|
||||
@@ -47,7 +32,7 @@ def deserialize(cassette_string):
|
||||
|
||||
def serialize(cassette_dict):
|
||||
data = ([{
|
||||
'request': request,
|
||||
'request': request._to_dict(),
|
||||
'response': response,
|
||||
} for request, response in zip(
|
||||
cassette_dict['requests'],
|
||||
|
||||
Reference in New Issue
Block a user