Example #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)
Example #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)
Example #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
Example #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
Example #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)
Example #6
0
def test_deserialize_new_json_cassette():
    with open('tests/fixtures/migration/new_cassette.json', 'r') as f:
        deserialize(f.read(), jsonserializer)
Example #7
0
def test_deserialize_new_yaml_cassette():
    with open('tests/fixtures/migration/new_cassette.yaml', 'r') as f:
        deserialize(f.read(), yamlserializer)
Example #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)
Example #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
Example #10
0
def test_deserialize_new_json_cassette():
    with open("tests/fixtures/migration/new_cassette.json", "r") as f:
        deserialize(f.read(), jsonserializer)
Example #11
0
def test_deserialize_new_yaml_cassette():
    with open("tests/fixtures/migration/new_cassette.yaml", "r") as f:
        deserialize(f.read(), yamlserializer)
Example #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
Example #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))