diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-10-04 14:52:57 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-10-04 14:52:57 +0000 |
| commit | ea3633cf3e00047ca3906406c270d9f04acd2241 (patch) | |
| tree | c2aeb365ee43dd9eb1de2fab201c01921420a833 /test/python | |
| parent | 5e7870834fc29e707bc7332d83e4c68f05b9b8f7 (diff) | |
| download | genenetwork4-ea3633cf3e00047ca3906406c270d9f04acd2241.tar.gz | |
Add GET /species/{species}/datasets
Lists the expression (ProbeSet) datasets belonging to a species, across
all of its groups -- the species-scoped equivalent of
/groups/{group}/datasets (db::get_species_datasets joins ProbeSetFreeze
through ProbeFreeze and InbredSet to InbredSet.SpeciesId, reusing the
existing Dataset struct). GeneNetwork2's own species-scoped variant of
wqflask.api.router.get_datasets_for_group still requires a group name
(species only disambiguates it); this doesn't.
Not gated on gn-auth, matching its /groups/{group}/datasets sibling:
this returns dataset metadata (names, public/confidentiality flags),
not trait data, unlike the /datasets/{dataset}/probesets family.
tests/species_datasets.rs and its Python mirror cover the mouse-group
and unknown-species cases.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XDDpXvZBQat9uSgDeEMJ8d
Diffstat (limited to 'test/python')
| -rw-r--r-- | test/python/test_species_datasets.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/test/python/test_species_datasets.py b/test/python/test_species_datasets.py new file mode 100644 index 0000000..4f759b6 --- /dev/null +++ b/test/python/test_species_datasets.py @@ -0,0 +1,62 @@ +"""Mirrors tests/species_datasets.rs. Needs a live MariaDB (SQL_URI); +skips with a message rather than failing when none is reachable, same +as test_group_by_name.py. +""" + +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 SpeciesDatasetsTest(ServerTestCase): + def test_species_datasets_mouse_returns_datasets(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/mouse/datasets") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 200) + + datasets = json.loads(body) + self.assertTrue(datasets) + names = {record["name"] for record in datasets} + self.assertIn("Br_U_0803_M", names) + + def test_species_datasets_unknown_species_returns_404(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/not-a-real-species/datasets") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 404) + + error = json.loads(body) + self.assertEqual(error["status"], 404) + self.assertEqual(error["code"], "species_not_found") + self.assertEqual(error["operation_id"], "species_datasets") + self.assertEqual(error["next"], "/species") + + +if __name__ == "__main__": + unittest.main() |
