forked from xarg/django-stdimage
-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add delete_orphans keyword in favor of delete signals (#210)
- Loading branch information
Showing
7 changed files
with
148 additions
and
71 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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django import forms | ||
|
||
from . import models | ||
|
||
|
||
class ThumbnailModelForm(forms.ModelForm): | ||
|
||
class Meta: | ||
model = models.ThumbnailModel | ||
fields = '__all__' |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import os | ||
|
||
from tests.test_models import TestStdImage | ||
|
||
from . import forms, models | ||
|
||
|
||
class TestStdImageField(TestStdImage): | ||
|
||
def test_save_form_data__new(self, db): | ||
instance = models.ThumbnailModel.objects.create(image=self.fixtures['100.gif']) | ||
org_path = instance.image.path | ||
assert os.path.exists(org_path) | ||
form = forms.ThumbnailModelForm( | ||
files=dict(image=self.fixtures['600x400.jpg']), | ||
instance=instance, | ||
) | ||
assert form.is_valid() | ||
obj = form.save() | ||
assert obj.image.name == 'img/600x400.jpg' | ||
assert os.path.exists(instance.image.path) | ||
assert not os.path.exists(org_path) | ||
|
||
def test_save_form_data__false(self, db): | ||
instance = models.ThumbnailModel.objects.create(image=self.fixtures['100.gif']) | ||
org_path = instance.image.path | ||
assert os.path.exists(org_path) | ||
form = forms.ThumbnailModelForm( | ||
data={'image-clear': '1'}, | ||
instance=instance, | ||
) | ||
assert form.is_valid() | ||
obj = form.save() | ||
assert obj.image._file is None | ||
assert not os.path.exists(org_path) | ||
|
||
def test_save_form_data__none(self, db): | ||
instance = models.ThumbnailModel.objects.create(image=self.fixtures['100.gif']) | ||
org_path = instance.image.path | ||
assert os.path.exists(org_path) | ||
form = forms.ThumbnailModelForm( | ||
data={'image': None}, | ||
instance=instance, | ||
) | ||
assert form.is_valid() | ||
obj = form.save() | ||
assert obj.image | ||
assert os.path.exists(org_path) |
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