示例#1
0
def load_cassette(cassette_path, serializer):
    try:
        with open(cassette_path) as f:
            cassette_content = f.read()
    except IOError:
        return [], []
    return deserialize(cassette_content, serializer)
示例#2
0
def load_cassette(cassette_path: str,
                  serializer: ModuleType) -> Tuple[List, List]:
    try:
        with open(cassette_path) as f:
            cassette_content = f.read()
    except OSError:
        return [], []
    return deserialize(cassette_content, serializer)
示例#3
0
 def load_cassette(cls, cassette_path, serializer):
     try:
         with open(cassette_path) as f:
             cassette_content = f.read()
     except OSError:
         raise ValueError("Cassette not found.")
     for replacement, value in [(v, f"<{k.upper()}>")
                                for k, v in placeholders.items()]:
         cassette_content = cassette_content.replace(value, replacement)
     cassette = deserialize(cassette_content, serializer)
     return cassette
示例#4
0
 def load_cassette(cls, cassette_path, serializer):
     """Load the cassette."""
     try:
         with open(cassette_path) as f:
             cassette_content = f.read()
     except OSError:
         raise ValueError("Cassette not found.")
     for replacement, value in placeholders:
         cassette_content = cassette_content.replace(value, replacement)
     cassette = deserialize(cassette_content, serializer)
     return cassette
示例#5
0
def test_deserialize_old_json_cassette():
    with open('tests/fixtures/migration/old_cassette.json', 'r') as f:
        with pytest.raises(ValueError):
            deserialize(f.read(), jsonserializer)
示例#6
0
def test_deserialize_new_json_cassette():
    with open('tests/fixtures/migration/new_cassette.json', 'r') as f:
        deserialize(f.read(), jsonserializer)
示例#7
0
def test_deserialize_new_yaml_cassette():
    with open('tests/fixtures/migration/new_cassette.yaml', 'r') as f:
        deserialize(f.read(), yamlserializer)
示例#8
0
def test_deserialize_old_yaml_cassette():
    with open("tests/fixtures/migration/old_cassette.yaml", "r") as f:
        with pytest.raises(ValueError):
            deserialize(f.read(), yamlserializer)
示例#9
0
def test_deserialize_py2py3_yaml_cassette(tmpdir, req_body, expect):
    cfile = tmpdir.join("test_cassette.yaml")
    cfile.write(REQBODY_TEMPLATE.format(req_body=req_body))
    with open(str(cfile)) as f:
        (requests, responses) = deserialize(f.read(), yamlserializer)
    assert requests[0].body == expect
示例#10
0
def test_deserialize_new_json_cassette():
    with open("tests/fixtures/migration/new_cassette.json", "r") as f:
        deserialize(f.read(), jsonserializer)
示例#11
0
def test_deserialize_new_yaml_cassette():
    with open("tests/fixtures/migration/new_cassette.yaml", "r") as f:
        deserialize(f.read(), yamlserializer)
示例#12
0
def test_deserialize_py2py3_yaml_cassette(tmpdir, req_body, expect):
    cfile = tmpdir.join('test_cassette.yaml')
    cfile.write(REQBODY_TEMPLATE.format(req_body=req_body))
    with open(str(cfile)) as f:
        (requests, responses) = deserialize(f.read(), yamlserializer)
    assert requests[0].body == expect
示例#13
0
def test_deserialize_old_json_cassette():
    with open('tests/fixtures/migration/old_cassette.json', 'r') as f:
        with pytest.raises(ValueError):
            deserialize(f.read(), jsonserializer)
 def _extract_vcr_object(file_path):
     with open(file_path, "rb") as cassette:
         return VcrObject(file_path,
                          deserialize(cassette.read(), yamlserializer))