From f4b8dd70a9b6bebebcc9d81e309a49f1acd6e583 Mon Sep 17 00:00:00 2001 From: Scott Huang Date: Tue, 10 Sep 2024 23:30:45 +0800 Subject: [PATCH] Add tests --- tests/dbt/cloud/test_http.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/dbt/cloud/test_http.py diff --git a/tests/dbt/cloud/test_http.py b/tests/dbt/cloud/test_http.py new file mode 100644 index 00000000..484436ba --- /dev/null +++ b/tests/dbt/cloud/test_http.py @@ -0,0 +1,25 @@ +import json + +import httpx +from testcontainers.general import DockerContainer + +from metaphor.common.logger import debug_files +from metaphor.dbt.cloud.http import LogTransport + + +def test_http_client(): + http_client = httpx.Client( + transport=LogTransport(httpx.HTTPTransport()), + ) + + with DockerContainer("hashicorp/http-echo").with_exposed_ports(5678).with_env( + "ECHO_TEXT", json.dumps({}) + ) as container: + port = container.get_exposed_port(5678) + host = container.get_container_host_ip() + + url = f"http://{host}:{port}" + http_client.post(url, content=json.dumps({"foo": "bar"})) + + # Should log two json file + assert len(debug_files) == 2