diff options
author | Rogelio Mita <rogeliomita@activitycentral.com> | 2013-08-14 19:59:02 (GMT) |
---|---|---|
committer | Rogelio Mita <rogeliomita@activitycentral.com> | 2013-08-14 21:48:02 (GMT) |
commit | 6453051cc951066af9c32fbacba9de62493942f8 (patch) | |
tree | a10a5533f4796e2e4a2ace76f282fb39311b3c75 /webapp/polls/tests/result_tests.py | |
parent | 641766b713b2b376af3ff37310353c1e84362772 (diff) |
issue 4430 - to csv method is sensitive for repeated names questions and options
Diffstat (limited to 'webapp/polls/tests/result_tests.py')
-rw-r--r-- | webapp/polls/tests/result_tests.py | 197 |
1 files changed, 194 insertions, 3 deletions
diff --git a/webapp/polls/tests/result_tests.py b/webapp/polls/tests/result_tests.py index ad7784f..7afd48f 100644 --- a/webapp/polls/tests/result_tests.py +++ b/webapp/polls/tests/result_tests.py @@ -259,9 +259,9 @@ class PollResultTests(MongoTestCase): "pollster_id": "51b0e946421aa90df17182e9", "pollster_username": "encuestador 1", "result": { - "10": { + "100": { "answers": { - "0": { + "10": { "fields": { "0": { "answer": { @@ -353,7 +353,7 @@ class PollResultTests(MongoTestCase): "RUEE;DEPARTAMENTO;NUM_ESC;GRADO;GRUPO;" + "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() @@ -362,6 +362,197 @@ class PollResultTests(MongoTestCase): 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) + + class PollResultShouldBeSortedByGrupoAndFields(MongoTestCase): def test_load_unsorted_and_fetch_should_be_sorted(self): |