mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-10 01:25:34 +00:00
Added migration script for old cassettes
This commit is contained in:
31
tests/fixtures/migration/new_cassette.json
vendored
Normal file
31
tests/fixtures/migration/new_cassette.json
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
[
|
||||
{
|
||||
"request": {
|
||||
"body": null,
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"Accept-Encoding": "gzip, deflate, compress",
|
||||
"Accept": "*/*",
|
||||
"User-Agent": "python-requests/2.2.1 CPython/2.6.1 Darwin/10.8.0"
|
||||
},
|
||||
"uri" : "http://httpbin.org:80/ip"
|
||||
},
|
||||
"response": {
|
||||
"status": {
|
||||
"message": "OK",
|
||||
"code": 200
|
||||
},
|
||||
"headers": [
|
||||
"Access-Control-Allow-Origin: *\r\n",
|
||||
"Content-Type: application/json\r\n",
|
||||
"Date: Mon, 21 Apr 2014 23:13:40 GMT\r\n",
|
||||
"Server: gunicorn/0.17.4\r\n",
|
||||
"Content-Length: 32\r\n",
|
||||
"Connection: keep-alive\r\n"
|
||||
],
|
||||
"body": {
|
||||
"string": "{\n \"origin\": \"217.122.164.194\"\n}"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
15
tests/fixtures/migration/new_cassette.yaml
vendored
Normal file
15
tests/fixtures/migration/new_cassette.yaml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
- request: !!python/object:vcr.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, '*/*']
|
||||
method: GET
|
||||
uri: http://httpbin.org:80/ip
|
||||
response:
|
||||
body: {string: !!python/unicode "{\n \"origin\": \"217.122.164.194\"\n}"}
|
||||
headers: [!!python/unicode "Access-Control-Allow-Origin: *\r\n", !!python/unicode "Content-Type:
|
||||
application/json\r\n", !!python/unicode "Date: Mon, 21 Apr 2014 23:06:09 GMT\r\n",
|
||||
!!python/unicode "Server: gunicorn/0.17.4\r\n", !!python/unicode "Content-Length:
|
||||
32\r\n", !!python/unicode "Connection: keep-alive\r\n"]
|
||||
status: {code: 200, message: OK}
|
||||
1
tests/fixtures/migration/not_cassette.txt
vendored
Normal file
1
tests/fixtures/migration/not_cassette.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
This is not a cassette
|
||||
34
tests/fixtures/migration/old_cassette.json
vendored
Normal file
34
tests/fixtures/migration/old_cassette.json
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
[
|
||||
{
|
||||
"request": {
|
||||
"body": null,
|
||||
"protocol": "http",
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"Accept-Encoding": "gzip, deflate, compress",
|
||||
"Accept": "*/*",
|
||||
"User-Agent": "python-requests/2.2.1 CPython/2.6.1 Darwin/10.8.0"
|
||||
},
|
||||
"host": "httpbin.org",
|
||||
"path": "/ip",
|
||||
"port": 80
|
||||
},
|
||||
"response": {
|
||||
"status": {
|
||||
"message": "OK",
|
||||
"code": 200
|
||||
},
|
||||
"headers": [
|
||||
"Access-Control-Allow-Origin: *\r\n",
|
||||
"Content-Type: application/json\r\n",
|
||||
"Date: Mon, 21 Apr 2014 23:13:40 GMT\r\n",
|
||||
"Server: gunicorn/0.17.4\r\n",
|
||||
"Content-Length: 32\r\n",
|
||||
"Connection: keep-alive\r\n"
|
||||
],
|
||||
"body": {
|
||||
"string": "{\n \"origin\": \"217.122.164.194\"\n}"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
18
tests/fixtures/migration/old_cassette.yaml
vendored
Normal file
18
tests/fixtures/migration/old_cassette.yaml
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
- request: !!python/object:vcr.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, '*/*']
|
||||
host: httpbin.org
|
||||
method: GET
|
||||
path: /ip
|
||||
port: 80
|
||||
protocol: http
|
||||
response:
|
||||
body: {string: !!python/unicode "{\n \"origin\": \"217.122.164.194\"\n}"}
|
||||
headers: [!!python/unicode "Access-Control-Allow-Origin: *\r\n", !!python/unicode "Content-Type:
|
||||
application/json\r\n", !!python/unicode "Date: Mon, 21 Apr 2014 23:06:09 GMT\r\n",
|
||||
!!python/unicode "Server: gunicorn/0.17.4\r\n", !!python/unicode "Content-Length:
|
||||
32\r\n", !!python/unicode "Connection: keep-alive\r\n"]
|
||||
status: {code: 200, message: OK}
|
||||
36
tests/unit/test_migration.py
Normal file
36
tests/unit/test_migration.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import filecmp
|
||||
import json
|
||||
import shutil
|
||||
|
||||
import vcr.migration
|
||||
|
||||
|
||||
def test_try_migrate_with_json(tmpdir):
|
||||
cassette = tmpdir.join('cassette').strpath
|
||||
shutil.copy('tests/fixtures/migration/old_cassette.json', cassette)
|
||||
assert vcr.migration.try_migrate(cassette)
|
||||
with open('tests/fixtures/migration/new_cassette.json', 'r') as f:
|
||||
expected_json = json.load(f)
|
||||
with open(cassette, 'r') as f:
|
||||
actual_json = json.load(f)
|
||||
assert actual_json == expected_json
|
||||
|
||||
|
||||
def test_try_migrate_with_yaml(tmpdir):
|
||||
cassette = tmpdir.join('cassette').strpath
|
||||
shutil.copy('tests/fixtures/migration/old_cassette.yaml', cassette)
|
||||
assert vcr.migration.try_migrate(cassette)
|
||||
assert filecmp.cmp(cassette, 'tests/fixtures/migration/new_cassette.yaml')
|
||||
|
||||
|
||||
def test_try_migrate_with_invalid_or_new_cassettes(tmpdir):
|
||||
cassette = tmpdir.join('cassette').strpath
|
||||
files = [
|
||||
'tests/fixtures/migration/not_cassette.txt',
|
||||
'tests/fixtures/migration/new_cassette.yaml',
|
||||
'tests/fixtures/migration/new_cassette.json',
|
||||
]
|
||||
for file_path in files:
|
||||
shutil.copy(file_path, cassette)
|
||||
assert not vcr.migration.try_migrate(cassette)
|
||||
assert filecmp.cmp(cassette, file_path) # shold not change file
|
||||
Reference in New Issue
Block a user