Skip to content

added test cases for observation viewset#3623

Open
praffq wants to merge 1 commit intodevelopfrom
prafful/tests/observation
Open

added test cases for observation viewset#3623
praffq wants to merge 1 commit intodevelopfrom
prafful/tests/observation

Conversation

@praffq
Copy link
Copy Markdown
Contributor

@praffq praffq commented Apr 13, 2026

Proposed Changes

  • added test cases for observation viewset

Associated Issue

Architecture changes

  • Remove this section if not used

Merge Checklist

  • Tests added/fixed
  • Update docs in /docs
  • Linting Complete
  • Any other necessary step

Only PR's with test cases included and passing lint and test pipelines will be reviewed

@ohcnetwork/care-backend-maintainers @ohcnetwork/care-backend-admins

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for Observation API endpoints, validating list, retrieve, and analyse operations with filtering, access control, and pagination scenarios.

@praffq praffq requested a review from a team as a code owner April 13, 2026 06:33
Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 13, 2026

📝 Walkthrough

Walkthrough

A new test file is added for the Observation API endpoints, introducing comprehensive test coverage for list, retrieve, create, update, delete, and analyse actions. Tests verify authentication, permissions, filtering by encounter and codes, ordering, and response structure.

Changes

Cohort / File(s) Summary
Observation API Tests
care/emr/tests/test_observation_api.py
Comprehensive test suite for Observation endpoints covering authentication, permissions, filtering by encounter/codes, ordering, analyse action with pagination, and error handling (403/404/405/400/422).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change—adding test cases for the observation viewset—and is concise and specific enough for quick understanding.
Description check ✅ Passed The description follows the template structure with all required sections present: Proposed Changes, Associated Issue, and Merge Checklist, though the proposed changes section is quite minimal.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch prafful/tests/observation

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
care/emr/tests/test_observation_api.py (1)

173-183: Ordering assertion is a bit brittle under timestamp ties

This test assumes obs2.modified_date > obs1.modified_date. If both rows get identical modified_date, DB tie-order can be nondeterministic and the test may flake.

Suggested hardening
     def test_list_ordered_by_modified_date_descending(self):
         self._grant_patient_read_permission()
-        obs1 = self._create_observation()
-        obs2 = self._create_observation()
+        obs1 = self._create_observation(modified_date="2026-01-01T00:00:00Z")
+        obs2 = self._create_observation(modified_date="2026-01-01T00:00:01Z")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@care/emr/tests/test_observation_api.py` around lines 173 - 183, The test
test_list_ordered_by_modified_date_descending is brittle because it assumes
obs2.modified_date > obs1.modified_date; make the ordering deterministic by
explicitly controlling timestamps or asserting with a deterministic secondary
key: either set distinct modified_date values when creating observations via
_create_observation (e.g., update obs2.modified_date to be later and save before
the GET) or change the assertion to compare results sorted by (modified_date,
id) so the expected order is deterministic using obs1.external_id and
obs2.external_id; update the test body around obs1/obs2 and the GET/assertion
accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@care/emr/tests/test_observation_api.py`:
- Around line 173-183: The test test_list_ordered_by_modified_date_descending is
brittle because it assumes obs2.modified_date > obs1.modified_date; make the
ordering deterministic by explicitly controlling timestamps or asserting with a
deterministic secondary key: either set distinct modified_date values when
creating observations via _create_observation (e.g., update obs2.modified_date
to be later and save before the GET) or change the assertion to compare results
sorted by (modified_date, id) so the expected order is deterministic using
obs1.external_id and obs2.external_id; update the test body around obs1/obs2 and
the GET/assertion accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c98374ea-c7f9-49f2-b2db-428c82d1398b

📥 Commits

Reviewing files that changed from the base of the PR and between 2645cb0 and 461cd58.

📒 Files selected for processing (1)
  • care/emr/tests/test_observation_api.py

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.31%. Comparing base (2645cb0) to head (461cd58).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3623      +/-   ##
===========================================
+ Coverage    77.20%   77.31%   +0.11%     
===========================================
  Files          474      474              
  Lines        22421    22421              
  Branches      2348     2348              
===========================================
+ Hits         17310    17335      +25     
+ Misses        4531     4504      -27     
- Partials       580      582       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant