diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-10-03 11:39:09 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-10-03 11:39:09 +0000 |
| commit | 5f1e5c56370cd54a84ab8717179d3f5a37440b1e (patch) | |
| tree | 65a95de6e3a475211c497e44938fcc4739e436da /test/python | |
| parent | eb18351880af6eb978103eb902855f668206dbec (diff) | |
| download | genenetwork4-5f1e5c56370cd54a84ab8717179d3f5a37440b1e.tar.gz | |
Add /species endpoint backed by MariaDB.
* Cargo.toml (dependencies): Add mysql, default-features = false, features minimal-rust and derive (minimal pulls in flate2/zlib, which fails to compile here; minimal-rust uses flate2's pure-Rust backend instead). * Cargo.lock: Regenerate. Picks up mysql and its roughly 100 transitive dependencies; also bumps libc to 0.2.190 and tokio to 1.53.2 from re-resolution. * src/db.rs: New file. sql_uri, Species, get_all_species. Mirrors GeneNetwork3's gn3.db.species.get_all_species: same query, same ordering. Connection string from the SQL_URI environment variable (same config key GeneNetwork3 uses), defaulting to mysql://webqtlout:webqtlout@127.0.0.1/db_webqtl. * src/lib.rs (app): Add /species route. (species): New handler. Runs db::get_all_species on a blocking thread, since mysql::Conn is synchronous. * tests/species.rs: New file. Checks for a database on 127.0.0.1:3306 first and skips with a message instead of failing when none is reachable, since the Guix build sandbox has no network. * test/python/test_species.py: New file. Likewise. * README.md: Document /species, SQL_URI, and the skip-without-database behavior of species.rs and test_species.py. * rust-package.scm: Regenerate with guix import crate -f Cargo.lock genenetwork4. Adds crate-source definitions for mysql's transitive dependencies; bumps rust-libc and rust-tokio to the versions above. * guix.scm (genenetwork4-git)[native-inputs]: Add every new rust-package.scm entry mysql pulled in (roughly 100 packages, including rust-mysql-28.0.3, rust-mysql-common-0.37.3, rust-uuid, rust-url, rust-sha1, rust-sha2, rust-flate2).
Diffstat (limited to 'test/python')
| -rw-r--r-- | test/python/test_species.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/python/test_species.py b/test/python/test_species.py new file mode 100644 index 0000000..373b286 --- /dev/null +++ b/test/python/test_species.py @@ -0,0 +1,44 @@ +"""Mirrors tests/species.rs. Needs a live MariaDB (SQL_URI); skips with a +message rather than failing when none is reachable (e.g. inside the Guix +build sandbox, which has no network/database access). +""" + +import http.client +import json +import socket +import unittest + +from server_test_case import HOST, PORT, ServerTestCase + + +def database_reachable(): + try: + with socket.create_connection(("127.0.0.1", 3306), timeout=0.5): + return True + except OSError: + return False + + +class SpeciesTest(ServerTestCase): + def test_species_returns_ok_with_species_list(self): + if not database_reachable(): + self.skipTest("no database on 127.0.0.1:3306") + + conn = http.client.HTTPConnection(HOST, int(PORT), timeout=10) + try: + conn.request("GET", "/species") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 200) + + species = json.loads(body) + self.assertTrue(species) + for record in species: + self.assertIn("name", record) + self.assertIn("family", record) + + +if __name__ == "__main__": + unittest.main() |
