Skip to content

fix(test): update radionuclide test to stop using thing_id and to validate the real FK/relationship on chemistry_sample_info_id#472

Merged
jacob-a-brown merged 6 commits intostagingfrom
kas-fix-radionuclide-legacy-test
Feb 6, 2026
Merged

fix(test): update radionuclide test to stop using thing_id and to validate the real FK/relationship on chemistry_sample_info_id#472
jacob-a-brown merged 6 commits intostagingfrom
kas-fix-radionuclide-legacy-test

Conversation

@ksmuczynski
Copy link
Copy Markdown
Contributor

@ksmuczynski ksmuczynski commented Feb 6, 2026

Why

This PR addresses the following problem / context:

  • NMA_Radionuclides intentionally has no thing_id, but the tests expected it, causing failures.
  • FK/relationship assertions needed to reflect the actual model: chemistry_sample_info_id.

How

Implementation summary - the following was changed / added / removed:

  • Removed thing_id from NMA_Radionuclides test constructions and expected columns.
  • Updated FK enforcement to assert cascade on chemistry_sample_info_id.
  • Updated relationship test to validate chemistry_sample_info back-population.
  • Kept CRUD coverage focused on actual model fields

Notes

Any special considerations, workarounds, or follow-up work to note?

…real FK/relationship on `chemistry_sample_info_id`
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates legacy radionuclides tests to align with the actual schema/ORM relationships by removing thing_id expectations and validating the real FK/relationship via chemistry_sample_info_id.

Changes:

  • Removed thing_id usage from NMA_Radionuclides test record construction and expected column lists
  • Updated FK cascade assertion to target chemistry_sample_info_id
  • Adjusted relationship test to validate navigation through chemistry_sample_info

@ksmuczynski ksmuczynski changed the title fix(test): update tests to stop using thing_id and to validate the real FK/relationship on chemistry_sample_info_id fix(test): update radionuclide test to stop using thing_id and to validate the real FK/relationship on chemistry_sample_info_id Feb 6, 2026
- verify sample_info.radionuclides includes the new record
- keep FK/relationship tests aligned to chemistry_sample_info_id
@ksmuczynski ksmuczynski marked this pull request as draft February 6, 2026 18:47
@ksmuczynski ksmuczynski marked this pull request as ready for review February 6, 2026 21:14
Copilot AI review requested due to automatic review settings February 6, 2026 21:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

tests/features/steps/nma-legacy-relationships.py:114

  • The step function name step_then_find_by_locationid is now inconsistent with the updated model semantics in this PR (chemistry samples FK to Thing, and Location import was removed). Consider renaming the step/function to reflect Thing/well-based lookup (or reintroduce/retain Location usage/import if location-based lookup is still required) to avoid confusion and mismatched intent.
def step_then_find_by_locationid(context: Context):

from sqlalchemy.exc import IntegrityError, StatementError

from db import Location, Thing
from db import Thing
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The step function name step_then_find_by_locationid is now inconsistent with the updated model semantics in this PR (chemistry samples FK to Thing, and Location import was removed). Consider renaming the step/function to reflect Thing/well-based lookup (or reintroduce/retain Location usage/import if location-based lookup is still required) to avoid confusion and mismatched intent.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the step function step_then_find_by_locationid still remains true - a well should be successfully queried by its legacy LocationID (Thing.nma_pk_location). I don't think this needs to be renamed.

"""
with session_ctx() as session:
with pytest.raises(ValueError, match="requires a parent Thing"):
with pytest.raises(ValueError, match="requires a chemistry_sample_info_id"):
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion matches a very specific error message string, which can make the test brittle (e.g., small wording changes will break it). Consider loosening the match to a more stable regex that still proves intent (for example, matching on a key phrase like chemistry_sample_info rather than the full sentence).

Suggested change
with pytest.raises(ValueError, match="requires a chemistry_sample_info_id"):
with pytest.raises(ValueError, match=r"chemistry_sample_info_id"):

Copilot uses AI. Check for mistakes.

def test_radionuclides_back_populates_thing(water_well_thing):
"""NMA_Radionuclides.thing navigates back to Thing."""
def test_radionuclides_back_populates_sample_info(water_well_thing):
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Within an explicit session scope, mixing a fixture instance (water_well_thing) with newly persisted objects can be harder to reason about (especially if the fixture instance is detached from the current session). Consider using the session-bound Thing instance (e.g., merge/query inside session_ctx) consistently when wiring thing_id, to keep everything in the same session identity map.

Copilot uses AI. Check for mistakes.
nma_sample_pt_id=uuid4(),
nma_sample_point_id=_next_sample_point_id(),
thing_id=well.id,
thing_id=water_well_thing.id,
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Within an explicit session scope, mixing a fixture instance (water_well_thing) with newly persisted objects can be harder to reason about (especially if the fixture instance is detached from the current session). Consider using the session-bound Thing instance (e.g., merge/query inside session_ctx) consistently when wiring thing_id, to keep everything in the same session identity map.

Copilot uses AI. Check for mistakes.
- Moved radionuclide sample-info requirement into its own class
- Moved sample-info navigation test under a new navigation section
@jacob-a-brown jacob-a-brown merged commit 08ac545 into staging Feb 6, 2026
6 checks passed
@ksmuczynski ksmuczynski linked an issue Feb 6, 2026 that may be closed by this pull request
@TylerAdamMartinez TylerAdamMartinez deleted the kas-fix-radionuclide-legacy-test branch March 12, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Radionuclide Tests Fail With thing_id

3 participants