Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tests/test_trace_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,26 @@ def test_constructor_trims_the_base_url_application_and_key(self):
self.assertTrue(request["user_agent"].endswith("(MyGame)"), request["user_agent"])
client.close()

def test_a_base_url_with_a_path_keeps_it_in_front_of_the_endpoint(self):
# A trace server behind a reverse proxy lives under a path prefix.
client = TraceClient(self.base_url + "/trace//", "MyGame", "1.2.3", key="k")
client.report("startup")
self.assertTrue(self.capture.arrived.wait(5), "the report should reach the server")
client.close()
self.assertEqual("/trace/api/metrics", self.capture.requests[0]["path"],
"the prefix is kept and every trailing slash is dropped before /api/metrics")

def test_non_ascii_names_and_tags_arrive_intact_as_utf8_json(self):
client = TraceClient(self.base_url, "Spiel", "1.2.3", key="k")
client.report("défi", tags={"ville": "Zürich", "emoji": "\U0001F3B2"})
self.assertTrue(self.capture.arrived.wait(5), "the report should reach the server")
client.close()
request = self.capture.requests[0]
self.assertEqual("application/json; charset=utf-8", request["content_type"])
self.assertEqual({"application": "Spiel", "name": "défi",
"tags": {"ville": "Zürich", "emoji": "\U0001F3B2", "version": "1.2.3"}},
json.loads(request["body"]), "text the program reports is what the server reads")

def test_report_carries_value_and_tags_when_given(self):
client = TraceClient(self.base_url, "MyGame", "1.2.3", key="k")
client.report("world-load", 2.5, {"seed": "42", "size": 'the "big" one'})
Expand Down
Loading