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:
Diffstat (limited to 'webapp/polls/tests/structure_tests.py')
-rw-r--r--webapp/polls/tests/structure_tests.py83
1 files changed, 72 insertions, 11 deletions
diff --git a/webapp/polls/tests/structure_tests.py b/webapp/polls/tests/structure_tests.py
index 7508248..c9fe0d9 100644
--- a/webapp/polls/tests/structure_tests.py
+++ b/webapp/polls/tests/structure_tests.py
@@ -7,6 +7,7 @@ from mock import Mock
from utils.test import (MongoTestCase, mock_in_memory_image,
remove_option_images_dir)
from polls.tests.poll_tests import MockImageFileInterface
+from polls.exceptions import ReadOnly
class StructureTests(MongoTestCase):
@@ -162,17 +163,6 @@ class StructureTests(MongoTestCase):
self.assertEqual(1, len(structure.errors))
- def test_save(self):
-
- structure = Structure(data=self.data)
-
- self.assertRaises(structure.ValidationError, structure.save)
-
- structure = Structure(data=self.data, poll=self.poll)
- structure.save()
-
- self.assertEqual(1, self.db.structures.count())
-
def test_get(self):
structure = Structure(data=self.data, poll=self.poll)
structure_id = structure.save()
@@ -321,6 +311,39 @@ class StructureTests(MongoTestCase):
self.assertEqual(1, len(structure.get_image_options()))
+ def test_it_should_respond_to_ready_only_msg(self):
+ self.assertTrue(hasattr(Structure, 'READ_ONLY_MSG'))
+
+
+class ReadOnlyTest(MongoTestCase):
+
+ def setUp(self):
+ poll = Poll({"name": "poll name"})
+ poll_id = poll.save()
+ self.poll = poll.get(poll_id)
+
+ def test_it_should_be_read_only_when_poll_has_results(self):
+ poll = self.poll
+ structure = Structure(data={}, poll=poll)
+ self.assertFalse(poll.has_result())
+ self.assertFalse(structure.is_read_only())
+
+ poll.has_result = Mock(return_value=True)
+ self.assertTrue(poll.has_result())
+ self.assertTrue(structure.is_read_only())
+
+ def test_read_only_when_poll_is_closed_and_has_not_results(self):
+ poll = self.poll
+ poll.status = Poll.CLOSED
+ poll_id = poll.save()
+ poll = poll.get(poll_id)
+
+ structure = Structure(data={}, poll=poll)
+ self.assertFalse(poll.has_result())
+ self.assertFalse(poll.is_open())
+
+ self.assertTrue(structure.is_read_only())
+
class UploadOptionImagesTest(MongoTestCase):
@@ -400,3 +423,41 @@ class UploadOptionImagesTest(MongoTestCase):
def tearDown(self):
remove_option_images_dir()
+
+
+class SaveStructureTest(MongoTestCase):
+
+ def setUp(self):
+ poll = Poll(data={'name': 'name'})
+ poll_id = poll.save()
+
+ self.poll = Poll.get(id=poll_id)
+
+ self.data = {
+ 'poll_id': 'POLL_ID',
+ 'groups': {
+ '0': {
+ 'name': 'group_0',
+ 'fields': {
+ '0': {
+ 'widget_type': Field.TextInput,
+ 'name': 'field_0_0'
+ }
+ }
+ }
+ }
+ }
+
+ def test_save(self):
+ structure = Structure(data=self.data)
+ self.assertRaises(structure.ValidationError, structure.save)
+
+ structure = Structure(data=self.data, poll=self.poll)
+ structure.save()
+ self.assertEqual(1, self.db.structures.count())
+
+ def test_it_should_not_save_if_is_read_only(self):
+ poll = self.poll
+ structure = Structure(data=self.data, poll=poll)
+ structure.is_read_only = Mock(return_value=True)
+ self.assertRaises(ReadOnly, structure.save)