Skip to content

test: cover the drug dashboard and the admin copy-attributes bulk action - #670

Merged
marceloarocha merged 1 commit into
developfrom
claude/magical-wozniak-u4m9n4
Sep 4, 2026
Merged

test: cover the drug dashboard and the admin copy-attributes bulk action#670
marceloarocha merged 1 commit into
developfrom
claude/magical-wozniak-u4m9n4

Conversation

@marceloarocha

Copy link
Copy Markdown
Collaborator

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:

  • a stub payload (drug name only) when the drug has no substance linked yet, which is how the front end knows to send the user to curation first;
  • a fallback on every attribute-derived field of the response (and of each outlier row) when the segment has no medatributos row;
  • the prescribed dose/frequency pair is flagged selected, 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-attributes

admin_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 every medatributos row 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:

  • substance catalog mode (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;
  • segment-to-segment mode (fromAdminSchema: false): origin values are copied, and the two cost attributes only this mode allows are written (they stay untouched in catalog mode);
  • only the attributes named in the request are written;
  • rows already edited by a real user are skipped, unless overwriteAll is used — and that flag requires a permission CURATOR does not have;
  • drugs with no substance are never touched and never audited;
  • every affected row gets a COPY_FROM_REFERENCE audit entry naming the copied attributes.

Notes

  • The copy statement rewrites a whole segment, so the tests aim it at segments they create themselves (9911 block) and never at the seed segments of the demo schema. Each test rebuilds its rows, because a successful copy leaves them marked as curated.
  • Fixtures use the reserved id ranges the shared clean_test_artifacts fixture wipes (90700 and 91000 blocks); the segments, which fall outside those windows, are removed by the module both before and after.
  • Mutation-checked: inverting the adult/pediatric column choice, changing the new outlier's score, and changing the dose rounding each make the relevant tests fail.

Coverage

module before after
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%

Full suite locally: 2289 passed (2257 before), ruff check clean. No production code changed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DDmGqQSfhPFUXAFsQj4G7o


Generated by Claude Code

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

@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 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.

@marceloarocha
marceloarocha merged commit d635a9c into develop Sep 4, 2026
10 checks passed
@marceloarocha
marceloarocha deleted the claude/magical-wozniak-u4m9n4 branch September 4, 2026 10:55
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