Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/webapp/polls/tests/poll_tests.py
diff options
context:
space:
mode:
authorRogelio Mita <rogeliomita@activitycentral.com>2013-04-25 05:24:41 (GMT)
committer Rogelio Mita <rogeliomita@activitycentral.com>2013-04-25 05:24:41 (GMT)
commitcfe0e9c3e7237332ab39a125257d74caa24905c0 (patch)
treee5a9d1a270310eae983fa3120732d47807baaa68 /webapp/polls/tests/poll_tests.py
parent3b830780849955ac4e24448d972c4f0f78068e5e (diff)
Clone a poll action
Diffstat (limited to 'webapp/polls/tests/poll_tests.py')
-rw-r--r--webapp/polls/tests/poll_tests.py75
1 files changed, 74 insertions, 1 deletions
diff --git a/webapp/polls/tests/poll_tests.py b/webapp/polls/tests/poll_tests.py
index 25f2f5e..17fa215 100644
--- a/webapp/polls/tests/poll_tests.py
+++ b/webapp/polls/tests/poll_tests.py
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
from bson import ObjectId
-from polls.models import Poll
+from polls.models import Poll, Field, Structure
from polls.forms import PollForm
from pollster.models import Pollster
@@ -139,6 +139,79 @@ class PollTests(MongoTestCase):
self.assertEqual(pollster.id, poll2.get_pollster().id)
self.assertIsNone(poll3.get_pollster())
+ # TODO: Mock file system methods
+ def test_clone(self):
+
+ poll = Poll(data={'name': 'name'})
+ poll.status = Poll.CLOSED
+ poll_id = poll.save()
+ poll = Poll.get(poll_id)
+
+ data = {
+ 'groups': {
+ '0': {
+ 'name': 'group_0',
+ 'fields': {
+ '0': {
+ 'widget_type': Field.TextInput,
+ 'name': 'field_0_0'
+ },
+ '1': {
+ 'widget_type': Field.RadioButton,
+ 'name': 'field_0_1'
+ }
+ },
+ },
+ '1': {
+ 'name': 'group_1',
+ 'fields': {
+ '0': {
+ 'widget_type': Field.MultipleCheckBox,
+ 'name': 'field_1_0'
+ },
+ '1': {
+ 'widget_type': Field.DropDownList,
+ 'name': 'field_1_1'
+ }
+ },
+ }
+ }
+ }
+
+ structure = Structure(data=data, poll=poll)
+ structure.save()
+ poll = Poll.get(poll_id)
+
+ poll_clone = poll.clone()
+
+ poll_data = poll.to_python()
+ poll_structure_data = poll.structure.to_python()
+ poll_id = poll_data['_id']
+ del poll_data['_id']
+ del poll_data['name']
+ poll_data['status'] = Poll.OPEN
+ poll_structure_data_id = poll_structure_data['_id']
+ del poll_structure_data['_id']
+
+ poll_clone_data = poll_clone.to_python()
+ poll_clone_structure_data = poll_clone.structure.to_python()
+ poll_clone_id = poll_clone_data['_id']
+ del poll_clone_data['_id']
+ del poll_clone_data['name']
+ poll_clone_structure_data_id = poll_clone_structure_data['_id']
+ del poll_clone_structure_data['_id']
+
+ self.assertIsNotNone(poll_clone_id)
+ self.assertIsNotNone(poll_clone_structure_data_id)
+ self.assertNotEqual(poll_clone_id, poll_id)
+ self.assertEqual('clon-%s' % poll.name, poll_clone.name)
+ self.assertTrue(poll_clone.is_open())
+ self.assertNotEqual(
+ poll_clone_structure_data_id, poll_structure_data_id)
+
+ self.assertEqual(poll_clone_data, poll_data)
+ self.assertEqual(poll_clone_structure_data, poll_structure_data)
+
class PollFormTests(MongoTestCase):