From e8fe116ef4a996a8281bf0b43bed5e9d39c766c8 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Thu, 1 Oct 2026 16:01:20 +0000 Subject: Add /version endpoint, extract shared python test helper. * .gitignore: Add __pycache__. * src/lib.rs (app): Add /version route. (VersionInfo, version): New struct and handler, returning name, short_name, version, release, date, and git as a JSON record. * build.rs: New file. Embeds GN4_GIT_HASH and GN4_COMMIT_DATE via cargo:rustc-env, read from git rev-parse and git show of HEAD. * Cargo.toml (dependencies): Add serde with derive feature. [dev-dependencies]: Add serde_json. * tests/version.rs: New file. * test/python/server_test_case.py: New file. ServerTestCase, wait_for_port, BINARY, HOST, PORT moved here from test/python/test_hello_world.py. * test/python/test_hello_world.py: Use server_test_case.ServerTestCase instead of duplicating setUpClass and tearDownClass. * test/python/test_version.py: New file. * guix.scm: Add (gnu packages version-control) to use-modules. (genenetwork4-git)[native-inputs]: Add git-minimal. (genenetwork4-git)[arguments]<#:phases>[python-rest-test]: Run test/python with python3 -m unittest discover instead of invoking test_hello_world.py directly, so test_version.py also runs. --- test/python/test_version.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/python/test_version.py (limited to 'test/python/test_version.py') diff --git a/test/python/test_version.py b/test/python/test_version.py new file mode 100644 index 0000000..2fb46e9 --- /dev/null +++ b/test/python/test_version.py @@ -0,0 +1,32 @@ +"""Mirrors tests/version.rs.""" + +import http.client +import json +import unittest + +from server_test_case import HOST, PORT, ServerTestCase + + +class VersionTest(ServerTestCase): + def test_version_returns_ok_with_json_record(self): + conn = http.client.HTTPConnection(HOST, int(PORT), timeout=5) + try: + conn.request("GET", "/version") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 200) + + record = json.loads(body) + self.assertEqual(record["name"], "GeneNetwork4") + self.assertEqual(record["short_name"], "GN4AI") + self.assertEqual(record["version"], 4.0) + self.assertEqual(record["release"], 1) + # date and git are set at build time (see build.rs); just check shape. + self.assertEqual(len(record["date"]), 8) + self.assertTrue(record["git"]) + + +if __name__ == "__main__": + unittest.main() -- cgit 1.4.1