Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/webapp/polls/tests/result_tests.py
diff options
context:
space:
mode:
authorCode Raguet <ignacio.code@gmail.com>2013-07-17 14:48:39 (GMT)
committer Code Raguet <ignacio.code@gmail.com>2013-07-17 16:23:09 (GMT)
commit54d4ade34a8577a604aba77ca97b3b275e446a07 (patch)
tree2b05255c2cd04673b720b9fea240eedc809fa4c3 /webapp/polls/tests/result_tests.py
parent4f13e859ac5565aac957c702a5f67614c9a89641 (diff)
CSV with sorted columns (#4160)
Diffstat (limited to 'webapp/polls/tests/result_tests.py')
-rw-r--r--webapp/polls/tests/result_tests.py176
1 files changed, 169 insertions, 7 deletions
diff --git a/webapp/polls/tests/result_tests.py b/webapp/polls/tests/result_tests.py
index acd43e9..6ec4fdb 100644
--- a/webapp/polls/tests/result_tests.py
+++ b/webapp/polls/tests/result_tests.py
@@ -182,7 +182,7 @@ class PollResultTests(MongoTestCase):
}
}
},
- "0": {
+ "10": {
"name": "Questions that admit only one answer",
"fields": {
"1": {
@@ -255,7 +255,7 @@ class PollResultTests(MongoTestCase):
"pollster_id": "51b0e946421aa90df17182e9",
"pollster_username": "encuestador 1",
"result": {
- "0": {
+ "10": {
"answers": {
"0": {
"fields": {
@@ -346,15 +346,177 @@ class PollResultTests(MongoTestCase):
poll_result = PollResult(data=result_data)
+ # expected_header = unicode(
+ # "RUEE;DEPARTAMENTO;NUM_ESC;GRADO;GRUPO;" +
+ # "TIPO_GRUPO;Q: TextInput con ácento;Q: RadioButton con ácento;" +
+ # "Q: DropDownList;" +
+ # "Q: ImageRadioButton;option 1;option 2;" +
+ # "1370786178812;1370786178813;", 'utf-8')
expected_header = unicode(
"RUEE;DEPARTAMENTO;NUM_ESC;GRADO;GRUPO;" +
- "TIPO_GRUPO;Q: TextInput con ácento;Q: RadioButton con ácento;" +
- "Q: DropDownList;" +
- "Q: ImageRadioButton;option 1;option 2;" +
- "1370786178812;1370786178813;", 'utf-8')
+ "TIPO_GRUPO;option 1;option 2;1370786178812;1370786178813;" +
+ "Q: TextInput con ácento;Q: RadioButton con ácento;" +
+ "Q: DropDownList;Q: ImageRadioButton;", 'utf-8')
self.assertEqual(expected_header, poll_result.get_csv_header())
csv = poll_result.to_csv()
- record = "1101236;MONTEVIDEO;236;2;A;1;some text;1;1;1;1;2;1;;"
+ record = "1101236;MONTEVIDEO;236;2;A;1;1;2;1;;some text;1;1;1;"
self.assertTrue(expected_header in csv)
self.assertTrue(record in csv)
+
+
+class PollResultShouldBeSortedByGrupoAndFields(MongoTestCase):
+
+ def test_load_unsorted_and_fetch_should_be_sorted(self):
+ field_1_1_3 = {
+ "answer": {
+ "1370787034900": {
+ "text": "some text"
+ }
+ },
+ "name": "Q: TextInput con ácento",
+ "widget_type": "TextInput"
+ }
+ field_1_1_1 = {
+ "answer": {
+ "1370786178802": {
+ "text": "option 1",
+ "weight": 1
+ }
+ },
+ "name": "Q: RadioButton con ácento",
+ "widget_type": "RadioButton"
+ }
+ field_1_1_0 = {
+ "answer": {
+ "1370786178804": {
+ "text": "option 1",
+ "weight": 1
+ }
+ },
+ "name": "Q: DropDownList",
+ "widget_type": "DropDownList"
+ }
+ field_1_1_2 = {
+ "answer": {
+ "1370786178806": {
+ "type": "img_input",
+ "weight": 1
+ }
+ },
+ "name": "Q: ImageRadioButton",
+ "widget_type": "ImageRadioButton"
+ }
+ field_1_0_0 = {
+ "answer": {
+ "1370786178809": {
+ "text": "option 1",
+ "weight": 1
+ },
+ "1370786178810": {
+ "text": "option 2",
+ "weight": 2
+ }
+ },
+ "name": "Q: CheckBox",
+ "widget_type": "MultipleCheckBox"
+ }
+ field_1_0_1 = {
+ "answer": {
+ "1370786178812": {
+ "type": "img_input",
+ "weight": 1
+ }
+ },
+ "name": "Q: ImageCheckBox",
+ "widget_type": "ImageCheckBox"
+ }
+ field_0_1_3 = field_1_1_3
+ field_0_0_1 = field_1_0_1
+ result_data = {
+ "poll_id": "poll_id",
+ "poll_name": "",
+ "poll_type": "general",
+ "pollster_id": "51b0e946421aa90df17182e9",
+ "pollster_username": "encuestador 1",
+ "result": {
+ "1": {
+ "answers": {
+ "1": {
+ "fields": {
+ "3": field_1_1_3,
+ "1": field_1_1_1,
+ "0": field_1_1_0,
+ "2": field_1_1_2,
+ },
+ "name": "Questions that admit only one answer"
+ },
+ "0": {
+ "fields": {
+ "0": field_1_0_0,
+ "1": field_1_0_1
+ },
+ "name": "Questions that admit many answers"
+ }
+ },
+ "polled": {
+ "DEPARTAMENTO": "MONTEVIDEO",
+ "GRADO": "2",
+ "GRUPO": "A",
+ "ID": "0",
+ "NUM_ESC": "236",
+ "RUEE": "1101236",
+ "TIPO_GRUPO": "1"
+ }
+ },
+ "0": {
+ "answers": {
+ "1": {
+ "fields": {
+ "3": field_0_1_3
+ },
+ "name": "Questions that admit only one answer"
+ },
+ "0": {
+ "fields": {
+ "1": field_0_0_1
+ },
+ "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)
+ results = poll_result.sorted()
+
+ sorted_answers = []
+ sorted_result = []
+ for a_result in results:
+ sorted_result.append(a_result.id)
+ for answer in a_result.sorted():
+ sorted_answers.append(answer)
+
+ expected_result = ['0', '1']
+ self.assertListEqual(expected_result, sorted_result)
+
+ expected_answers = [
+ field_0_0_1,
+ field_0_1_3,
+ field_1_0_0,
+ field_1_0_1,
+ field_1_1_0,
+ field_1_1_1,
+ field_1_1_2,
+ field_1_1_3,
+ ]
+ self.assertListEqual(expected_answers, sorted_answers)