예제 #1
0
    def save_cassette(cls, cassette_path, cassette_dict, serializer):
        for cassette_request, cassette_response in zip(cassette_dict["requests"], cassette_dict["responses"]):
            if not cls.record_errors and get_in(["status", "code"], cassette_response) >= HTTPStatus.BAD_REQUEST:
                return

            cassette_request.uri = cassette_request.uri.replace(cls.base_uri, cls.mock_url)
            if cassette_request.body and xml_in_headers(cassette_request):
                cassette_request.body = strip_soap_namespaces_from_body(cassette_request.body)

            if any("xml" in content_type for content_type in cassette_response["headers"].get('Content-Type', [])):
                cassette_response["body"]["string"] = replace_locations_in_xml(cassette_response["body"]["string"])
        FilesystemPersister.save_cassette(cassette_path, cassette_dict, serializer)
예제 #2
0
    def load_cassette(cls, cassette_path, serializer):
        if os.path.exists(
                cassette_path) and vcr_mode == 'all' and os.path.basename(
                    cassette_path) not in cls.CASSETTES_TO_NEVER_OVERWRITE:
            os.remove(cassette_path)

        return FilesystemPersister.load_cassette(cassette_path, serializer)
예제 #3
0
    def save_cassette(cassette_path, cassette_dict, serializer):
        if os.path.basename(
                cassette_path
        ) in CassetteOverwritingPersister.CASSETTES_TO_NEVER_OVERWRITE:
            return

        return FilesystemPersister.save_cassette(cassette_path, cassette_dict,
                                                 serializer)
예제 #4
0
 def save_cassette(cassette_path, cassette_dict, serializer):
     cassette_path += ".test"
     FilesystemPersister.save_cassette(cassette_path, cassette_dict, serializer)
예제 #5
0
 def load_cassette(cassette_path, serializer):
     cassette_path += ".test"
     return FilesystemPersister.load_cassette(cassette_path, serializer)
예제 #6
0
def test_load_cassette_with_invalid_cassettes(cassette_path, serializer):
    with pytest.raises(Exception) as excinfo:
        FilesystemPersister.load_cassette(cassette_path, serializer)
    assert "run the migration script" not in excinfo.exconly()
예제 #7
0
def test_load_cassette_with_old_cassettes(cassette_path, serializer):
    with pytest.raises(ValueError) as excinfo:
        FilesystemPersister.load_cassette(cassette_path, serializer)
    assert "run the migration script" in excinfo.exconly()
예제 #8
0
 def save_cassette(cassette_path, cassette_dict, serializer):
     cassette_path += '.test'
     FilesystemPersister.save_cassette(cassette_path, cassette_dict,
                                       serializer)
예제 #9
0
 def load_cassette(cassette_path, serializer):
     cassette_path += '.test'
     return FilesystemPersister.load_cassette(cassette_path, serializer)