Skip to content

test: cover the raw exams report and the user security-group update - #677

Merged
marceloarocha merged 1 commit into
developfrom
claude/magical-wozniak-sfe4tt
Sep 8, 2026
Merged

test: cover the raw exams report and the user security-group update#677
marceloarocha merged 1 commit into
developfrom
claude/magical-wozniak-sfe4tt

Conversation

@marceloarocha

Copy link
Copy Markdown
Collaborator

Two features had no test at all. Both are now covered by integration tests, 22 in total.

GET /reports/exams/rawtests/integration/test_reports_exams.py

The raw-exams report hands a patient's laboratory results to an integration untransformed, so the tests pin exactly what the service decides:

  • READ_REPORTS is required (a USER_MANAGER is refused) and is enough (a VIEWER may pull the results);
  • idPatient is mandatory (400 errors.invalidParams);
  • the 30-day window, including its edge: a result exactly 30 days old is still reported, one 31 days old is not, and the seeded 2019 results are outside it by construction;
  • the results are scoped to the requested patient, and an unknown patient reports an empty list;
  • the rows are grouped by exam type, newest result of each type first;
  • the full column mapping — every identifier and the result value leave as strings, the date as ISO-8601, and a result stored without a unit keeps a null unit.

Exam dates are anchored at midday so the per-request America/Sao_Paulo timezone cannot move a date across the day boundary the window is measured from. Each test removes exactly the rows it inserted, so the file is re-runnable.

POST /admin/integration/update-user-security-grouptests/integration/test_admin_integration.py

This support endpoint opens the client's AWS security group for the machine the caller is asking from. The Lambda is replaced by a recorder, so the tests assert the part the backend actually decides:

  • only a role holding UPDATE_USER_SG may ask, and a refused caller never reaches the Lambda;
  • the backend function is invoked once, synchronously, on the configured region;
  • the rule is opened for the caller's own address, taken from the forwarded proxy headers (first entry wins, connection address as fallback) and narrowed to a single host (/32);
  • the Lambda answer is handed back untouched, including when it arrives double-encoded as a JSON string holding JSON;
  • an answer flagged error becomes 400 errors.businessRules, carrying the Lambda's message or a default one when it is mute;
  • a successful change leaves an audit record naming the schema, the new address and the author — and a refused change leaves none.

The production refusal of api_endpoint(is_admin=True) is already covered by tests/unit/test_api_endpoint_decorator.py, so it is not repeated here.

Validation

  • ENV=test pytest — 2529 passed (2507 before, +22), against the same seed data CI loads
  • ruff check . — clean

🤖 Generated with Claude Code

https://claude.ai/code/session_01DA8MQTchTCXwGc7f63xJap


Generated by Claude Code

Both features had no test at all:

* GET /reports/exams/raw hands a patient's laboratory results to an
  integration untransformed. The tests pin the permission gate, the
  mandatory patient, the 30-day window (including its edge), the
  per-patient scoping, the type/date ordering and the full column
  mapping -- every identifier and the result value leave as strings.

* POST /admin/integration/update-user-security-group opens the client's
  AWS security group for the caller's own address. The Lambda is
  replaced by a recorder, so the tests assert what the backend decides:
  the permission gate, the synchronous invoke of the backend function,
  the caller address taken from the forwarded headers and narrowed to a
  /32, the double-encoded answer being unwrapped, an answer flagged
  error becoming a business-rule error, and the audit record written on
  success and absent on failure.

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

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

Summary

This PR adds comprehensive integration test coverage for two previously untested features: the raw exams report endpoint and the user security group update endpoint. The implementation is solid with 22 new tests that properly validate permissions, data filtering, error handling, and audit logging.

Test Coverage Assessment:

  • ✅ Proper fixture management with automatic cleanup
  • ✅ Appropriate mocking of AWS Lambda interactions
  • ✅ Comprehensive edge case testing (30-day window boundaries, empty results, permission checks)
  • ✅ Clean database operations with proper isolation
  • ✅ All 2529 tests passing (+22 new tests)

No blocking issues identified. The tests are well-structured, handle cleanup properly, and validate the correct behavior of both endpoints. The code is ready for merge.


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 b45a84e into develop Sep 8, 2026
10 checks passed
@marceloarocha
marceloarocha deleted the claude/magical-wozniak-sfe4tt branch September 8, 2026 11:20
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