test: cover admin drug listing and protocol tracing - #662
Merged
Conversation
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
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-listis the entry point of the drug curation screen.drugs_repository.get_admin_drug_listjoins 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/sampleand/protocol/testexplain 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_groupshelper 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.
ADMIN_DRUGSrequired, curator allowed,WRITE_DRUG_ATTRIBUTESalone is not enough, invalid token, no-role user(drug, segment)outlier group, outlier counts summed per group, substance reference doses picked by segment typecountreports every matching row while the page respectslimit/offset; empty result reports zeroterm,substance,hasSubstance,hasInconsistency,hasDefaultUnit,hasPriceUnit,hasPriceConversion,hasMaxDose,tpRefMaxDose,hasAISubstance+aiAccuracyRange,substanceStatus,minDrugCount,idSegmentList,substanceList(in/notin),attributeList(in/notin, boolean and numeric),hasSubstanceMaxDoseWeight*,groupByDrugtests/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.
limitbound and its upper limitdetailedshapes, 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 validationVerification
1948 -> 2008 passed, no changes to existing testsruff check .clean, filesruff format-cleanminDrugCount,groupByDrugand the trace name lookup in the source made the corresponding tests fail, so the assertions are not vacuousCoverage on the touched modules:
repository/drugs_repository.pyservices/protocol_trace_service.pyroutes/protocol.pyTest rows use reserved high id ranges (
medicamento/outlier≥ 95000,substancia≥ 9500000,protocolo991xxx) 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