Skip to content

Testcases for valuesets#3612

Open
nandkishorr wants to merge 8 commits intodevelopfrom
fix/tests/valuesets
Open

Testcases for valuesets#3612
nandkishorr wants to merge 8 commits intodevelopfrom
fix/tests/valuesets

Conversation

@nandkishorr
Copy link
Copy Markdown
Contributor

@nandkishorr nandkishorr commented Mar 31, 2026

ohcnetwork/roadmap#253

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 ValueSet API endpoints, including permission handling, search functionality, code validation, and user preferences.

@nandkishorr nandkishorr self-assigned this Mar 31, 2026
@nandkishorr nandkishorr requested a review from a team as a code owner March 31, 2026 06:50
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 Mar 31, 2026

📝 Walkthrough

Walkthrough

Adds a new Django test module with comprehensive test coverage for the ValueSet API, introducing eight test classes that verify permission-gated CRUD operations, action endpoints (expand, preview_search, validate_code, lookup_code), and feature management (favorites and recent views).

Changes

Cohort / File(s) Summary
ValueSet API Test Suite
care/emr/tests/test_valueset_api.py
New test module with shared base class and eight test classes covering API permissions (list/retrieve/create/update/delete), expand action with language handling, preview_search with query parameters, validate_code verification, lookup_code functionality with CodeConceptResource mocking, favorites management (add/remove/clear/list), and recent views tracking (add/remove/list/clear).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete—it references an issue link but omits the 'Proposed Changes' section that should detail what was actually added, making it difficult to understand the scope. Add a 'Proposed Changes' section describing the test classes and coverage added (permissions, expand, preview_search, validate_code, lookup_code, favorites, recent_views), then complete all checklist items.
Docstring Coverage ⚠️ Warning Docstring coverage is 10.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 'Testcases for valuesets' is somewhat vague and generic, lacking specificity about which aspects or test coverage is being added. Consider a more descriptive title that highlights the specific test coverage added, such as 'Add comprehensive API tests for ValueSet CRUD, actions, and preferences'.

✏️ 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 fix/tests/valuesets

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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 (2)
care/emr/tests/test_valueset_api.py (2)

611-615: Add a docstring for consistency with other test classes.

Every other test class in this file has a descriptive docstring. It would be a shame if this one felt left out.

📝 Suggested fix
 class TestValueSetRecentViews(ValueSetTestBase):
+    """Tests for recent_views, add_recent_view, remove_recent_view, clear_recent_views actions."""
+
     `@patch.object`(ValueSet, "lookup", return_value=True)
     def test_add_recent_view(self, mock_lookup):
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@care/emr/tests/test_valueset_api.py` around lines 611 - 615, Add a
descriptive docstring to the TestValueSetRecentViews test class (class
TestValueSetRecentViews) to match the style of other test classes in the file;
place a short one-line or multi-line string immediately under the class
declaration that briefly describes the test group's purpose (e.g., "Tests for
recent view handling on ValueSet endpoints"), keeping tone and format consistent
with neighboring test classes' docstrings.

383-432: Fix typo in mock parameter name: moke_code_conceptmock_code_concept.

I'm sure moke is a perfectly valid word somewhere, but in the context of Python testing, mock tends to be the convention. This typo appears consistently in all three lookup_code tests.

✏️ Suggested fix
 class TestValueSetLookupCode(ValueSetTestBase):
     """Tests for the lookup_code action."""

     `@patch`("care.emr.api.viewsets.valueset.CodeConceptResource")
-    def test_lookup_code_found(self, moke_code_concept):
+    def test_lookup_code_found(self, mock_code_concept):
         mock_resource = MagicMock()
         mock_filtered = MagicMock()
         mock_resource.filter.return_value = mock_filtered
         mock_filtered.get.return_value = {
             "code": "123",
             "system": "http://snomed.info/sct",
             "display": "Test",
         }
-        moke_code_concept.return_value = mock_resource
+        mock_code_concept.return_value = mock_resource
         url = reverse("value-set-lookup-code")
         payload = {"code": "123", "system": "http://snomed.info/sct"}
         response = self.client.post(url, payload, format="json")
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.json()["code"], "123")

     `@patch`("care.emr.api.viewsets.valueset.CodeConceptResource")
-    def test_lookup_code_not_found(self, moke_code_concept):
+    def test_lookup_code_not_found(self, mock_code_concept):
         mock_resource = MagicMock()
         mock_filtered = MagicMock()
         mock_resource.filter.return_value = mock_filtered
         mock_filtered.get.side_effect = ValueError("No results found")
-        moke_code_concept.return_value = mock_resource
+        mock_code_concept.return_value = mock_resource
         url = reverse("value-set-lookup-code")
         payload = {"code": "999", "system": "http://snomed.info/sct"}
         response = self.client.post(url, payload, format="json")
         self.assertEqual(response.status_code, 404)
         self.assertEqual(
             response.json()["error"],
             "No results found for the given system and code",
         )

     `@patch`("care.emr.api.viewsets.valueset.CodeConceptResource")
-    def test_lookup_code_as_regular_user(self, moke_code_concept):
+    def test_lookup_code_as_regular_user(self, mock_code_concept):
         user = self.create_user()
         self.client.force_authenticate(user=user)
         mock_resource = MagicMock()
         mock_filtered = MagicMock()
         mock_resource.filter.return_value = mock_filtered
         mock_filtered.get.return_value = {"code": "123"}
-        moke_code_concept.return_value = mock_resource
+        mock_code_concept.return_value = mock_resource
         url = reverse("value-set-lookup-code")
         payload = {"code": "123", "system": "http://snomed.info/sct"}
         response = self.client.post(url, payload, format="json")
         self.assertEqual(response.status_code, 200)

As per coding guidelines: "Use descriptive variable and function names; adhere to naming conventions."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@care/emr/tests/test_valueset_api.py` around lines 383 - 432, Rename the
misspelled mock parameter `moke_code_concept` to `mock_code_concept` in the
TestValueSetLookupCode tests (methods test_lookup_code_found,
test_lookup_code_not_found, test_lookup_code_as_regular_user) and update all
uses (e.g., `moke_code_concept.return_value = mock_resource`) to
`mock_code_concept.return_value = mock_resource` so the `@patch-provided` mock is
referenced with the conventional name.
🤖 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_valueset_api.py`:
- Around line 611-615: Add a descriptive docstring to the
TestValueSetRecentViews test class (class TestValueSetRecentViews) to match the
style of other test classes in the file; place a short one-line or multi-line
string immediately under the class declaration that briefly describes the test
group's purpose (e.g., "Tests for recent view handling on ValueSet endpoints"),
keeping tone and format consistent with neighboring test classes' docstrings.
- Around line 383-432: Rename the misspelled mock parameter `moke_code_concept`
to `mock_code_concept` in the TestValueSetLookupCode tests (methods
test_lookup_code_found, test_lookup_code_not_found,
test_lookup_code_as_regular_user) and update all uses (e.g.,
`moke_code_concept.return_value = mock_resource`) to
`mock_code_concept.return_value = mock_resource` so the `@patch-provided` mock is
referenced with the conventional name.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4d524435-b789-44f3-91f9-ca660565f634

📥 Commits

Reviewing files that changed from the base of the PR and between c691750 and 0621feb.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant