test: cover the drug dashboard and the admin copy-attributes bulk action - #670
Merged
Merged
Conversation
Two features had no coverage at all. Both are reached only through their endpoint and both write to the database, so they are covered as integration tests. GET /drugs/dashboard/<segment>/<drug> (drug_service.get_drug_dashboard) is the screen opened from a prescription line. Besides the read, it returns a stub payload when the drug has no substance linked yet, falls back on every attribute-derived field when the segment has no medatributos row, flags the prescribed dose/frequency pair as selected, and *creates* an outlier with score 4 when no pair matches. The new tests assert that write in the database, along with the dose rounding and the parameter combinations that must not create anything. POST /admin/drug/copy-attributes (admin_drug_service.copy_drug_attributes / admin_drug_repository.copy_attributes) is the bulk action of the drug curation screen and the widest write in the admin area. The tests cover both modes (substance catalog and segment-to-segment), the choice of the adult/pediatric reference columns, the mapping of substance tags to boolean attributes, the two cost attributes only the segment mode allows, and the rules that protect a curator's work: only the requested attributes are written, rows edited by a user are skipped unless overwriteAll is used (which CURATOR may not), drugs with no substance are never touched, and every affected row is audited. Coverage of the modules involved: repository/admin/admin_drug_repository.py 24% -> 100% services/admin/admin_drug_service.py 79% -> 85% services/drug_service.py 66% -> 76% repository/outlier_repository.py 62% -> 75% The copy statement rewrites a whole segment, so the tests aim it at segments they create themselves and never at the seed segments of the demo schema. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DDmGqQSfhPFUXAFsQj4G7o
There was a problem hiding this comment.
This PR adds comprehensive integration test coverage for two previously untested features: the drug dashboard endpoint and the admin copy-attributes bulk action. The tests are well-structured, thoroughly documented, and follow good testing practices including proper test isolation, database cleanup, and mutation testing verification. No blocking issues found.
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.
Two features had no coverage at all. Both are reachable only through their endpoint and both write to the database, so they are covered as integration tests.
GET /drugs/dashboard/<segment>/<drug>drug_service.get_drug_dashboard— the screen opened from a prescription line to see how a drug behaves in a segment. Besides the read it has behaviour worth pinning down:medatributosrow;dose/frequencypair is flaggedselected, and when no outlier matches, one is created with score 4 so the pair shows up from then on.tests/integration/test_drug_dashboard.py(15 tests) asserts that write in the database, the two-decimal dose rounding, the outlier ordering and row shape (note join, special frequency labels), the conversions being restricted to the requested segment, and the parameter combinations that must not create anything (non-numeric or partial dose/frequency).POST /admin/drug/copy-attributesadmin_drug_service.copy_drug_attributes/admin_drug_repository.copy_attributes— the bulk action of the drug curation screen, and the widest write in the admin area: one call rewrites the chosen attributes of everymedatributosrow of a segment.tests/integration/test_admin_drug_copy_attributes.py(17 tests) covers both modes and the rules that protect a curator's work:fromAdminSchema: true): substance tags map to the boolean attributes, direct columns are copied as-is, and the kidney/liver columns are picked by the destination segment's type — an adult and a pediatric segment get different values from the same substance;fromAdminSchema: false): origin values are copied, and the two cost attributes only this mode allows are written (they stay untouched in catalog mode);overwriteAllis used — and that flag requires a permissionCURATORdoes not have;COPY_FROM_REFERENCEaudit entry naming the copied attributes.Notes
9911block) and never at the seed segments of the demo schema. Each test rebuilds its rows, because a successful copy leaves them marked as curated.clean_test_artifactsfixture wipes (90700and91000blocks); the segments, which fall outside those windows, are removed by the module both before and after.Coverage
repository/admin/admin_drug_repository.pyservices/admin/admin_drug_service.pyservices/drug_service.pyrepository/outlier_repository.pyFull suite locally: 2289 passed (2257 before),
ruff checkclean. No production code changed.🤖 Generated with Claude Code
https://claude.ai/code/session_01DDmGqQSfhPFUXAFsQj4G7o
Generated by Claude Code