Skip to content

Commit

Permalink
Add test for ImageField
Browse files Browse the repository at this point in the history
  • Loading branch information
treyhunner committed Apr 21, 2013
1 parent 3ac8f69 commit c6768d6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"Development Status :: 5 - Production/Stable",
"Framework :: Django",
],
tests_require=["Django>=1.3", "webtest", "django-webtest"],
tests_require=["Django>=1.3", "webtest", "django-webtest", "pillow"],
test_suite='runtests.main',
)
5 changes: 5 additions & 0 deletions simple_history/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ class FileModel(models.Model):
history = HistoricalRecords()


class ImageModel(models.Model):
file = models.ImageField(upload_to='images')
history = HistoricalRecords()


register(User, app='simple_history.tests', manager_name='histories')
10 changes: 9 additions & 1 deletion simple_history/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User

from .models import Poll, Choice, Restaurant, FileModel
from .models import Poll, Choice, Restaurant, FileModel, ImageModel


today = datetime(2021, 1, 1, 10, 0)
Expand Down Expand Up @@ -123,6 +123,14 @@ def test_file_field(self):
self.assertEqual(create_record.file, 'files/name')
self.assertEqual(update_record.file, '')

def test_image_field(self):
model = ImageModel.objects.create(file=ContentFile('img', name='name'))
self.assertEqual(model.file.name, 'images/name')
model.file.delete()
update_record, create_record = model.history.all()
self.assertEqual(create_record.file, 'images/name')
self.assertEqual(update_record.file, '')

def test_inheritance(self):
pizza_place = Restaurant.objects.create(name='Pizza Place', rating=3)
pizza_place.rating = 4
Expand Down

0 comments on commit c6768d6

Please sign in to comment.