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:
Diffstat (limited to 'webapp/polls/tests/result_tests.py')
-rw-r--r--webapp/polls/tests/result_tests.py221
1 files changed, 208 insertions, 13 deletions
diff --git a/webapp/polls/tests/result_tests.py b/webapp/polls/tests/result_tests.py
index 9a646ba..7afd48f 100644
--- a/webapp/polls/tests/result_tests.py
+++ b/webapp/polls/tests/result_tests.py
@@ -153,15 +153,17 @@ class PollResultTests(MongoTestCase):
"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
+ "weight": 2,
+ "order": "1"
+ },
+ "1370786178812": {
+ "img_name": "1370786178812.jpg",
+ "type": "img_input",
+ "weight": 1,
+ "order": "2"
}
}
},
@@ -172,11 +174,13 @@ class PollResultTests(MongoTestCase):
"options": {
"1370786178809": {
"text": "option 1",
- "weight": 1
+ "weight": 1,
+ "order": "1"
},
"1370786178810": {
"text": "option 2",
- "weight": 2
+ "weight": 2,
+ "order": "2"
}
}
}
@@ -255,9 +259,9 @@ class PollResultTests(MongoTestCase):
"pollster_id": "51b0e946421aa90df17182e9",
"pollster_username": "encuestador 1",
"result": {
- "10": {
+ "100": {
"answers": {
- "0": {
+ "10": {
"fields": {
"0": {
"answer": {
@@ -347,13 +351,204 @@ class PollResultTests(MongoTestCase):
poll_result = PollResult(data=result_data)
expected_header = unicode(
"RUEE;DEPARTAMENTO;NUM_ESC;GRADO;GRUPO;" +
- "TIPO_GRUPO;option 1;option 2;1370786178812;1370786178813;" +
+ "TIPO_GRUPO;option 1;option 2;1370786178813;1370786178812;" +
"Q: TextInput con ácento;Q: RadioButton con ácento;" +
- "Q: DropDownList;Q: ImageRadioButton;", 'utf-8')
+ "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;1;2;1;;some text;1;1;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 CsvNoRepitePesoParaOpcionesConElMismoTextDescriptivo(MongoTestCase):
+ """
+ issue 4430
+ """
+
+ def setUp(self):
+ poll_data = {
+ "name": "test",
+ "status": Poll.CLOSED
+ }
+
+ question_name = "repite nombre pregunta"
+ structure_data = {
+ "groups": {
+ "0": {
+ "name": "grupo 1",
+ "fields": {
+ "0": {
+ "widget_type": "MultipleCheckBox",
+ "name": "pregunta 1",
+ "options": {
+ "1": {
+ "text": "no repite 1",
+ "weight": 1,
+ "order": "0"
+ },
+ "2": {
+ "text": "se repite",
+ "weight": 2,
+ "order": "1"
+ }
+ }
+ },
+ "1": {
+ "widget_type": "MultipleCheckBox",
+ "name": "pregunta 2",
+ "options": {
+ "1": {
+ "text": "no repite 2",
+ "weight": 3,
+ "order": "0"
+ },
+ "2": {
+ "text": "se repite",
+ "weight": 10,
+ "order": "1"
+ }
+ }
+ },
+ "2": {
+ "widget_type": "TextInput",
+ "name": question_name,
+ "options": {
+ "0": {
+ "text": "texto 1",
+ "weight": 5,
+ "order": "0"
+ }
+ }
+ },
+ "3": {
+ "widget_type": "TextInput",
+ "name": question_name,
+ "options": {
+ "0": {
+ "text": "texto 2",
+ "weight": 1,
+ "order": "0"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ poll = Poll(data=poll_data)
+ poll_id = poll.save()
+ self.poll = Poll.get(poll_id)
+ structure = Structure(data=structure_data, poll=self.poll)
+ structure.save()
+
+ def test_get_csv_header_with_order(self):
+ poll = self.poll
+
+ poll_header = poll.get_csv_header(with_order=True)
+
+ expected_header = unicode(
+ "0_0 no repite 1;0_0 se repite;" +
+ "0_1 no repite 2;0_1 se repite;" +
+ "0_2 repite nombre pregunta;0_3 repite nombre pregunta",
+ 'utf-8')
+
+ self.assertEqual(expected_header, poll_header)
+
+ def test_to_csv(self):
+
+ poll = self.poll
+
+ question_name = "repite nombre pregunta"
+ result_data = {
+ "poll_id": str(poll.id),
+ "poll_name": "",
+ "poll_type": "general",
+ "pollster_id": "cualquiera",
+ "pollster_username": "cualquiera",
+ "result": {
+ "0": {
+ "answers": {
+ "0": {
+ "name": "grupo 1",
+ "fields": {
+ "0": {
+ "widget_type": "MultipleCheckBox",
+ "name": "pregunta 1",
+ "answer": {
+ "1": {
+ "text": "no repite 1",
+ "weight": 1,
+ "order": "0"
+ },
+ "2": {
+ "text": "se repite",
+ "weight": 2,
+ "order": "1"
+ }
+ }
+ },
+ "1": {
+ "widget_type": "MultipleCheckBox",
+ "name": "pregunta 2",
+ "answer": {
+ "1": {
+ "text": "no repite 2",
+ "weight": 3,
+ "order": "0"
+ }
+ }
+ },
+ "2": {
+ "widget_type": "TextInput",
+ "name": question_name,
+ "answer": {
+ "0": {
+ "text": "texto 1",
+ "weight": 5,
+ "order": "0"
+ }
+ }
+ },
+ "3": {
+ "widget_type": "TextInput",
+ "name": question_name,
+ "answer": {
+ "0": {
+ "text": "texto 2",
+ "weight": 1,
+ "order": "0"
+ }
+ }
+ }
+ }
+ }
+ },
+ "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 = unicode(
+ "RUEE;DEPARTAMENTO;NUM_ESC;GRADO;GRUPO;TIPO_GRUPO;" +
+ "no repite 1;se repite;no repite 2;se repite;" +
+ question_name + ";" + question_name + ";",
+ 'utf-8')
+ csv = poll_result.to_csv()
+
+ record = "1101236;MONTEVIDEO;236;2;A;1;1;2;3;;texto 1;texto 2;"
self.assertTrue(expected_header in csv)
self.assertTrue(record in csv)