Skip to content

Commit

Permalink
Add test for self SOFT_DELETE_CASCADE
Browse files Browse the repository at this point in the history
  • Loading branch information
Gagaro committed Aug 21, 2023
1 parent 3804385 commit 6cdd3e8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
21 changes: 21 additions & 0 deletions safedelete/tests/test_soft_delete_cascade.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ class ArticleView(CustomAbstractModel):
article = models.ForeignKey(Article, on_delete=models.CASCADE)


class ParentSelf(SafeDeleteModel):
_safedelete_policy = SOFT_DELETE_CASCADE
parent = models.ForeignKey(
'self',
related_name="children",
on_delete=models.CASCADE,
null=True,
blank=True
)


def pre_softdelete_article(sender, instance, *args, **kwargs):
# Related objects should not be SET before instance was deleted
assert instance.pressnormalmodel_set.count() == 1
Expand Down Expand Up @@ -282,3 +293,13 @@ def test_safe_delete_cascade_generic_foreign_key(self):
child.undelete(force_policy=SOFT_DELETE_CASCADE)
self.assertEqual(ChildGeneric.objects.count(), 1)
self.assertEqual(ParentGeneric.objects.count(), 1)

def test_parent_self_cascade(self):
parent = ParentSelf.objects.create()
ParentSelf.objects.create(parent=parent)
ParentSelf.objects.create(parent=parent)
ParentSelf.objects.create()

self.assertEqual(ParentSelf.objects.all().count(), 4)
parent.delete()
self.assertEqual(ParentSelf.objects.all().count(), 1)
12 changes: 7 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
skipsdist = True
envlist =
{py37}-django-{32}
{py38}-django-{32,40,41}
{py39}-django-{32,40,41}
{py310}-django-{32,40,41}
{py38}-django-{32,40,41,42}
{py39}-django-{32,40,41,42}
{py310}-django-{32,40,41,42}
{py311}-django-{32,40,41,42}
{py310}-isort
{py310}-flake8
{py310}-mypy
Expand All @@ -17,8 +18,9 @@ deps =
django-32: Django>=3.2,<3.3
django-40: Django>=4.0,<4.1
django-41: Django>=4.1,<4.2
django-42: Django>=4.2,<5.0
mypy: mypy
mypy: Django>=4.0,<4.1
mypy: Django>=4.1,<5.0
mypy: django-stubs
mypy: types-setuptools
isort: isort
Expand All @@ -34,7 +36,7 @@ changedir = docs
deps =
sphinx
sphinx_rtd_theme
Django>=3.2,<4.1
Django>=4.2,<5.0
commands =
sphinx-build -W -b html -d build/doctrees . build/html

Expand Down

0 comments on commit 6cdd3e8

Please sign in to comment.