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-06-07 18:22:57 (GMT)
committer Rogelio Mita <rogeliomita@activitycentral.com>2013-06-07 18:22:57 (GMT)
commit40999feb0c94c68fff3b827304fff2ec1a0a79ee (patch)
tree96b954f3cd03b3b45f1c116b4fc082210411b73a /webapp/polls/tests/poll_tests.py
parent708a7ee7600ec3e878f8428e6400c2100f69e1f2 (diff)
When a pollster download a poll assigned to him, that poll must have pollster's id.
Diffstat (limited to 'webapp/polls/tests/poll_tests.py')
-rw-r--r--webapp/polls/tests/poll_tests.py106
1 files changed, 106 insertions, 0 deletions
diff --git a/webapp/polls/tests/poll_tests.py b/webapp/polls/tests/poll_tests.py
index bb4b5a6..8b74abc 100644
--- a/webapp/polls/tests/poll_tests.py
+++ b/webapp/polls/tests/poll_tests.py
@@ -1,4 +1,7 @@
# -*- encoding: utf-8 -*-
+import json
+import warnings
+
from bson import ObjectId
from polls.models import Poll, Field, Structure
@@ -249,6 +252,109 @@ class PollTests(MongoTestCase):
self.assertEqual(poll_clone_data, poll_data)
self.assertEqual(poll_clone_structure_data, poll_structure_data)
+ def test_get_template(self):
+
+ pollster = Pollster.create(username="test", password="test")
+
+ poll_data = {
+ "name": "test",
+ "pollsters": [pollster],
+ "status": Poll.OPEN
+ }
+
+ structure_data = {
+ 'groups': {
+ '0': {
+ 'name': 'group_0',
+ 'fields': {
+ '0': {
+ 'widget_type': Field.TextInput,
+ 'name': 'field_0_0',
+ 'options': {
+ '1': {
+ 'text': 'Default text'
+ }
+ },
+ }
+ }
+ }
+ }
+ }
+
+ poll = Poll(data=poll_data)
+ poll_id = poll.save()
+ poll = Poll.get(poll_id)
+ structure = Structure(data=structure_data, poll=poll)
+ structure.save()
+
+ template = poll.get_template()
+
+ expected_dict = {
+ 'groups': structure.to_python()['groups'],
+ 'poll_id': str(poll.id),
+ 'poll_name': poll.name,
+ 'pollster_id': None,
+ 'pollster_username': None,
+ }
+ expected = json.dumps(
+ expected_dict,
+ sort_keys=True,
+ indent=4,
+ separators=(',', ': '),
+ ensure_ascii=False
+ )
+
+ self.assertEqual(expected, template)
+
+ template = poll.get_template(pollster=pollster)
+
+ expected_dict = {
+ 'groups': structure.to_python()['groups'],
+ 'poll_id': str(poll.id),
+ 'poll_name': poll.name,
+ 'pollster_id': str(pollster.id),
+ 'pollster_username': pollster.username,
+ }
+ expected = json.dumps(
+ expected_dict,
+ sort_keys=True,
+ indent=4,
+ separators=(',', ': '),
+ ensure_ascii=False
+ )
+
+ self.assertEqual(expected, template)
+
+ new_pollster = Pollster.create(username="test1", password="test1")
+
+ with warnings.catch_warnings(record=True) as w:
+ # Cause all warnings to always be triggered.
+ warnings.simplefilter("always")
+ # Trigger a warning.
+ template = poll.get_template(pollster=new_pollster)
+ # Verify some things
+ assert len(w) == 1
+ assert issubclass(w[-1].category, Warning)
+ assert "Pollster given not belongs to this poll" in str(
+ w[-1].message)
+
+ expected_dict = {
+ 'groups': structure.to_python()['groups'],
+ 'poll_id': str(poll.id),
+ 'poll_name': poll.name,
+ 'pollster_id': str(new_pollster.id),
+ 'pollster_username': new_pollster.username,
+ }
+ expected = json.dumps(
+ expected_dict,
+ sort_keys=True,
+ indent=4,
+ separators=(',', ': '),
+ ensure_ascii=False
+ )
+
+ self.assertEqual(expected, template)
+
class PollFormTests(MongoTestCase):