test: cover the raw exams report and the user security-group update - #677
Merged
Conversation
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
There was a problem hiding this comment.
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.
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 test at all. Both are now covered by integration tests, 22 in total.
GET /reports/exams/raw—tests/integration/test_reports_exams.pyThe raw-exams report hands a patient's laboratory results to an integration untransformed, so the tests pin exactly what the service decides:
idPatientis mandatory (400 errors.invalidParams);Exam dates are anchored at midday so the per-request
America/Sao_Paulotimezone 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-group—tests/integration/test_admin_integration.pyThis 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:
/32);errorbecomes400 errors.businessRules, carrying the Lambda's message or a default one when it is mute;The production refusal of
api_endpoint(is_admin=True)is already covered bytests/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 loadsruff check .— clean🤖 Generated with Claude Code
https://claude.ai/code/session_01DA8MQTchTCXwGc7f63xJap
Generated by Claude Code