diff options
author | Rogelio Mita <rogeliomita@activitycentral.com> | 2013-09-12 17:06:13 (GMT) |
---|---|---|
committer | Rogelio Mita <rogeliomita@activitycentral.com> | 2013-09-12 17:06:13 (GMT) |
commit | 45e952392e740da72018cb413591e0a09c50c65d (patch) | |
tree | e5a2940a3b6d04b567559c8f8688e1769d00c9c9 /webapp/polls/tests/option_tests.py | |
parent | 713607e49509c1068397420e4d31615ae5218321 (diff) |
Better checking for image options
Diffstat (limited to 'webapp/polls/tests/option_tests.py')
-rw-r--r-- | webapp/polls/tests/option_tests.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/webapp/polls/tests/option_tests.py b/webapp/polls/tests/option_tests.py index 03fe684..b22f4a0 100644 --- a/webapp/polls/tests/option_tests.py +++ b/webapp/polls/tests/option_tests.py @@ -3,7 +3,9 @@ from django.conf import settings from polls.models import Poll, Option -from utils.test import MongoTestCase, mock_in_memory_image, mock_text_file +from utils.test import MongoTestCase, mock_text_file +from polls.tests.poll_tests import MockImageFileInterface +from utils.test import mock_image_file class OptionTests(MongoTestCase): @@ -35,7 +37,7 @@ class OptionTests(MongoTestCase): def test_option_img(self): - img_file = mock_in_memory_image('image.jpg') + img_file = MockImageFileInterface('image.jpg') data = {'id': "1", 'img': img_file} option = Option(data) self.assertEqual(img_file, option.img) @@ -43,7 +45,7 @@ class OptionTests(MongoTestCase): def test_option_img_and_weight(self): - img_file = mock_in_memory_image('image.jpg') + img_file = MockImageFileInterface('image.jpg') data = {'id': "1", 'img': img_file, 'weight': "100"} option = Option(data) self.assertEqual(img_file, option.img) @@ -76,7 +78,7 @@ class OptionTests(MongoTestCase): def test_image_option_get_absolute_path(self): - img_file = mock_in_memory_image(size=(250, 250)) + img_file = MockImageFileInterface(size=(250, 250)) data = {'id': '1', 'img': img_file} option = Option(data, poll=self.poll) @@ -97,30 +99,31 @@ class OptionTests(MongoTestCase): self.assertIsNone(option.img_name) def test_image_option_validation_invalid_size(self): - - invalid_img_file = mock_in_memory_image(size=(300, 200)) + wrong_size = (300, 200) + invalid_img_file = MockImageFileInterface(size=wrong_size) data = {'id': '1', 'img': invalid_img_file} option = Option(data) - self.assertRaises(Option.ValidationError, option.validate) + validator = lambda img: mock_image_file(size=wrong_size) + self.assertRaises(Option.ValidationError, option.validate, validator) msg = u"%s: Se necesita una imagen menor a 250x250." % option.id self.assertTrue(msg in option.errors) self.assertIsNone(option.img) self.assertIsNone(option.img_name) - invalid_img_file = mock_in_memory_image(size=(200, 300)) + invalid_img_file = MockImageFileInterface(size=wrong_size) data = {'id': '1', 'img': invalid_img_file} option = Option(data) - self.assertRaises(Option.ValidationError, option.validate) + self.assertRaises(Option.ValidationError, option.validate, validator) msg = u"%s: Se necesita una imagen menor a 250x250." % option.id self.assertTrue(msg in option.errors) self.assertIsNone(option.img) self.assertIsNone(option.img_name) - img_file = mock_in_memory_image(size=(250, 250)) + img_file = MockImageFileInterface(size=(250, 250)) data = {'id': '1', 'img': img_file} option = Option(data) |