diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-10-03 16:14:49 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-10-04 06:31:16 +0000 |
| commit | e7191463db66fcc3c2618ccdf004e798e1d3ac6a (patch) | |
| tree | 2e76f71985ee8b6a49c49c1c17606fffbceb056f /test/python/test_group_datasets.py | |
| parent | 0980c21ff71bf4c8fa73d3193460f7b7f69d9f6b (diff) | |
| download | genenetwork4-e7191463db66fcc3c2618ccdf004e798e1d3ac6a.tar.gz | |
Add ProbeSetXRef endpoints: datasets, probesets, probeset values.
The expression (ProbeSet) counterpart to the PublishXRef endpoints:
ProbeSetXRef has no single Id column of its own (its primary key is
DataId; the natural key is the pair (ProbeSetFreezeId, ProbeSetId)),
so a trait here is addressed by dataset name plus ProbeSet.Name
instead of a single numeric trait id.
* src/db.rs (Dataset): New struct, one ProbeSetFreeze row.
(get_group_datasets): New function. Joins ProbeSetFreeze and
ProbeFreeze by group Id, matching GeneNetwork2's
wqflask.api.router.get_datasets_for_group.
(get_dataset_by_name): New function. Matches Name, Name2, FullName,
ShortName or numeric Id, matching
wqflask.api.router.get_dataset_info's ProbeSet-branch matching logic.
A dataset name is globally unique on its own, unlike a group's
traits, so this isn't scoped by group.
(ProbeSetInfo): New struct, a probe's ProbeSetXRef mapping stats plus
its ProbeSet gene annotation.
(get_dataset_probeset_info): New function, matching
wqflask.api.router.get_trait_info's ProbeSet branch.
(ProbeSetValue): New struct.
(get_dataset_probeset_values): New function, matching
wqflask.api.router.trait_sample_data's ProbeSet branch.
* src/lib.rs (DatasetProbesetLookup): New enum, the expression-dataset
equivalent of GroupTraitLookup -- distinguishes a missing dataset from
a missing probeset in an existing dataset.
(group_datasets): New handler for GET /groups/{group}/datasets.
(dataset_by_name): New handler for GET /datasets/{dataset}.
(get_dataset_probeset_info_result, dataset_probeset_info): New
function and handler for GET /datasets/{dataset}/probesets/{probeset}.
(get_dataset_probeset_values_result, dataset_probeset_values): New
function and handler for
GET /datasets/{dataset}/probesets/{probeset}/values.
(app): Register all four.
* tests/group_datasets.rs, tests/dataset_by_name.rs,
tests/dataset_probeset_info.rs, tests/dataset_probeset_values.rs,
test/python/test_group_datasets.py, test/python/test_dataset_by_name.py,
test/python/test_dataset_probeset_info.py,
test/python/test_dataset_probeset_values.py: New files. Br_U_0803_M
(dataset) / 100001_at (probeset, gene symbol Cd3g) in BXD are real rows
used as fixtures.
* tests/openapi.rs, test/python/test_openapi.py: Check the four new
paths are in the generated spec.
* README.md: Document the four new endpoints and list the new test
files.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XDDpXvZBQat9uSgDeEMJ8d
Diffstat (limited to 'test/python/test_group_datasets.py')
| -rw-r--r-- | test/python/test_group_datasets.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/test/python/test_group_datasets.py b/test/python/test_group_datasets.py new file mode 100644 index 0000000..d338075 --- /dev/null +++ b/test/python/test_group_datasets.py @@ -0,0 +1,62 @@ +"""Mirrors tests/group_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 GroupDatasetsTest(ServerTestCase): + def test_group_datasets_bxd_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", "/groups/BXD/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_group_datasets_unknown_group_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", "/groups/not-a-real-group/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"], "group_not_found") + self.assertEqual(error["operation_id"], "group_datasets") + self.assertEqual(error["next"], "/groups") + + +if __name__ == "__main__": + unittest.main() |
