Example #1
0
def test_serialize_empty_request():
    request = Request(method="POST",
                      uri="http://localhost/",
                      body="",
                      headers={})

    serialize({"requests": [request], "responses": [{}]}, jsonserializer)
Example #2
0
def test_serialize_json_request():
    request = Request(method="POST",
                      uri="http://localhost/",
                      body="{'hello': 'world'}",
                      headers={})

    serialize({"requests": [request], "responses": [{}]}, jsonserializer)
Example #3
0
def test_serialize_binary_request():
    msg = "Does this HTTP interaction contain binary data?"

    request = Request(method="POST", uri="http://localhost/", body=b"\x8c", headers={})

    try:
        serialize({"requests": [request], "responses": [{}]}, jsonserializer)
    except (UnicodeDecodeError, TypeError) as exc:
        assert msg in str(exc)
Example #4
0
def test_serialize_empty_request():
    request = Request(
        method='POST',
        uri='http://localhost/',
        body='',
        headers={},
    )

    serialize({'requests': [request], 'responses': [{}]}, jsonserializer)
Example #5
0
def test_serialize_json_request():
    request = Request(
        method='POST',
        uri='http://localhost/',
        body="{'hello': 'world'}",
        headers={},
    )

    serialize({'requests': [request], 'responses': [{}]}, jsonserializer)
Example #6
0
def test_serialize_empty_request():
    request = Request(
        method='POST',
        uri='http://localhost/',
        body='',
        headers={},
    )

    serialize(
        {'requests': [request], 'responses': [{}]},
        jsonserializer
    )
Example #7
0
def test_serialize_json_request():
    request = Request(
        method='POST',
        uri='http://localhost/',
        body="{'hello': 'world'}",
        headers={},
    )

    serialize(
        {'requests': [request], 'responses': [{}]},
        jsonserializer
    )
Example #8
0
def test_serialize_binary_request():
    msg = "Does this HTTP interaction contain binary data?"

    request = Request(
        method='POST',
        uri='http://localhost/',
        body=b'\x8c',
        headers={},
    )

    try:
        serialize({'requests': [request], 'responses': [{}]}, jsonserializer)
    except (UnicodeDecodeError, TypeError) as exc:
        assert msg in str(exc)
Example #9
0
def test_serialize_binary_request():
    msg = "Does this HTTP interaction contain binary data?"

    request = Request(
        method='POST',
        uri='http://localhost/',
        body=b'\x8c',
        headers={},
    )

    try:
        serialize(
            {'requests': [request], 'responses': [{}]},
            jsonserializer
        )
    except (UnicodeDecodeError, TypeError) as exc:
        assert msg in str(exc)
Example #10
0
 def save_cassette(cassette_path, cassette_dict, serializer):
     data = serialize(cassette_dict, serializer)
     for replacement, value in [(f"<{k.upper()}>", v)
                                for k, v in placeholders.items()]:
         data = data.replace(value, replacement)
     dirname, filename = os.path.split(cassette_path)
     if dirname and not os.path.exists(dirname):
         os.makedirs(dirname)
     with open(cassette_path, "w") as f:
         f.write(data)
Example #11
0
 def save_cassette(cassette_path, cassette_dict, serializer):
     """Save the cassette."""
     data = serialize(cassette_dict, serializer)
     for replacement, value in placeholders:
         data = data.replace(value, replacement)
     dirname, filename = os.path.split(cassette_path)
     if dirname and not os.path.exists(dirname):
         os.makedirs(dirname)
     with open(cassette_path, "w") as f:
         f.write(data)
    def _output_response(self, vcr_object):
        self.print("Outputing file: {}".format(vcr_object.file_path))

        with open(vcr_object.file_path, "w+", encoding="utf-8") as output:
            output.write(serialize(vcr_object.to_dict(), yamlserializer))