Skip to content

Comments

added pending testcases#3532

Open
praffq wants to merge 2 commits intodevelopfrom
prafful/test/pending-testcases
Open

added pending testcases#3532
praffq wants to merge 2 commits intodevelopfrom
prafful/test/pending-testcases

Conversation

@praffq
Copy link
Contributor

@praffq praffq commented Feb 16, 2026

Proposed Changes

  • test_account_api.py — CRUD, duplicate active account validation, filters (status/patient/billing_status), primary encounter facility/patient mismatch,
    default_account action
  • test_medication_request_prescription_api.py — CRUD, filters (status/encounter), permission checks for create/update
  • test_facility_api.py — CRUD, duplicate name validation, delete permissions (superuser/non-superuser), filters (name/phone), cover image deletion,
    AllFacilityViewSet public endpoint listing & search
    Updated files
  • test_resource_request_api.py — Added CRUD, filtering (status/origin_facility/category/title), assigned_to without assigned_facility validation, comment
    CRUD (create/list/delete)
  • test_file_upload_api.py — Added archive action, list without required params, list with params, invalid MIME type, empty original name, direct upload
    missing fields, file name update
  • test_patient_api.py — Added future deceased_datetime validation, delete as superuser, delete as non-superuser
  • test_encounter_api.py — Added update without permissions, restart completed/non-completed/expired encounter
    Skipped (already comprehensive)

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
    • Expanded test coverage for account management, encounter operations, facility management, file uploads, medication prescriptions, patient records, and resource requests.
    • Added comprehensive validation tests for CRUD operations, access control, filtering, and error handling across multiple API endpoints.

@praffq praffq requested a review from a team as a code owner February 16, 2026 09:16
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 16, 2026

📝 Walkthrough

Walkthrough

This pull request introduces comprehensive Django REST Framework test suites for multiple EMR API viewsets, adding approximately 900 lines of new test coverage across Account, Encounter, Facility, Patient, File Upload, Medication Request Prescription, and Resource Request endpoints.

Changes

Cohort / File(s) Summary
Account & Encounter Tests
care/emr/tests/test_account_api.py, care/emr/tests/test_encounter_api.py
Adds Account viewset test suite covering CRUD operations, unique active account enforcement, filtering, and default account actions; extends Encounter tests with permission validation and encounter restart lifecycle tests (completed, non-completed, expired scenarios).
Facility & Patient Tests
care/emr/tests/test_facility_api.py, care/emr/tests/test_patient_api.py
Introduces comprehensive Facility API tests for CRUD, access control, filtering by name/phone, and public facility visibility; updates Patient tests with future deceased datetime validation and delete operation permission checks for superuser and non-superuser roles.
File Upload & Prescription Tests
care/emr/tests/test_file_upload_api.py, care/emr/tests/test_medication_request_prescription_api.py
Adds file lifecycle tests covering archival, filtering, MIME type validation, and field updates; introduces Medication Request Prescription viewset tests for CRUD operations, status filtering, encounter association, and permission enforcement.
Resource Request Tests
care/emr/tests/test_resource_request_api.py
Expands Resource Request test coverage with CRUD operations, multi-field filtering (status, facility, category, title), assigned facility validation, and introduces new ResourceRequestComment viewset tests for comment lifecycle management.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

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.
Title check ❓ Inconclusive The title 'added pending testcases' is vague and generic, failing to convey which specific tests were added or their purpose despite this being a substantial test expansion across 7 files. Consider a more descriptive title like 'Add comprehensive API test suites for Account, Facility, Patient, and other endpoints' to better reflect the scope and nature of changes.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The description provides detailed coverage of all test files added with specific test cases listed, includes an associated issue link, and follows most template sections with appropriate checkmarks.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into develop

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch prafful/test/pending-testcases

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

Copy link
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 (3)
care/emr/tests/test_file_upload_api.py (1)

186-214: Consider completing the upload before archiving.

Right now the archive path doesn’t exercise the actual blob upload, so this test could start failing if the backend ever enforces file existence on “mark upload completed.” A tiny upload step would make this more future-proof.

care/emr/tests/test_account_api.py (1)

36-48: Make service_period time-agnostic to avoid test time-bombs.

The hard-coded 2025 range is already in the past (current date: 2026-02-16), so any validation that expects a current/forward period will make this test flaky. Consider generating dates relative to timezone.now().

♻️ Example update (dynamic service period)
-from django.urls import reverse
+from datetime import timedelta
+from django.urls import reverse
+from django.utils import timezone
 ...
     def _get_account_data(self, **overrides):
+        now = timezone.now()
         data = {
             "status": AccountStatusOptions.active.value,
             "billing_status": AccountBillingStatusOptions.open.value,
             "name": "Test Account",
             "service_period": {
-                "start": "2025-01-01T00:00:00Z",
-                "end": "2025-12-31T23:59:59Z",
+                "start": (now - timedelta(days=1)).isoformat(),
+                "end": (now + timedelta(days=365)).isoformat(),
             },
             "patient": str(self.patient.external_id),
         }
care/emr/tests/test_patient_api.py (1)

242-286: Split the extra validation block into its own test.

Right now this method mixes delete-permission behavior with a date-of-birth/death validation scenario that’s unrelated, which makes the intent fuzzy. A dedicated test would keep each case crisp.

As per coding guidelines, "Prioritize readability and maintainability; follow Django's coding style guide (PEP 8 compliance)."

@codecov
Copy link

codecov bot commented Feb 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.18%. Comparing base (3c30dc8) to head (6ce3d2d).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3532      +/-   ##
===========================================
+ Coverage    75.32%   76.18%   +0.85%     
===========================================
  Files          473      473              
  Lines        22066    22066              
  Branches      2305     2305              
===========================================
+ Hits         16622    16810     +188     
+ Misses        4926     4736     -190     
- Partials       518      520       +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.

@vigneshhari
Copy link
Member

@nandkishorr Review!

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.

Testcases for EMR

3 participants