Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/webapp
diff options
context:
space:
mode:
authorCode Raguet <ignacio.code@gmail.com>2013-09-25 21:56:20 (GMT)
committer Code Raguet <ignacio.code@gmail.com>2013-09-25 21:56:20 (GMT)
commitc2231e95bab8c5a9d2d63ded8ccec58bdec1977f (patch)
treee0c2bbba9848eee89bdadd6aced8c4629f203682 /webapp
parentb118f6619c97906106edb9bca4162b0fe1898bb5 (diff)
check if structure is not read only before save
Diffstat (limited to 'webapp')
-rw-r--r--webapp/polls/models.py3
-rw-r--r--webapp/polls/tests/structure_tests.py7
2 files changed, 10 insertions, 0 deletions
diff --git a/webapp/polls/models.py b/webapp/polls/models.py
index d254e3b..18e126b 100644
--- a/webapp/polls/models.py
+++ b/webapp/polls/models.py
@@ -25,6 +25,7 @@ from utils.mongo_document import Document
from utils.strings import multiple_replace
from pollster.models import Pollster
+from polls.exceptions import ReadOnly
def is_image_file(value):
@@ -1180,6 +1181,8 @@ class Structure(AbstractObject, ComponentStructure):
# Prepare dbref to poll object
if not self.poll:
raise ValidationError("Need a parent poll.")
+ elif self.is_read_only():
+ raise ReadOnly(Structure.READ_ONLY_MSG)
else:
dbref = DBRef(Poll.collection_name, ObjectId(self.poll.id))
_dict.update({'poll': dbref})
diff --git a/webapp/polls/tests/structure_tests.py b/webapp/polls/tests/structure_tests.py
index a7857f4..aeb8702 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):
@@ -434,3 +435,9 @@ class SaveStructureTest(MongoTestCase):
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)