Skip to content

test: cover admin drug listing and protocol tracing - #662

Merged
marceloarocha merged 1 commit into
developfrom
claude/magical-wozniak-4y3016
Aug 30, 2026
Merged

test: cover admin drug listing and protocol tracing#662
marceloarocha merged 1 commit into
developfrom
claude/magical-wozniak-4y3016

Conversation

@marceloarocha

Copy link
Copy Markdown
Collaborator

Why

Two features reached the test suite only indirectly. Both are user-facing, both are mostly SQL and route/service/repository wiring, and both had large untested surfaces.

Admin drug listing/admin/drug/attributes-list is the entry point of the drug curation screen. drugs_repository.get_admin_drug_list joins the outlier counters with the schema drug attributes and the public substance catalog, and exposes around twenty filters. None of them were exercised end-to-end (repository at 38%).

Protocol tracing/protocol/prescription-trace, /protocol/test/sample and /protocol/test explain why a protocol did or did not activate on a prescription, and do the same for a config still being edited. Only the internal _evaluate_date_groups helper had unit tests; the orchestration, applicability rules, name resolution and per-prescription error isolation had none (service at 33%).

What

Two new integration test files. Integration rather than unit, because the behaviour under test lives in the query and in the wiring, not in isolated logic.

tests/integration/test_admin_drug_list.py (31 tests)

Seeds three drugs covering the states the curation screen sorts by: one fully curated, one prescribed but with no attributes row at all (inconsistency), one carrying an AI-suggested substance and attributes on two segments.

  • permission gating: ADMIN_DRUGS required, curator allowed, WRITE_DRUG_ATTRIBUTES alone is not enough, invalid token, no-role user
  • row shape, one row per (drug, segment) outlier group, outlier counts summed per group, substance reference doses picked by segment type
  • pagination: count reports every matching row while the page respects limit/offset; empty result reports zero
  • filters: term, substance, hasSubstance, hasInconsistency, hasDefaultUnit, hasPriceUnit, hasPriceConversion, hasMaxDose, tpRefMaxDose, hasAISubstance + aiAccuracyRange, substanceStatus, minDrugCount, idSegmentList, substanceList (in/notin), attributeList (in/notin, boolean and numeric), hasSubstanceMaxDoseWeight*, groupByDrug

tests/integration/test_protocol_trace.py (29 tests)

Seeds protocols covering activation, non-activation, inactive status, incompatible type, another schema and an unrunnable config, then traces a real prescription against them.

  • trace: visible protocols only, trigger/result/variables of an activated protocol, the variable that turned a trigger false, drug ids rendered as drug names, inactive and type-incompatible protocols reported as not applicable with their notes, an invalid config reported per date group instead of failing the request
  • sample: type-to-aggregation mapping, limit bound and its upper limit
  • test: compact vs detailed shapes, custom name in the trace and summary, type mismatch reported as informational, invalid config reported per group, one unknown prescription id isolated from the rest of the chunk, chunk size and config validation

Verification

  • full suite: 1948 -> 2008 passed, no changes to existing tests
  • ruff check . clean, files ruff format-clean
  • each new file was mutation-checked: breaking minDrugCount, groupByDrug and the trace name lookup in the source made the corresponding tests fail, so the assertions are not vacuous

Coverage on the touched modules:

module before after
repository/drugs_repository.py 38% 90%
services/protocol_trace_service.py 33% 92%
routes/protocol.py 87% 97%

Test rows use reserved high id ranges (medicamento/outlier ≥ 95000, substancia ≥ 9500000, protocolo 991xxx) and are removed by their own fixtures, so the suite stays re-runnable.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CjEbprG7BvzEUsrkjttd1j


Generated by Claude Code

Two features reached the test suite only indirectly:

- /admin/drug/attributes-list, the entry point of the drug curation
  screen. Its query in drugs_repository.get_admin_drug_list joins the
  outlier counters with the schema attributes and the public substance
  catalog and exposes ~20 filters, none of which were exercised
  end-to-end (repository at 38% coverage).

- The protocol tracing endpoints (/protocol/prescription-trace,
  /protocol/test/sample, /protocol/test). Only the internal
  _evaluate_date_groups helper had unit tests; the orchestration,
  applicability rules, name resolution and per-prescription error
  isolation had none (service at 33%).

Both are covered with integration tests, since the behaviour under test
lives in the SQL and in the route/service/repository wiring rather than
in isolated logic.

Coverage: drugs_repository 38% -> 90%, protocol_trace_service 33% -> 92%,
routes/protocol 87% -> 97%.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CjEbprG7BvzEUsrkjttd1j

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR adds comprehensive integration test coverage for two important features: admin drug listing and protocol tracing. The implementation is solid with 60 new tests that follow testing best practices.

Strengths:

  • Proper test isolation with fixtures and thorough cleanup
  • Reserved ID ranges prevent collision with seed data
  • Comprehensive coverage of filters, permissions, and edge cases
  • Clear test organization and documentation
  • Database changes are properly rolled back after tests

Test Coverage Improvements:

  • Admin drug listing: 38% → 90%
  • Protocol trace service: 33% → 92%
  • Protocol routes: 87% → 97%

The test suite is well-designed and ready to merge. No blocking issues identified.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

@marceloarocha
marceloarocha merged commit 3bd084b into develop Aug 30, 2026
10 checks passed
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.

2 participants