def test_type_conversion(self):
        submission_1 = {
            "_id": 579827,
            "geolocation": "-1.2625482 36.7924794 0.0 21.0",
            "_bamboo_dataset_id": "",
            "meta/instanceID": "uuid:2a8129f5-3091-44e1-a579-bed2b07a12cf",
            "name": "Smith",
            "formhub/uuid": "633ec390e024411ba5ce634db7807e62",
            "_submission_time": "2013-07-03T08:25:30",
            "age": "107",
            "_uuid": "2a8129f5-3091-44e1-a579-bed2b07a12cf",
            "when": "2013-07-03",
            "amount": "250.0",
            "_geolocation": [
                "-1.2625482",
                "36.7924794"
            ],
            "_xform_id_string": "test_data_types",
            "_userform_id": "larryweya_test_data_types",
            "_status": "submitted_via_web",
            "precisely": "2013-07-03T15:24:00.000+03",
            "really": "15:24:00.000+03"
        }

        submission_2 = {
            "_id": 579828,
            "_submission_time": "2013-07-03T08:26:10",
            "_uuid": "5b4752eb-e13c-483e-87cb-e67ca6bb61e5",
            "_bamboo_dataset_id": "",
            "_xform_id_string": "test_data_types",
            "_userform_id": "larryweya_test_data_types",
            "_status": "submitted_via_web",
            "meta/instanceID": "uuid:5b4752eb-e13c-483e-87cb-e67ca6bb61e5",
            "formhub/uuid": "633ec390e024411ba5ce634db7807e62",
            "amount": "",
        }

        survey = create_survey_from_xls(viewer_fixture_path(
            'test_data_types/test_data_types.xls'))
        export_builder = ExportBuilder()
        export_builder.set_survey(survey)
        # format submission 1 for export
        survey_name = survey.name
        indices = {survey_name: 0}
        data = dict_to_joined_export(submission_1, 1, indices, survey_name)
        new_row = export_builder.pre_process_row(data[survey_name],
                                                 export_builder.sections[0])
        self.assertIsInstance(new_row['age'], int)
        self.assertIsInstance(new_row['when'], datetime.date)
        self.assertIsInstance(new_row['amount'], float)

        # check missing values dont break and empty values return blank strings
        indices = {survey_name: 0}
        data = dict_to_joined_export(submission_2, 1, indices, survey_name)
        new_row = export_builder.pre_process_row(data[survey_name],
                                                 export_builder.sections[0])
        self.assertIsInstance(new_row['amount'], basestring)
        self.assertEqual(new_row['amount'], '')
Exemple #2
0
    def test_type_conversion(self):
        submission_1 = {
            "_id": 579827,
            "geolocation": "-1.2625482 36.7924794 0.0 21.0",
            "_bamboo_dataset_id": "",
            "meta/instanceID": "uuid:2a8129f5-3091-44e1-a579-bed2b07a12cf",
            "name": "Smith",
            "formhub/uuid": "633ec390e024411ba5ce634db7807e62",
            "_submission_time": "2013-07-03T08:25:30",
            "age": "107",
            "_uuid": "2a8129f5-3091-44e1-a579-bed2b07a12cf",
            "when": "2013-07-03",
            "amount": "250.0",
            "_geolocation": [
                "-1.2625482",
                "36.7924794"
            ],
            "_xform_id_string": "test_data_types",
            "_userform_id": "larryweya_test_data_types",
            "_status": "submitted_via_web",
            "precisely": "2013-07-03T15:24:00.000+03",
            "really": "15:24:00.000+03"
        }

        submission_2 = {
            "_id": 579828,
            "_submission_time": "2013-07-03T08:26:10",
            "_uuid": "5b4752eb-e13c-483e-87cb-e67ca6bb61e5",
            "_bamboo_dataset_id": "",
            "_xform_id_string": "test_data_types",
            "_userform_id": "larryweya_test_data_types",
            "_status": "submitted_via_web",
            "meta/instanceID": "uuid:5b4752eb-e13c-483e-87cb-e67ca6bb61e5",
            "formhub/uuid": "633ec390e024411ba5ce634db7807e62",
            "amount": "",
        }

        survey = create_survey_from_xls(viewer_fixture_path(
            'test_data_types/test_data_types.xls'))
        export_builder = ExportBuilder()
        export_builder.set_survey(survey)
        # format submission 1 for export
        survey_name = survey.name
        indices = {survey_name: 0}
        data = dict_to_joined_export(submission_1, 1, indices, survey_name)
        new_row = export_builder.pre_process_row(data[survey_name],
                                                 export_builder.sections[0])
        self.assertIsInstance(new_row['age'], int)
        self.assertIsInstance(new_row['when'], datetime.date)
        self.assertIsInstance(new_row['amount'], float)

        # check missing values dont break and empty values return blank strings
        indices = {survey_name: 0}
        data = dict_to_joined_export(submission_2, 1, indices, survey_name)
        new_row = export_builder.pre_process_row(data[survey_name],
                                                 export_builder.sections[0])
        self.assertIsInstance(new_row['amount'], basestring)
        self.assertEqual(new_row['amount'], '')
 def test_xls_convert_dates_before_1900(self):
     survey = create_survey_from_xls(viewer_fixture_path("test_data_types/test_data_types.xls"))
     export_builder = ExportBuilder()
     export_builder.set_survey(survey)
     data = [{"name": "Abe", "when": "1899-07-03"}]
     # create export file
     temp_xls_file = NamedTemporaryFile(suffix=".xlsx")
     export_builder.to_xls_export(temp_xls_file.name, data)
     temp_xls_file.close()
Exemple #4
0
 def test_xls_convert_dates_before_1900(self):
     survey = create_survey_from_xls(
         viewer_fixture_path('test_data_types/test_data_types.xls'))
     export_builder = ExportBuilder()
     export_builder.set_survey(survey)
     data = [{
         'name': 'Abe',
         'when': '1899-07-03',
     }]
     # create export file
     temp_xls_file = NamedTemporaryFile(suffix='.xlsx')
     export_builder.to_xls_export(temp_xls_file.name, data)
     temp_xls_file.close()
 def test_xls_convert_dates_before_1900(self):
     survey = create_survey_from_xls(viewer_fixture_path(
         'test_data_types/test_data_types.xls'))
     export_builder = ExportBuilder()
     export_builder.set_survey(survey)
     data = [
         {
             'name': 'Abe',
             'when': '1899-07-03',
         }
     ]
     # create export file
     temp_xls_file = NamedTemporaryFile(suffix='.xlsx')
     export_builder.to_xls_export(temp_xls_file.name, data)
     temp_xls_file.close()
Exemple #6
0
 def test_csv_http_response(self):
     self._publish_transportation_form()
     survey = self.surveys[0]
     self._make_submission(
         os.path.join(
             self.this_directory, 'fixtures', 'transportation',
             'instances', survey, survey + '.xml'),
         forced_submission_time=self._submission_time)
     response = self.client.get(reverse(
         'csv_export',
         kwargs={
             'username': self.user.username,
             'id_string': self.xform.id_string
         }))
     self.assertEqual(response.status_code, 200)
     test_file_path = viewer_fixture_path('transportation.csv')
     content = self._get_response_content(response)
     with open(test_file_path, 'r') as test_file:
         self.assertEqual(content, test_file.read())