Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,30 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

## [1.0.0] - 2026-04-24

### Changed

* Upgraded MySQL version for GitHub CI to 8.4
* Updated the ORM to reflect [changes](https://github.com/wtsi-npg/npg_tracking/pull/969)
to the production database.
* Regenerated the ORM with the current (4.0.3) version of `sqlacodegen`.
* Renamed `tests/test_schema.py` to `tests/test_retrieval.py` to reflect the
module name that is being tested.

### Added

* `validate_runfolder` function to npgtracking.db.retrieval

## [0.2.0] - 2025-12-12

### Added

* get_run_by_id function added to retrieval module
* `get_run_by_id` function added to retrieval module

### Fixed

* run.batch_id is now a varchar
* `run.batch_id` is now a varchar

## [0.1.1] - 2025-12-11

Expand Down
22 changes: 22 additions & 0 deletions src/npgtracking/db/retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,25 @@ def get_run_by_id(
raise ValueError("Can't get one run without an argument")
result = session.execute(statement).scalar_one_or_none()
return result


def validate_runfolder(session: Session, id_run: int, runfolder_name: str) -> bool:
"""Validates the runfolder name against the run ID.

Errors if run with the given ID does not exist.

Args:
session :
Database session
id_run :
Tracking run ID
runfolder_name :
Runfolder name
Returns:
`True` if the runfolder name and run id belong to the same run, `False`
otherwise.
"""
run = session.execute(select(Run).where(Run.id_run == id_run)).scalar()
if not run:
raise ValueError(f"Run with ID {id_run} does not exist.")
return run.folder_name == runfolder_name
19 changes: 18 additions & 1 deletion tests/test_schema.py → tests/test_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
from npgtracking.db.retrieval import (
get_run_by_id,
get_runs_by_currentstatus,
validate_runfolder,
)


@m.describe("SchemaModel")
@m.describe("Data retrieval from the tracking database")
class TestSchemaModel(object):
@m.context("When retrieving run records from tracking DB")
@m.context("When there are no runs having a current status and manufacturer name")
Expand Down Expand Up @@ -102,3 +103,19 @@ def test_run_by_id(self, tracking_session):

run = get_run_by_id(session=tracking_session, id_run=12345)
assert run is None

@m.context("When runfolder name and run ID are correct")
@m.it("Validator returns True, otherwise False")
def test_validate_runfolder(self, tracking_session):
assert (
validate_runfolder(tracking_session, 51533, "430591-20251204_1628") is True
)
assert (
validate_runfolder(tracking_session, 51533, "430591-20251204_XXXX") is False
)

@m.context("When run ID is invalid")
@m.it("An error is raised")
def test_validate_runfolder_error(self, tracking_session):
with raises(ValueError, match="Run with ID 1 does not exist"):
validate_runfolder(tracking_session, 1, "430591-20251204_1628")