async def test_override_headers(client, deployment_schema, response_klass, async_mock): extra_headers = {"custom-serialization": "application/x-avro-json"} client = SchemaRegistryClient(url=os.getenv("SCHEMA_REGISTRY_URL"), extra_headers=extra_headers) assert (client.prepare_headers().get("custom-serialization") == "application/x-avro-json") subject = "test" override_header = {"custom-serialization": "application/avro"} mock = async_mock( requests.sessions.Session, "request", returned_value=response_klass(200, content={"id": 1}), ) with mock: await client.register(subject, deployment_schema, headers=override_header) prepare_headers = client.prepare_headers(body="1") prepare_headers["custom-serialization"] = "application/avro" mock.assert_called_with(headers=prepare_headers)
def test_override_headers(client, deployment_schema, mocker, response_klass): extra_headers = {"custom-serialization": "application/x-avro-json"} client = SchemaRegistryClient("https://127.0.0.1:65534", extra_headers=extra_headers) assert (client.prepare_headers().get("custom-serialization") == "application/x-avro-json") subject = "test" override_header = {"custom-serialization": "application/avro"} request_patch = mocker.patch.object( requests.sessions.Session, "request", return_value=response_klass(200, content={"id": 1}), ) client.register(subject, deployment_schema, headers=override_header) prepare_headers = client.prepare_headers(body="1") prepare_headers["custom-serialization"] = "application/avro" request_patch.assert_called_once_with("POST", mocker.ANY, headers=prepare_headers, json=mocker.ANY)
async def test_override_headers(client, deployment_schema, response_klass, async_mock): extra_headers = {"custom-serialization": utils.HEADER_AVRO_JSON} client = SchemaRegistryClient(url=os.getenv("SCHEMA_REGISTRY_URL"), extra_headers=extra_headers) assert client.prepare_headers().get( "custom-serialization") == utils.HEADER_AVRO_JSON subject = "test" override_header = {"custom-serialization": utils.HEADER_AVRO} mock = async_mock(httpx.AsyncClient, "request", returned_value=response_klass(200, content={"id": 1})) with mock: await client.register(subject, deployment_schema, headers=override_header) prepare_headers = client.prepare_headers(body="1") prepare_headers["custom-serialization"] = utils.HEADER_AVRO mock.assert_called_with(headers=prepare_headers)
def test_override_headers(client, deployment_schema, mocker): extra_headers = {"custom-serialization": "application/x-avro-json"} client = SchemaRegistryClient( "https://127.0.0.1:65534", extra_headers=extra_headers ) assert ( client.prepare_headers().get("custom-serialization") == "application/x-avro-json" ) class Response: def __init__(self, status_code, content=None): self.status_code = status_code if content is None: content = {} self.content = content def json(self): return self.content subject = "test" override_header = {"custom-serialization": "application/avro"} request_patch = mocker.patch.object( requests.sessions.Session, "request", return_value=Response(200, content={"id": 1}), ) client.register(subject, deployment_schema, headers=override_header) prepare_headers = client.prepare_headers(body="1") prepare_headers["custom-serialization"] = "application/avro" request_patch.assert_called_once_with( "POST", mocker.ANY, headers=prepare_headers, json=mocker.ANY )