Testcases for valuesets#3612
Conversation
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
📝 WalkthroughWalkthroughAdds 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 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_concept→mock_code_concept.I'm sure
mokeis a perfectly valid word somewhere, but in the context of Python testing,mocktends to be the convention. This typo appears consistently in all threelookup_codetests.✏️ 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
📒 Files selected for processing (1)
care/emr/tests/test_valueset_api.py
ohcnetwork/roadmap#253
Merge Checklist
/docsOnly 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