Skip to content

[test]: Backend unit test for the Like operator in QueryOps#8292

Merged
CarolineDenis merged 6 commits into
mainfrom
issue-8291
Jul 13, 2026
Merged

[test]: Backend unit test for the Like operator in QueryOps#8292
CarolineDenis merged 6 commits into
mainfrom
issue-8291

Conversation

@rijulpoudel

@rijulpoudel rijulpoudel commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Fixes #8291

Summary by CodeRabbit

  • Tests
    • Added automated unit test coverage for search pattern matching behavior.
    • Verified support for contains-style patterns (e.g., %value%), prefix patterns using % wildcards, single-character matching with _ wildcards, and exact (no-wildcard) values.

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown

Warning

One or more dependencies are approaching or past End-of-Life.
Please plan upgrades accordingly.

STATUS=WARNING
NODE_VERSION=20
NODE_CYCLE=20
EOL_DATE=2026-04-30
DAYS_REMAINING=-74

--- Node.js ---
Version: 20
EOL: 2026-04-30
Status: WARNING

STATUS=OK
PYTHON_VERSION=3.12
PYTHON_CYCLE=3.12
EOL_DATE=2028-10-31
DAYS_REMAINING=841

--- Python ---
Version: 3.12
EOL: 2028-10-31
Status: OK

STATUS=WARNING
DJANGO_VERSION=4.2
DJANGO_CYCLE=4.2
EOL_DATE=2026-04-07
DAYS_REMAINING=-97

--- Django ---
Version: 4.2
EOL: 2026-04-07
Status: WARNING


@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b2b39caa-b77b-462a-b6ac-7c71bd63adb0

📥 Commits

Reviewing files that changed from the base of the PR and between 966aa35 and d702a89.

📒 Files selected for processing (1)
  • specifyweb/backend/stored_queries/tests/test_query_ops.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • specifyweb/backend/stored_queries/tests/test_query_ops.py

📝 Walkthrough

Walkthrough

Adds backend unit tests for QueryOps.op_like, covering SQL compilation with percent wildcards, underscore wildcards, and exact input values.

Changes

QueryOps LIKE tests

Layer / File(s) Summary
LIKE expression test coverage
specifyweb/backend/stored_queries/tests/test_query_ops.py
Adds a QueryOps test fixture and checks compiled SQL for four op_like input patterns.
🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding backend unit tests for QueryOps LIKE behavior.
Linked Issues check ✅ Passed The new tests cover QueryOps.op_like patterns as requested by issue #8291.
Out of Scope Changes check ✅ Passed The PR appears limited to relevant test coverage with no unrelated code changes.
Automatic Tests ✅ Passed The PR adds a new unittest module covering QueryOps.op_like with four cases, so it includes automatic test coverage.
Testing Instructions ✅ Passed The new TestQueryOps cases clearly and directly cover QueryOps.op_like, with focused assertions for the affected component and no unrelated scope.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-8291

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
specifyweb/backend/stored_queries/tests/test_query_ops.py (1)

10-28: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider extracting a shared assertion helper to reduce duplication.

All four test methods repeat the same three-step pattern: call op_like, compile with literal_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

📥 Commits

Reviewing files that changed from the base of the PR and between 192882b and 966aa35.

📒 Files selected for processing (1)
  • specifyweb/backend/stored_queries/tests/test_query_ops.py

@CarolineDenis CarolineDenis merged commit 2194759 into main Jul 13, 2026
20 checks passed
@github-project-automation github-project-automation Bot moved this from 📋Back Log to ✅Done in General Tester Board Jul 13, 2026
@CarolineDenis CarolineDenis deleted the issue-8291 branch July 13, 2026 07:13
@CarolineDenis CarolineDenis added this to the 7.12.1 milestone Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅Done

Development

Successfully merging this pull request may close these issues.

[test]: Backend unit test for the Like operator in QueryOps

2 participants