Files
paperless-ngx/src/documents/tests/test_models.py
T
Trenton H 48d97b78bb Chore: Move model factories to the shared test layer (#14170)
The model factories lived in the documents test package, but three other
apps needed them. The AI, mail and testing suites all reached across an app
boundary to import from documents.tests.factories, which made a private test
package into a shared dependency.

The factories now live in the shared testing package, where cross-app use is
the intended use.
2026-09-21 10:57:11 -07:00

25 lines
886 B
Python

import pytest
from documents.models import Correspondent
from documents.models import Document
from paperless_testing.factories import CorrespondentFactory
from paperless_testing.factories import DocumentFactory
@pytest.mark.django_db
class TestDocument:
def test_correspondent_deletion_does_not_cascade(self) -> None:
assert Correspondent.objects.count() == 0
correspondent = CorrespondentFactory.create()
assert Correspondent.objects.count() == 1
assert Document.objects.count() == 0
DocumentFactory.create(correspondent=correspondent)
assert Document.objects.count() == 1
assert Document.objects.first().correspondent is not None
correspondent.delete()
assert Correspondent.objects.count() == 0
assert Document.objects.count() == 1
assert Document.objects.first().correspondent is None