def test_serialize_empty_request(): request = Request(method="POST", uri="http://localhost/", body="", headers={}) serialize({"requests": [request], "responses": [{}]}, jsonserializer)
def test_serialize_json_request(): request = Request(method="POST", uri="http://localhost/", body="{'hello': 'world'}", headers={}) serialize({"requests": [request], "responses": [{}]}, jsonserializer)
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)
def test_serialize_empty_request(): request = Request( method='POST', uri='http://localhost/', body='', headers={}, ) serialize({'requests': [request], 'responses': [{}]}, jsonserializer)
def test_serialize_json_request(): request = Request( method='POST', uri='http://localhost/', body="{'hello': 'world'}", headers={}, ) serialize({'requests': [request], 'responses': [{}]}, jsonserializer)
def test_serialize_empty_request(): request = Request( method='POST', uri='http://localhost/', body='', headers={}, ) serialize( {'requests': [request], 'responses': [{}]}, jsonserializer )
def test_serialize_json_request(): request = Request( method='POST', uri='http://localhost/', body="{'hello': 'world'}", headers={}, ) serialize( {'requests': [request], 'responses': [{}]}, jsonserializer )
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)
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)
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)
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))