diff options
author | Rogelio Mita <rogeliomita@activitycentral.com> | 2013-06-08 20:39:45 (GMT) |
---|---|---|
committer | Rogelio Mita <rogeliomita@activitycentral.com> | 2013-06-10 17:47:31 (GMT) |
commit | 22dab872c03af7b53b2d5da8f5e531715e89c35a (patch) | |
tree | 206d7b7ee979fb842c27108063920be134371be3 /webapp/polls/tests/result_tests.py | |
parent | 0fb480fae92f51528d0d95754751451c34c57374 (diff) |
Web system can export poll results to csv file.
Diffstat (limited to 'webapp/polls/tests/result_tests.py')
-rw-r--r-- | webapp/polls/tests/result_tests.py | 229 |
1 files changed, 227 insertions, 2 deletions
diff --git a/webapp/polls/tests/result_tests.py b/webapp/polls/tests/result_tests.py index a72be04..c8b2ee3 100644 --- a/webapp/polls/tests/result_tests.py +++ b/webapp/polls/tests/result_tests.py @@ -1,10 +1,11 @@ # -*- encoding: utf-8 -*- -from polls.models import Poll, PollResult +from polls.models import Poll, PollResult, Structure +from pollster.models import Pollster from utils.test import MongoTestCase -class PollTests(MongoTestCase): +class PollResultTests(MongoTestCase): """ data = @@ -131,3 +132,227 @@ class PollTests(MongoTestCase): len(data_1['result']) + len(data_2['result']), len(poll_result._data['result']) ) + + def test_to_csv(self): + + pollster = Pollster.create(username="test", password="test") + + poll_data = { + "name": "test", + "pollsters": [pollster], + "status": Poll.CLOSED + } + + structure_data = { + "groups": { + "1": { + "name": "Questions that admit many answers", + "fields": { + "1": { + "widget_type": "ImageCheckBox", + "dependence": {}, + "name": "Q: ImageCheckBox", + "options": { + "1370786178812": { + "img_name": "1370786178812.jpg", + "type": "img_input", + "weight": 1 + }, + "1370786178813": { + "img_name": "1370786178813.jpg", + "type": "img_input", + "weight": 2 + } + } + }, + "0": { + "widget_type": "MultipleCheckBox", + "dependence": {}, + "name": "Q: MultipleCheckBox", + "options": { + "1370786178809": { + "text": "option 1", + "weight": 1 + }, + "1370786178810": { + "text": "option 2", + "weight": 2 + } + } + } + } + }, + "0": { + "name": "Questions that admit only one answer", + "fields": { + "1": { + "widget_type": "RadioButton", + "dependence": {}, + "name": "Q: RadioButton", + "options": { + "1370786178803": { + "text": "option 2", + "weight": 2 + }, + "1370786178802": { + "text": "option 1", + "weight": 1 + } + } + }, + "0": { + "widget_type": "TextInput", + "name": "Q: TextInput", + "options": {} + }, + "3": { + "widget_type": "ImageRadioButton", + "dependence": {}, + "name": "Q: ImageRadioButton", + "options": { + "1370786178807": { + "img_name": "1370786178807.jpg", + "type": "img_input", + "weight": 2 + }, + "1370786178806": { + "img_name": "1370786178806.jpg", + "type": "img_input", + "weight": 1 + } + } + }, + "2": { + "widget_type": "DropDownList", + "dependence": {}, + "name": "Q: DropDownList", + "options": { + "1370786178805": { + "text": "option 2", + "weight": 2 + }, + "1370786178804": { + "text": "option 1", + "weight": 1 + } + } + } + } + } + } + } + + poll = Poll(data=poll_data) + poll_id = poll.save() + poll = Poll.get(poll_id) + structure = Structure(data=structure_data, poll=poll) + structure.save() + + result_data = { + "poll_id": str(poll_id), + "poll_name": "", + "poll_type": "general", + "pollster_id": "51b0e946421aa90df17182e9", + "pollster_username": "encuestador 1", + "result": { + "0": { + "answers": { + "0": { + "fields": { + "0": { + "answer": { + "1370787034900": { + "text": "some text" + } + }, + "name": "Q: TextIntup", + "widget_type": "TextInput" + }, + "1": { + "answer": { + "1370786178802": { + "text": "option 1", + "weight": 1 + } + }, + "name": "Q: RadioButton", + "widget_type": "RadioButton" + }, + "2": { + "answer": { + "1370786178804": { + "text": "option 1", + "weight": 1 + } + }, + "name": "Q: DropDownList", + "widget_type": "DropDownList" + }, + "3": { + "answer": { + "1370786178806": { + "type": "img_input", + "weight": 1 + } + }, + "name": "Q: ImageRadioButton", + "widget_type": "ImageRadioButton" + } + }, + "name": "Questions that admit only one answer" + }, + "1": { + "fields": { + "0": { + "answer": { + "1370786178809": { + "text": "option 1", + "weight": 1 + }, + "1370786178810": { + "text": "option 2", + "weight": 2 + } + }, + "name": "Q: CheckBox", + "widget_type": "MultipleCheckBox" + }, + "1": { + "answer": { + "1370786178812": { + "type": "img_input", + "weight": 1 + } + }, + "name": "Q: ImageCheckBox", + "widget_type": "ImageCheckBox" + } + }, + "name": "Questions that admit many answers" + } + }, + "polled": { + "DEPARTAMENTO": "MONTEVIDEO", + "GRADO": "2", + "GRUPO": "A", + "ID": "0", + "NUM_ESC": "236", + "RUEE": "1101236", + "TIPO_GRUPO": "1" + } + } + } + } + + poll_result = PollResult(data=result_data) + + expected_header = "RUEE;DEPARTAMENTO;NUM_ESC;GRADO;GRUPO;" + \ + "TIPO_GRUPO;Q: TextInput;Q: RadioButton;Q: DropDownList;" + \ + "Q: ImageRadioButton;1370786178809;1370786178810;" + \ + "1370786178812;1370786178813;" + self.assertEqual(expected_header, poll_result.get_csv_header()) + + csv = poll_result.to_csv() + record = "1101236;MONTEVIDEO;236;2;A;1;;1;1;1;1;2;1;;" + self.assertTrue(expected_header in csv) + self.assertTrue(record in csv) |