[test]: Backend unit test for the Like operator in QueryOps#8292
Conversation
|
Warning One or more dependencies are approaching or past End-of-Life. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds backend unit tests for ChangesQueryOps LIKE tests
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✨ Finishing Touches🧪 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 (1)
specifyweb/backend/stored_queries/tests/test_query_ops.py (1)
10-28: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider extracting a shared assertion helper to reduce duplication.
All four test methods repeat the same three-step pattern: call
op_like, compile withliteral_binds, assert the SQL string. A small helper would centralize the compile logic and make adding future cases trivial.♻️ Optional refactor
def setUp(self): self.ops = QueryOps(uiformatter=None) + def assert_like_sql(self, value, expected_sql): + result = self.ops.op_like(column("catalogNumber"), value) + sql = str(result.compile(compile_kwargs={"literal_binds": True})) + self.assertEqual(sql, expected_sql) + def test_op_like_basic(self): - result = self.ops.op_like(column("catalogNumber"), "%test%") - sql = str(result.compile(compile_kwargs={"literal_binds": True})) - self.assertEqual(sql, '"catalogNumber" LIKE \'%test%\'') + self.assert_like_sql("%test%", '"catalogNumber" LIKE \'%test%\'') def test_op_like_percent_wildcard(self): - result = self.ops.op_like(column("catalogNumber"), "2025%") - sql = str(result.compile(compile_kwargs={"literal_binds": True})) - self.assertEqual(sql, '"catalogNumber" LIKE \'2025%\'') + self.assert_like_sql("2025%", '"catalogNumber" LIKE \'2025%\'') def test_op_like_underscore_wildcard(self): - result = self.ops.op_like(column("catalogNumber"), "202_") - sql = str(result.compile(compile_kwargs={"literal_binds": True})) - self.assertEqual(sql, '"catalogNumber" LIKE \'202_\'') + self.assert_like_sql("202_", '"catalogNumber" LIKE \'202_\'') def test_op_like_no_wildcard(self): - result = self.ops.op_like(column("catalogNumber"), "exact") - sql = str(result.compile(compile_kwargs={"literal_binds": True})) - self.assertEqual(sql, '"catalogNumber" LIKE \'exact\'') + self.assert_like_sql("exact", '"catalogNumber" LIKE \'exact\'')🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@specifyweb/backend/stored_queries/tests/test_query_ops.py` around lines 10 - 28, Extract the repeated op_like invocation, SQL compilation, and assertion into a shared helper method in the test class, then update test_op_like_basic, test_op_like_percent_wildcard, test_op_like_underscore_wildcard, and test_op_like_no_wildcard to call it with the pattern and expected SQL.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@specifyweb/backend/stored_queries/tests/test_query_ops.py`:
- Around line 10-28: Extract the repeated op_like invocation, SQL compilation,
and assertion into a shared helper method in the test class, then update
test_op_like_basic, test_op_like_percent_wildcard,
test_op_like_underscore_wildcard, and test_op_like_no_wildcard to call it with
the pattern and expected SQL.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 2dce53be-e623-4f01-b7a5-9f3ae72dc36a
📒 Files selected for processing (1)
specifyweb/backend/stored_queries/tests/test_query_ops.py
Fixes #8291
Summary by CodeRabbit
%value%), prefix patterns using%wildcards, single-character matching with_wildcards, and exact (no-wildcard) values.