Skip to content

Commit

Permalink
fix: remove subtree when removing scope
Browse files Browse the repository at this point in the history
  • Loading branch information
czosel committed Apr 21, 2022
1 parent 40a82b6 commit fc1e4ff
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
26 changes: 26 additions & 0 deletions emeis/core/migrations/0009_alter_scope_parent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 3.2.12 on 2022-04-21 07:24

from django.db import migrations
import django.db.models.deletion
import mptt.fields


class Migration(migrations.Migration):

dependencies = [
("emeis_core", "0008_scope_is_active"),
]

operations = [
migrations.AlterField(
model_name="scope",
name="parent",
field=mptt.fields.TreeForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="children",
to="emeis_core.scope",
),
),
]
2 changes: 1 addition & 1 deletion emeis/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class Scope(MPTTModel, UUIDModel):
)
parent = TreeForeignKey(
"self",
on_delete=models.SET_NULL,
on_delete=models.CASCADE,
null=True,
blank=True,
related_name="children",
Expand Down
16 changes: 16 additions & 0 deletions emeis/core/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ def test_scope_model(db):
parent_scope.save()


def test_scope_deletion(db, scope_factory):
root = scope_factory() # not deleted
child = scope_factory(parent=root)
grandchild = scope_factory(parent=child)
scope_factory(parent=grandchild)
scope_factory(parent=grandchild)

other_child = scope_factory(parent=root) # not deleted
scope_factory(parent=other_child) # not deleted

child.delete()

assert Scope.objects.count() == 3
assert list(Scope.objects.root_nodes()) == [root]


def test_can_authenticate(db, user):
# Test whether the authentication mechanism works correctly
user.set_password("test_password")
Expand Down

0 comments on commit fc1e4ff

Please sign in to comment.