"code": 200
},
"headers": {
- "Access-Control-Allow-Origin": ["*"],
- "Content-Type": ["application/json"],
- "Date": ["Mon, 21 Apr 2014 23:13:40 GMT"],
- "Server": ["gunicorn/0.17.4"],
- "Content-Length": ["32"],
- "Connection": ["keep-alive"]
+ "access-control-allow-origin": ["*"],
+ "content-type": ["application/json"],
+ "date": ["Mon, 21 Apr 2014 23:13:40 GMT"],
+ "server": ["gunicorn/0.17.4"],
+ "content-length": ["32"],
+ "connection": ["keep-alive"]
},
"body": {
"string": "{\n \"origin\": \"217.122.164.194\"\n}"
response:
body: {string: !!python/unicode "{\n \"origin\": \"217.122.164.194\"\n}"}
headers:
- Access-Control-Allow-Origin: ['*']
- Content-Type: [application/json]
- Date: ['Mon, 21 Apr 2014 23:06:09 GMT']
- Server: [gunicorn/0.17.4]
- Content-Length: ['32']
- Connection: [keep-alive]
+ access-control-allow-origin: ['*']
+ content-type: [application/json]
+ date: ['Mon, 21 Apr 2014 23:06:09 GMT']
+ server: [gunicorn/0.17.4]
+ content-length: ['32']
+ connection: [keep-alive]
status: {code: 200, message: OK}
from .serializers import compat, yamlserializer
from . import request
+from stubs.compat import get_httpmessage
# Use the libYAML versions if possible
try:
data = json.load(in_fp)
for item in data:
req = item['request']
+ res = item['response']
uri = dict((k, req.pop(k)) for k in PARTS)
req['uri'] = build_uri(**uri)
# convert headers to dict of lists
headers = req['headers']
for k in headers:
headers[k] = [headers[k]]
+ response_headers = {}
+ for k, v in get_httpmessage(b"".join(res['headers'])).items():
+ response_headers.setdefault(k, [])
+ response_headers[k].append(v)
+ res['headers'] = response_headers
+
+
json.dump(data, out_fp, indent=4)
def migrate_yml(in_fp, out_fp):
(requests, responses) = _old_deserialize(in_fp.read())
- for req in requests:
+ for req, res in zip(requests, responses):
if not isinstance(req, request.Request):
raise Exception("already migrated")
else:
req.headers = {}
for key, value in headers:
req.add_header(key, value)
+ response_headers = {}
+ for k, v in get_httpmessage(b"".join(res['headers'])).items():
+ response_headers.setdefault(k, [])
+ response_headers[k].append(v)
+ res['headers'] = response_headers
data = yamlserializer.serialize({
"requests": requests,
def try_migrate(path):
try: # try to migrate as json
migrate(path, migrate_json)
- except Exception: # probably the file is not a json
+ except Exception as e: # probably the file is not a json
try: # let's try to migrate as yaml
migrate(path, migrate_yml)
except Exception: # oops probably the file is not a cassette