Skip to content

[test]: Backend unit test for creating a record set from multiple entry points#8309

Open
rijulpoudel wants to merge 3 commits into
mainfrom
issue-8308
Open

[test]: Backend unit test for creating a record set from multiple entry points#8309
rijulpoudel wants to merge 3 commits into
mainfrom
issue-8308

Conversation

@rijulpoudel

@rijulpoudel rijulpoudel commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Fixes #8308

Summary by CodeRabbit

  • Tests
    • Added coverage for creating record sets with multiple records.
    • Added coverage for adding individual existing records to record sets.
    • Added coverage for creating record sets from query results and validating record counts.

@github-actions

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=-75

--- 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=840

--- 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=-98

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


@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds RecordSetCreationTests covering recordset creation with multiple existing records, individual record association, and bulk creation from filtered Collectionobject query results.

Changes

Recordset creation test coverage

Layer / File(s) Summary
Recordset creation entry points
specifyweb/specify/tests/test_record_sets.py
Adds ORM imports and tests bulk item creation, single-record association, stored record IDs, and item counts derived from filtered collection-object query results.
🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Testing Instructions ⚠️ Warning The PR leaves the Testing instructions section blank, so there are no clear steps covering the new recordset test paths. Add concrete steps to run the new recordset unit tests and mention the affected backend recordset creation paths (bulk add, single add, query results).
✅ Passed checks (5 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 added backend unit tests for record-set creation from multiple entry points.
Linked Issues check ✅ Passed The new tests cover all requested cases: multiple collection objects, adding an existing record, and query results.
Out of Scope Changes check ✅ Passed The changes stay scoped to the requested test coverage and do not introduce unrelated code changes.
Automatic Tests ✅ Passed The PR adds specifyweb/specify/tests/test_record_sets.py with three test_ methods covering record-set creation scenarios.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-8308

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/specify/tests/test_record_sets.py (1)

62-74: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Optimize query evaluation and strengthen assertions.

You can optimize memory usage by evaluating only the id field using values_list, rather than loading full model instances. Additionally, you could verify that the specific record IDs match, ensuring parity with the first test case.

♻️ Proposed refactor
-        matching_cos = Collectionobject.objects.filter(
-            collection=self.collection
-        )
-
-        Recordsetitem.objects.bulk_create([
-            Recordsetitem(recordset=recordset, recordid=co.id)
-            for co in matching_cos
-        ])
-
-        self.assertEqual(
-            recordset.recordsetitems.count(),
-            matching_cos.count(),
-        )
+        expected_ids = set(
+            Collectionobject.objects.filter(
+                collection=self.collection
+            ).values_list("id", flat=True)
+        )
+
+        Recordsetitem.objects.bulk_create([
+            Recordsetitem(recordset=recordset, recordid=co_id)
+            for co_id in expected_ids
+        ])
+
+        self.assertEqual(recordset.recordsetitems.count(), len(expected_ids))
+
+        rs_item_ids = set(
+            recordset.recordsetitems.values_list("recordid", flat=True)
+        )
+        self.assertEqual(rs_item_ids, expected_ids)
🤖 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/specify/tests/test_record_sets.py` around lines 62 - 74, Update
the matching_cos query in this test to retrieve only collection object IDs via
values_list, and use those IDs when building Recordsetitem instances. Replace or
supplement the count-only assertion with an assertion that the created recordset
item IDs exactly match the queried IDs, preserving the existing parity check.
🤖 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/specify/tests/test_record_sets.py`:
- Around line 62-74: Update the matching_cos query in this test to retrieve only
collection object IDs via values_list, and use those IDs when building
Recordsetitem instances. Replace or supplement the count-only assertion with an
assertion that the created recordset item IDs exactly match the queried IDs,
preserving the existing parity check.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 274c0905-a71d-490e-b7be-5cf327ea5a02

📥 Commits

Reviewing files that changed from the base of the PR and between bc644bc and 3cef5e5.

📒 Files selected for processing (1)
  • specifyweb/specify/tests/test_record_sets.py

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

Labels

None yet

Projects

Status: 📋Back Log

Development

Successfully merging this pull request may close these issues.

[test]: Backend unit test for creating a record set from multiple entry points

2 participants