forked from django-cms/django-filer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: File.objects.only("id") query when deleting a user (django-cms#1357
) * Fix: Failing js test * Fix Flie.objects.only("id") query refs django-cms#1290 * Add test for deleting users --------- Co-authored-by: William Lindholm <[email protected]>
- Loading branch information
Showing
3 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,9 +35,11 @@ def tearDown(self): | |
for f in File.objects.all(): | ||
f.delete() | ||
|
||
def create_filer_image(self): | ||
def create_filer_image(self, owner=None): | ||
if owner is None: | ||
owner = self.superuser | ||
file_obj = DjangoFile(open(self.filename, 'rb'), name=self.image_name) | ||
image = Image.objects.create(owner=self.superuser, | ||
image = Image.objects.create(owner=owner, | ||
original_filename=self.image_name, | ||
file=file_obj) | ||
return image | ||
|
@@ -307,3 +309,22 @@ def test_canonical_url_settings(self): | |
image.save() | ||
canonical = image.canonical_url | ||
self.assertTrue(canonical.startswith('/filer/test-path/')) | ||
|
||
def test_delete_user_who_owns_file(self): | ||
"""Tests if deleting users who own files works""" | ||
from django.contrib.auth.models import User | ||
|
||
user = User.objects.create( | ||
username="test", | ||
password="top-secret", | ||
email="[email protected]", | ||
is_staff=True, | ||
) | ||
image = self.create_filer_image(user) | ||
|
||
user.delete() | ||
|
||
# User needs to be gone | ||
self.assertEqual(len(User.objects.filter(username="test")), 0) | ||
# Image remains w/o owner | ||
self.assertIsNone(File.objects.get(pk=image.pk).owner) |