Skip to content

Commit

Permalink
Write unit test to check that library with dependents cannot be deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche committed Feb 13, 2024
1 parent c6ef79e commit a99378c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions backend/core/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,3 +1115,30 @@ def test_library_reference_count_must_be_zero_for_library_deletion(
library.delete()

assert Library.objects.count() == 0

@pytest.mark.usefixtures("domain_project_fixture")
def test_library_cannot_be_deleted_if_it_is_a_dependency_of_other_libraries(self):
dependency_library = Library.objects.create(
name="Dependency Library",
description="Dependency Library description",
folder=Folder.get_root_folder(),
locale="en",
version=1,
)
library = Library.objects.create(
name="Library",
description="Library description",
folder=Folder.get_root_folder(),
locale="en",
version=1,
)
library.dependencies.add(dependency_library)

with pytest.raises(ValueError):
dependency_library.delete()

library.delete()
assert Library.objects.count() == 1

dependency_library.delete()
assert Library.objects.count() == 0

0 comments on commit a99378c

Please sign in to comment.