about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorPjotr Prins <pjotr.public01@thebird.nl>2026-10-03 16:14:49 +0000
committerPjotr <wrk@bosa.lan>2026-10-04 06:31:16 +0000
commite7191463db66fcc3c2618ccdf004e798e1d3ac6a (patch)
tree2e76f71985ee8b6a49c49c1c17606fffbceb056f /tests
parent0980c21ff71bf4c8fa73d3193460f7b7f69d9f6b (diff)
downloadgenenetwork4-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 'tests')
-rw-r--r--tests/dataset_by_name.rs58
-rw-r--r--tests/dataset_probeset_info.rs82
-rw-r--r--tests/dataset_probeset_values.rs83
-rw-r--r--tests/group_datasets.rs56
-rw-r--r--tests/openapi.rs4
5 files changed, 283 insertions, 0 deletions
diff --git a/tests/dataset_by_name.rs b/tests/dataset_by_name.rs
new file mode 100644
index 0000000..48208e6
--- /dev/null
+++ b/tests/dataset_by_name.rs
@@ -0,0 +1,58 @@
+use axum::http::StatusCode;
+use http_body_util::BodyExt;
+use serde_json::Value;
+
+mod common;
+
+/// Needs a live MariaDB connection (SQL_URI, see src/db.rs); skips rather
+/// than fails when none is reachable, same as group_by_name.rs.
+/// Br_U_0803_M is a real ProbeSetFreeze row in BXD, used here as a
+/// fixture the same way BXD itself is used elsewhere.
+#[tokio::test]
+async fn dataset_by_name_returns_dataset_row() {
+    if !common::db_available() {
+        eprintln!(
+            "skipping dataset_by_name_returns_dataset_row: no usable database (check SQL_URI credentials)"
+        );
+        return;
+    }
+
+    let response = common::get(
+        "GET /datasets/Br_U_0803_M",
+        "/datasets/Br_U_0803_M",
+    )
+    .await;
+
+    assert_eq!(response.status(), StatusCode::OK);
+
+    let body = response.into_body().collect().await.unwrap().to_bytes();
+    let dataset: Value = serde_json::from_slice(&body).unwrap();
+
+    assert_eq!(dataset["name"], "Br_U_0803_M");
+    assert_eq!(dataset["full_name"], "Brain U74Av2 08/03 MAS5");
+    assert_eq!(dataset["data_scale"], "log2");
+}
+
+#[tokio::test]
+async fn dataset_by_name_unknown_dataset_returns_404() {
+    if !common::db_available() {
+        eprintln!(
+            "skipping dataset_by_name_unknown_dataset_returns_404: no usable database (check SQL_URI credentials)"
+        );
+        return;
+    }
+
+    let response = common::get(
+        "GET /datasets/not-a-real-dataset",
+        "/datasets/not-a-real-dataset",
+    )
+    .await;
+
+    assert_eq!(response.status(), StatusCode::NOT_FOUND);
+    let body = response.into_body().collect().await.unwrap().to_bytes();
+    let error: Value = serde_json::from_slice(&body).unwrap();
+
+    assert_eq!(error["status"], 404);
+    assert_eq!(error["code"], "dataset_not_found");
+    assert_eq!(error["operation_id"], "dataset_by_name");
+}
diff --git a/tests/dataset_probeset_info.rs b/tests/dataset_probeset_info.rs
new file mode 100644
index 0000000..eb0224b
--- /dev/null
+++ b/tests/dataset_probeset_info.rs
@@ -0,0 +1,82 @@
+use axum::http::StatusCode;
+use http_body_util::BodyExt;
+use serde_json::Value;
+
+mod common;
+
+/// Needs a live MariaDB connection (SQL_URI, see src/db.rs); skips rather
+/// than fails when none is reachable, same as group_by_name.rs.
+/// Probeset 100001_at (gene symbol Cd3g) in dataset Br_U_0803_M is a
+/// real row in the database.
+#[tokio::test]
+async fn dataset_probeset_info_returns_gene_annotation() {
+    if !common::db_available() {
+        eprintln!(
+            "skipping dataset_probeset_info_returns_gene_annotation: no usable database (check SQL_URI credentials)"
+        );
+        return;
+    }
+
+    let response = common::get(
+        "GET /datasets/Br_U_0803_M/probesets/100001_at",
+        "/datasets/Br_U_0803_M/probesets/100001_at",
+    )
+    .await;
+
+    assert_eq!(response.status(), StatusCode::OK);
+
+    let body = response.into_body().collect().await.unwrap().to_bytes();
+    let info: Value = serde_json::from_slice(&body).unwrap();
+
+    assert_eq!(info["name"], "100001_at");
+    assert_eq!(info["symbol"], "Cd3g");
+    assert!(info["mean"].as_f64().is_some());
+}
+
+#[tokio::test]
+async fn dataset_probeset_info_unknown_dataset_returns_404() {
+    if !common::db_available() {
+        eprintln!(
+            "skipping dataset_probeset_info_unknown_dataset_returns_404: no usable database (check SQL_URI credentials)"
+        );
+        return;
+    }
+
+    let response = common::get(
+        "GET /datasets/not-a-real-dataset/probesets/100001_at",
+        "/datasets/not-a-real-dataset/probesets/100001_at",
+    )
+    .await;
+
+    assert_eq!(response.status(), StatusCode::NOT_FOUND);
+    let body = response.into_body().collect().await.unwrap().to_bytes();
+    let error: Value = serde_json::from_slice(&body).unwrap();
+
+    assert_eq!(error["status"], 404);
+    assert_eq!(error["code"], "dataset_not_found");
+    assert_eq!(error["operation_id"], "dataset_probeset_info");
+}
+
+#[tokio::test]
+async fn dataset_probeset_info_unknown_probeset_in_dataset_returns_404() {
+    if !common::db_available() {
+        eprintln!(
+            "skipping dataset_probeset_info_unknown_probeset_in_dataset_returns_404: no usable database (check SQL_URI credentials)"
+        );
+        return;
+    }
+
+    let response = common::get(
+        "GET /datasets/Br_U_0803_M/probesets/not-a-real-probeset",
+        "/datasets/Br_U_0803_M/probesets/not-a-real-probeset",
+    )
+    .await;
+
+    assert_eq!(response.status(), StatusCode::NOT_FOUND);
+    let body = response.into_body().collect().await.unwrap().to_bytes();
+    let error: Value = serde_json::from_slice(&body).unwrap();
+
+    assert_eq!(error["status"], 404);
+    assert_eq!(error["code"], "probeset_not_found");
+    assert_eq!(error["operation_id"], "dataset_probeset_info");
+}
diff --git a/tests/dataset_probeset_values.rs b/tests/dataset_probeset_values.rs
new file mode 100644
index 0000000..4ff8d08
--- /dev/null
+++ b/tests/dataset_probeset_values.rs
@@ -0,0 +1,83 @@
+use axum::http::StatusCode;
+use http_body_util::BodyExt;
+use serde_json::Value;
+
+mod common;
+
+/// Needs a live MariaDB connection (SQL_URI, see src/db.rs); skips rather
+/// than fails when none is reachable, same as group_by_name.rs.
+#[tokio::test]
+async fn dataset_probeset_values_returns_strain_values() {
+    if !common::db_available() {
+        eprintln!(
+            "skipping dataset_probeset_values_returns_strain_values: no usable database (check SQL_URI credentials)"
+        );
+        return;
+    }
+
+    let response = common::get(
+        "GET /datasets/Br_U_0803_M/probesets/100001_at/values",
+        "/datasets/Br_U_0803_M/probesets/100001_at/values",
+    )
+    .await;
+
+    assert_eq!(response.status(), StatusCode::OK);
+
+    let body = response.into_body().collect().await.unwrap().to_bytes();
+    let values: Vec<Value> = serde_json::from_slice(&body).unwrap();
+
+    assert!(!values.is_empty());
+    let bxd1 = values
+        .iter()
+        .find(|v| v["name"] == "BXD1")
+        .expect("BXD1 in /datasets/Br_U_0803_M/probesets/100001_at/values");
+    assert!(bxd1["value"].as_f64().is_some());
+}
+
+#[tokio::test]
+async fn dataset_probeset_values_unknown_dataset_returns_404() {
+    if !common::db_available() {
+        eprintln!(
+            "skipping dataset_probeset_values_unknown_dataset_returns_404: no usable database (check SQL_URI credentials)"
+        );
+        return;
+    }
+
+    let response = common::get(
+        "GET /datasets/not-a-real-dataset/probesets/100001_at/values",
+        "/datasets/not-a-real-dataset/probesets/100001_at/values",
+    )
+    .await;
+
+    assert_eq!(response.status(), StatusCode::NOT_FOUND);
+    let body = response.into_body().collect().await.unwrap().to_bytes();
+    let error: Value = serde_json::from_slice(&body).unwrap();
+
+    assert_eq!(error["status"], 404);
+    assert_eq!(error["code"], "dataset_not_found");
+    assert_eq!(error["operation_id"], "dataset_probeset_values");
+}
+
+#[tokio::test]
+async fn dataset_probeset_values_unknown_probeset_in_dataset_returns_404() {
+    if !common::db_available() {
+        eprintln!(
+            "skipping dataset_probeset_values_unknown_probeset_in_dataset_returns_404: no usable database (check SQL_URI credentials)"
+        );
+        return;
+    }
+
+    let response = common::get(
+        "GET /datasets/Br_U_0803_M/probesets/not-a-real-probeset/values",
+        "/datasets/Br_U_0803_M/probesets/not-a-real-probeset/values",
+    )
+    .await;
+
+    assert_eq!(response.status(), StatusCode::NOT_FOUND);
+    let body = response.into_body().collect().await.unwrap().to_bytes();
+    let error: Value = serde_json::from_slice(&body).unwrap();
+
+    assert_eq!(error["status"], 404);
+    assert_eq!(error["code"], "probeset_not_found");
+    assert_eq!(error["operation_id"], "dataset_probeset_values");
+}
diff --git a/tests/group_datasets.rs b/tests/group_datasets.rs
new file mode 100644
index 0000000..6d7d961
--- /dev/null
+++ b/tests/group_datasets.rs
@@ -0,0 +1,56 @@
+use axum::http::StatusCode;
+use http_body_util::BodyExt;
+use serde_json::Value;
+
+mod common;
+
+/// Needs a live MariaDB connection (SQL_URI, see src/db.rs); skips rather
+/// than fails when none is reachable, same as group_by_name.rs.
+#[tokio::test]
+async fn group_datasets_bxd_returns_datasets() {
+    if !common::db_available() {
+        eprintln!(
+            "skipping group_datasets_bxd_returns_datasets: no usable database (check SQL_URI credentials)"
+        );
+        return;
+    }
+
+    let response = common::get("GET /groups/BXD/datasets", "/groups/BXD/datasets").await;
+
+    assert_eq!(response.status(), StatusCode::OK);
+
+    let body = response.into_body().collect().await.unwrap().to_bytes();
+    let datasets: Vec<Value> = serde_json::from_slice(&body).unwrap();
+
+    assert!(!datasets.is_empty());
+    let names: Vec<&str> = datasets
+        .iter()
+        .map(|record| record["name"].as_str().unwrap())
+        .collect();
+    assert!(names.contains(&"Br_U_0803_M"));
+}
+
+#[tokio::test]
+async fn group_datasets_unknown_group_returns_404() {
+    if !common::db_available() {
+        eprintln!(
+            "skipping group_datasets_unknown_group_returns_404: no usable database (check SQL_URI credentials)"
+        );
+        return;
+    }
+
+    let response = common::get(
+        "GET /groups/not-a-real-group/datasets",
+        "/groups/not-a-real-group/datasets",
+    )
+    .await;
+
+    assert_eq!(response.status(), StatusCode::NOT_FOUND);
+    let body = response.into_body().collect().await.unwrap().to_bytes();
+    let error: Value = serde_json::from_slice(&body).unwrap();
+
+    assert_eq!(error["status"], 404);
+    assert_eq!(error["code"], "group_not_found");
+    assert_eq!(error["operation_id"], "group_datasets");
+    assert_eq!(error["next"], "/groups");
+}
diff --git a/tests/openapi.rs b/tests/openapi.rs
index d2d75c0..8cb6dc1 100644
--- a/tests/openapi.rs
+++ b/tests/openapi.rs
@@ -34,6 +34,10 @@ async fn openapi_json_describes_all_endpoints() {
         "/groups/{group}/strains",
         "/groups/{group}/traits/{trait_id}",
         "/groups/{group}/traits/{trait_id}/values",
+        "/groups/{group}/datasets",
+        "/datasets/{dataset}",
+        "/datasets/{dataset}/probesets/{probeset}",
+        "/datasets/{dataset}/probesets/{probeset}/values",
     ] {
         assert!(paths.contains_key(path), "missing path: {path}");
     }