Skip to content

[test]: add permit attachment add and delete#8281

Open
rijulpoudel wants to merge 11 commits into
mainfrom
issue-8268
Open

[test]: add permit attachment add and delete#8281
rijulpoudel wants to merge 11 commits into
mainfrom
issue-8268

Conversation

@rijulpoudel

@rijulpoudel rijulpoudel commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Fixes #8268

Summary by CodeRabbit

  • Tests
    • Expanded coverage for associating attachments with permits and removing those associations cleanly.
    • Added verification that deleting an attachment association also removes its underlying attachment record.
    • Added coverage confirming permits can be deleted successfully when no related records prevent removal.

@github-actions

github-actions Bot commented Jul 8, 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=-71

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

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

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


@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Permit Business Rule Tests

Layer / File(s) Summary
Attachment association cleanup
specifyweb/backend/businessrules/tests/test_permit.py
Tests creating a Permitattachment, verifying its attachment linkage, then deleting the link and underlying attachment.
Unblocked permit deletion
specifyweb/backend/businessrules/tests/test_permit.py
Tests that deleting a permit without blockers removes its database row.

Possibly related PRs

Suggested reviewers: CarolineDenis

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR also adds a separate permit-deletion test that is not required by the linked attachment coverage. Move the permit-deletion test to a separate change or document it as part of the issue scope.
✅ 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 main change: adding permit attachment add/delete test coverage.
Linked Issues check ✅ Passed The new tests cover attachment creation and deletion for permits, matching issue #8268.
Automatic Tests ✅ Passed Yes—this PR adds automatic unit tests in test_permit.py covering permit attachment add/delete and permit deletion.
Testing Instructions ✅ Passed PASS: The permit attachment tests are clear and accurate; Permitattachment triggers the attachment post-delete hook, so the Attachment row deletion assertion is valid.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-8268

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.

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@specifyweb/backend/businessrules/tests/test_permit.py`:
- Around line 126-131: Update the deletion assertions in the test containing
permit_attachment.delete() so they verify the related Attachment row remains
instead of expecting its count to be zero; retain the permitattachments count
assertion and use the existing attachment identifier to assert the row still
exists.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4350207c-6a12-49c1-9561-25f14d5be342

📥 Commits

Reviewing files that changed from the base of the PR and between 077f8a9 and 7fd05d5.

📒 Files selected for processing (1)
  • specifyweb/backend/businessrules/tests/test_permit.py

Comment on lines +126 to +131
# Delete the attachment
permit_attachment.delete()

# Verifying it's gone
self.assertEqual(permit.permitattachments.count(), 0)
self.assertEqual(models.Attachment.objects.filter(id=attachment.id).count(), 0)

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check for post_delete signals connected to Permitattachment
rg -n "post_delete" --type=py -C3 specifyweb/specify/models.py | grep -i -A3 -B3 "permitattachment\|Permitattachment"
rg -n "post_delete" --type=py -C3 specifyweb/ | grep -i -A5 -B5 "permitattachment\|PermitAttachment"
# Also check for any custom delete method on Permitattachment
rg -n "class Permitattachment" --type=py -A30 specifyweb/specify/models.py
# Check signal handlers broadly
rg -n "post_delete" --type=py specifyweb/specify/ | head -30

Repository: specify/specify7

Length of output: 2073


permit_attachment.delete() should not clear the Attachment row. The final assertion should expect the attachment to remain, unless there’s separate cleanup logic that explicitly deletes it; otherwise this test will fail.

🤖 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/businessrules/tests/test_permit.py` around lines 126 -
131, Update the deletion assertions in the test containing
permit_attachment.delete() so they verify the related Attachment row remains
instead of expecting its count to be zero; retain the permitattachments count
assertion and use the existing attachment identifier to assert the row still
exists.

@github-project-automation github-project-automation Bot moved this from 📋Back Log to Dev Attention Needed in General Tester Board Jul 10, 2026
@CarolineDenis CarolineDenis self-requested a review July 10, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Dev Attention Needed

Development

Successfully merging this pull request may close these issues.

[test]: Add unit test for permit attachments (add + delete)

2 participants