about summary refs log tree commit diff
path: root/test/python
AgeCommit message (Collapse)Author
2026-10-03Add GET /groups/{group}/strains, mirroring gn-guile's strain-id-names.Pjotr Prins
* src/db.rs (Strain): New struct. (get_group_strains): New function. Joins Strain and StrainXRef by group Id, optionally filtered to strains used for mapping, matching gn-guile's gn.data.strains:strain-id-names (same InbredSetId and used-for-mapping? arguments), returning strain names as well as ids. * src/lib.rs (GroupStrainsParams): New struct, the used_for_mapping query parameter. (group_strains): New handler for GET /groups/{group}/strains. Looks the group up the same way group_by_name does, for the same 404 shape on an unknown group. (app): Register it. * tests/group_strains.rs, test/python/test_group_strains.py: New files. * tests/openapi.rs, test/python/test_openapi.py: Check the new path is in the generated spec. * README.md (GET /groups/{group}/strains): Document it, including the used_for_mapping filter excluding BXD's parent strains. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XDDpXvZBQat9uSgDeEMJ8d
2026-10-03Match group by numeric Id, use Group alias for InbredSet fields.Pjotr Prins
* src/db.rs (get_group_by_name): Also match CAST(Id AS CHAR), so a numeric Id works like GeneNetwork2's wqflask.api.router.get_group_info plus gn-guile's gn.data.population:population-info, which looks a group up by Id only. (GroupDetail): Rename inbred_set_id, inbred_set_name, inbred_set_code fields to group_id, display_name, group_code, adding #[mysql(rename = "...")] overrides so FromRow still matches the InbredSetId, InbredSetName, InbredSetCode MariaDB columns; InbredSet stays a MariaDB-only name, not a Rust identifier. * src/lib.rs (group_by_name): Update the "group" path parameter description to mention matching by numeric Id too. * tests/group_by_name.rs (group_by_name_bxd_returns_group_row): Update assertion for the display_name field rename. (group_by_name_numeric_id_returns_same_group_row): New test. * test/python/test_group_by_name.py: Likewise. * README.md (GET /groups/{group}): Document matching by numeric Id and the group_id/display_name/group_code field names. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XDDpXvZBQat9uSgDeEMJ8d
2026-10-03Add /groups and /groups/{group} endpoints.Pjotr Prins
* src/db.rs (Group): New struct. Summary of one InbredSet row, matching the shape of GeneNetwork2's GET /api/v_pre1/groups response. (get_all_groups): New function. Mirrors GeneNetwork2's wqflask.api.router.get_groups_list (no species filter yet). (GroupDetail): New struct, deriving FromRow instead of being built from a tuple like SpeciesDetail, since InbredSet has 14 columns, more than mysql_common's FromRow is implemented for tuples (up to 12). FromRow matches by column name (PascalCase of the field name via #[mysql(rename_all = "PascalCase")]), except public, which is lowercase in the schema and needs its own #[mysql(rename = "public")]. (get_group_by_name): New function. Mirrors GeneNetwork2's wqflask.api.router.get_group_info, but returns every column instead of a fixed subset. * src/lib.rs (app): Add /groups and /groups/{group} routes. (groups, group_by_name): New handlers, following the same ApiError/request-id/spawn_blocking pattern as species/species_by_name. (group_by_name): On no match, set ApiError's next to /groups. * tests/groups.rs: New file. Checks BXD is present (used throughout the GeneNetwork2 and GeneNetwork3 test suites as a fixture group, always present in the database); skips rather than fails when no database is reachable, same as species.rs. * test/python/test_groups.py: New file. Likewise. * tests/group_by_name.rs: New file. Checks BXD's full row and an unknown-group 404 case, same pattern as species_by_name.rs. * test/python/test_group_by_name.py: New file. Likewise. * tests/openapi.rs (openapi_json_describes_all_endpoints): Check for /groups and /groups/{group} among the documented paths. * test/python/test_openapi.py (test_openapi_json_describes_all_endpoints): Likewise. * README.md: Document /groups and /groups/{group}.
2026-10-03Add shared ApiError response shape and request-id tracking.Pjotr Prins
* Cargo.toml (dependencies): Add tower-http, features request-id and util. * src/error.rs: New file. ApiError, modeled on RFC 7807 (Problem Details for HTTP APIs) plus code, operation_id, spec_url, request_id and next. type and spec_url are relative paths since this service has no fixed public domain. Implements axum::response::IntoResponse. * src/lib.rs (app): Add SetRequestIdLayer and PropagateRequestIdLayer, assigning each request an x-request-id and copying it onto the response. (request_id_string): New function. (species, species_by_name): Take an Extension<RequestId> parameter. Return Result<_, ApiError> instead of Result<_, (StatusCode, String)>. (species_by_name): On no match, set ApiError's next to /species, so a caller with a wrong species name can discover the valid ones. * tests/species_by_name.rs (species_by_name_unknown_species_returns_404): Check the full ApiError body (status, code, operation_id, spec_url, next) and that request_id matches the x-request-id response header, instead of only the status code. * test/python/test_species_by_name.py (test_species_by_name_unknown_species_returns_404): Likewise. * README.md: Add an Error handling section documenting the ApiError shape and each field. * rust-package.scm: Regenerate with guix import crate -f Cargo.lock genenetwork4. Adds crate-source definitions for tower-http and its new transitive dependencies. * guix.scm (genenetwork4-git)[native-inputs]: Add rust-tower-http-0.7.1, rust-getrandom-0.4.3 and rust-r-efi-6.0.0.
2026-10-03Add /species/{species} for a single species' full row.Pjotr Prins
Checked for an existing implementation first: GeneNetwork2's wqflask/api/router.py has /api/v_pre1/species/<species_name>, matching Name, FullName or SpeciesName, but returning only a 4-column subset (Id, Name, FullName, TaxonomyId). GeneNetwork3's gn3/db/wiki.py has only internal name-to-id lookups for the wiki feature; its /species is SPARQL-based metadata, not a Species table row. gn-guile's species code (gn/data/species.scm) is also SPARQL/RDF metadata, not backed by db_webqtl. * src/db.rs (params): Import. (SpeciesDetail): New struct, one full row of the Species table. (get_species_by_name): New function. Same match logic as GeneNetwork2's get_species_info (Name, FullName or SpeciesName), but selects every column instead of a fixed subset. * src/lib.rs (app): Add /species/{species} route. (species_by_name): New handler. 404 if no species matches. * tests/species_by_name.rs: New file. Tests mouse specifically (Name=mouse is always present) and an unknown-species 404 case; skips rather than fails when no database is reachable, same as species.rs. * test/python/test_species_by_name.py: New file. Likewise. * tests/openapi.rs (openapi_json_describes_all_endpoints): Check for /species/{species} among the documented paths. * test/python/test_openapi.py (test_openapi_json_describes_all_endpoints): Likewise. * README.md: Document /species/{species}.
2026-10-03Add /openapi.json describing the REST API.Pjotr Prins
* Cargo.toml (dependencies): Add utoipa, feature axum_extras; add utoipa-axum. * src/lib.rs: Use utoipa_axum::router::OpenApiRouter and routes! instead of axum::Router and route!, so paths register into an OpenApi document as well as the router. (ApiDoc): New struct, deriving utoipa::OpenApi with title, description and license. (app): Add /openapi.json, serving the OpenApi document split out of OpenApiRouter via split_for_parts. (hello_world, version, species): Add #[utoipa::path(...)] attributes describing each endpoint's responses. (VersionInfo): Derive utoipa::ToSchema in addition to Serialize. * src/db.rs (Species): Likewise. * tests/openapi.rs: New file. Checks /openapi.json's info.title and that it lists all three endpoints. * test/python/test_openapi.py: New file. Likewise. * README.md: Document /openapi.json. * rust-package.scm: Regenerate with guix import crate -f Cargo.lock genenetwork4. Adds crate-source definitions for utoipa, utoipa-gen, utoipa-axum and pastey. * guix.scm (genenetwork4-git)[native-inputs]: Add rust-utoipa-6.0.0, rust-utoipa-gen-6.0.1, rust-utoipa-axum-0.3.0 and rust-pastey-0.2.3.
2026-10-03Assert mouse and rat are present in /species.Pjotr Prins
* tests/species.rs (species_returns_ok_with_species_list): Assert the returned names include mouse and rat, which are always present in the database. * test/python/test_species.py (test_species_returns_ok_with_species_list): Likewise.
2026-10-03Add /species endpoint backed by MariaDB.Pjotr Prins
* 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).
2026-10-01Add /version endpoint, extract shared python test helper.Pjotr Prins
* .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.
2026-10-01Add Python REST API test, run it from guix.scm.Pjotr Prins
* src/main.rs (main): Read GENENETWORK4_PORT environment variable for the listen port, default to 3000. * test/python/test_hello_world.py: New file. * guix.scm: Add (gnu packages python) to use-modules. (genenetwork4-git)[native-inputs]: Add python. (genenetwork4-git)[arguments]<#:phases>: Add 'python-rest-test phase after 'install, running test/python/test_hello_world.py against the installed binary on port 3737.