Skip to content
Closed
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/go.imports.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import os
import uuid
from datetime import datetime
from http.server import BaseHTTPRequestHandler, HTTPServer


Expand All @@ -10,13 +11,19 @@ def get_linux_upload_value():
return load_one_minute


def get_linux_server_time():
return datetime.now().astimezone().isoformat()


def build_response(path):
if path == "/hello":
return 200, {"message": "hello"}, "application/json"
if path == "/healthz":
return 200, "ok", "text/plain; charset=utf-8"
if path == "/upload":
return 200, {"upload": get_linux_upload_value()}, "application/json"
if path == "/ime":
return 200, {"time": get_linux_server_time()}, "application/json"
return 404, None, None


Expand Down
19 changes: 19 additions & 0 deletions test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ def test_upload_endpoint(self, _):
self.assertEqual(body, {"upload": 1.23})
self.assertEqual(content_type, "application/json")

@patch("server.get_linux_server_time", return_value="2026-03-03T15:45:00+00:00")
def test_time_endpoint(self, _):
status, body, content_type = build_response("/ime")
self.assertEqual(status, 200)
self.assertEqual(body, {"time": "2026-03-03T15:45:00+00:00"})
self.assertEqual(content_type, "application/json")

def test_missing_endpoint(self):
status, body, content_type = build_response("/missing")
self.assertEqual(status, 404)
Expand Down Expand Up @@ -92,6 +99,18 @@ def test_upload_endpoint_returns_upload_value_and_request_id_header(self, _, __)
self.assertEqual(handler.wfile.buffer, b'{"upload": 4.56}')
self.assertTrue(handler.ended)

@patch("server.get_linux_server_time", return_value="2026-03-03T15:45:00+00:00")
@patch("server.generate_request_id", return_value="req-time")
def test_time_endpoint_returns_server_time_and_request_id_header(self, _, __):
handler = _FakeHandler("/ime")

Handler.do_GET(handler)

self.assertEqual(handler.status, 200)
self.assertIn(("X-Request-Id", "req-time"), handler.headers)
self.assertEqual(handler.wfile.buffer, b'{"time": "2026-03-03T15:45:00+00:00"}')
self.assertTrue(handler.ended)


if __name__ == "__main__":
unittest.main()