Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/webapp/polls/tests/structure_tests.py
diff options
context:
space:
mode:
authorGustavo Duarte <gduarte@activitycentral.com>2013-09-24 21:51:18 (GMT)
committer Gustavo Duarte <gduarte@activitycentral.com>2013-09-24 21:51:18 (GMT)
commit4faac65a6c8d2ce54cfd5c7d2d3fdad2e6d6ebc5 (patch)
tree354fa805814a34d69d49b928667ecd0143783d80 /webapp/polls/tests/structure_tests.py
parentaac682d823f421cd551d23ee1cd907ed35c661a6 (diff)
parent446a86b35595ec1f004e923e318a2be031cce84b (diff)
Create installers for Version 4.19v4.19
Merge branch 'DEV'
Diffstat (limited to 'webapp/polls/tests/structure_tests.py')
-rw-r--r--webapp/polls/tests/structure_tests.py86
1 files changed, 85 insertions, 1 deletions
diff --git a/webapp/polls/tests/structure_tests.py b/webapp/polls/tests/structure_tests.py
index e7ee213..7508248 100644
--- a/webapp/polls/tests/structure_tests.py
+++ b/webapp/polls/tests/structure_tests.py
@@ -1,7 +1,11 @@
# -*- encoding: utf-8 -*-
+import os
+
from polls.models import Poll, Group, Field, Structure
+from mock import Mock
-from utils.test import MongoTestCase, mock_in_memory_image
+from utils.test import (MongoTestCase, mock_in_memory_image,
+ remove_option_images_dir)
from polls.tests.poll_tests import MockImageFileInterface
@@ -316,3 +320,83 @@ class StructureTests(MongoTestCase):
structure = Structure(data=data, poll=poll)
self.assertEqual(1, len(structure.get_image_options()))
+
+
+class UploadOptionImagesTest(MongoTestCase):
+
+ def setUp(self):
+ self.option_id = '131212'
+ self.data = {
+ 'groups': {
+ '0': {
+ 'name': "group name",
+ 'fields': {
+ '0': {
+ 'name': "field_0_0",
+ 'widget_type': Field.ImageCheckBox,
+ 'options': {
+ self.option_id: {
+ 'img': None,
+ 'text': "text",
+ 'order': 0
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ poll = Poll({"name": "poll name"})
+ poll_id = poll.save()
+ self.poll = poll.get(poll_id)
+
+ img_ext = "jpg"
+ self.img_filename = '.'.join([self.option_id, img_ext])
+ self.img = Mock()
+ self.img.chunks = Mock(return_value=['chunk', 'chunk'])
+ self.img.name = self.img_filename
+
+ def test_it_should_save_option_images_with_many_chunks(self):
+ option_id = self.option_id
+ img = self.img
+ img_filename = self.img_filename
+
+ data = self.data
+ data['groups']['0']['fields']['0']['options'][option_id]['img'] = img
+ poll = self.poll
+ structure = Structure(data=data, poll=poll)
+
+ structure.save_image_options()
+
+ images_dir = structure.get_image_options_path()
+ saved_on_disk = os.path.exists(os.path.join(images_dir, img_filename))
+ self.assertTrue(saved_on_disk)
+
+ def test_save_imgs_when_exists_a_valid_structure_with_temp_imgs(self):
+ option_id = self.option_id
+ poll = self.poll
+ data = self.data
+ data_option = data['groups']['0']['fields']['0']['options'][option_id]
+ img_filename = self.img_filename
+ img = self.img
+
+ data_option['img'] = img
+ structure = Structure(data=data, poll=poll)
+ structure.save_image_options(tmp=True)
+ images_tmp_dir = structure.get_image_options_tmp_path()
+ saved_on_tmp_dir = os.path.exists(
+ os.path.join(images_tmp_dir, img_filename))
+ self.assertTrue(saved_on_tmp_dir)
+
+ data = structure.to_python()
+ structure = Structure(data=data, poll=poll)
+ structure.save_image_options(tmp=False)
+
+ images_dir = structure.get_image_options_path()
+ saved_on_right_place = os.path.exists(
+ os.path.join(images_dir, img_filename))
+ self.assertTrue(saved_on_right_place)
+ self.assertFalse(os.path.exists(images_tmp_dir))
+
+ def tearDown(self):
+ remove_option_images_dir()