Beispiel #1
0
 def test_parse_xls_form_blatantly_invalid(self):
     with open("iaso/tests/fixtures/odk_form_blatantly_invalid.xls",
               "rb") as xls_file:
         with self.assertRaises(ParsingError) as cm:
             parse_xls_form(xls_file)
         self.assertEqual(
             str(cm.exception),
             "Invalid XLS file: The survey sheet is either empty or missing important column headers.",
         )
Beispiel #2
0
 def test_parse_xls_form_invalid_version_same_as_previous(self):
     with open("iaso/tests/fixtures/odk_form_valid_sample1_2020022401.xls",
               "rb") as xls_file:
         with self.assertRaises(ParsingError) as cm:
             parse_xls_form(xls_file, previous_version="2020022401")
         self.assertEqual(
             str(cm.exception),
             "Invalid XLS file: Parsed version should be greater than previous version."
         )
Beispiel #3
0
 def test_parse_xls_form_invalid_version(self):
     with open("iaso/tests/fixtures/odk_form_invalid_version.xls",
               "rb") as xls_file:
         with self.assertRaises(ParsingError) as cm:
             parse_xls_form(xls_file)
         self.assertEqual(
             str(cm.exception),
             "Invalid XLS file: Invalid version (must be a string of 1-10 numbers)."
         )
Beispiel #4
0
    def test_parse_xls_form_autogenerate_100th_version_of_the_day(
            self, now_mock):
        now_mock.return_value = parse_datetime("2020-02-24T10:00:00Z")

        with open("iaso/tests/fixtures/odk_form_valid_sample1_no_version.xls",
                  "rb") as xls_file:
            with self.assertRaises(ParsingError) as cm:
                parse_xls_form(xls_file, previous_version="2020022499")
            self.assertEqual(str(cm.exception),
                             "Invalid XLS file: Too many versions.")
Beispiel #5
0
    def test_parse_xls_form_autogenerate_first_version(self, now_mock):
        now_mock.return_value = parse_datetime("2020-02-24T10:00:00Z")

        with open("iaso/tests/fixtures/odk_form_valid_sample1_no_version.xls",
                  "rb") as xls_file:
            survey = parse_xls_form(xls_file)

        self.assertEqual(survey.version, "2020022401")
Beispiel #6
0
    def test_parse_xls_form_valid_no_settings(self):
        with open("iaso/tests/fixtures/odk_form_valid_no_settings.xls",
                  "rb") as xls_file:
            survey = parse_xls_form(xls_file)

        self.assertIsInstance(survey, Survey)
        xml_content = survey.to_xml()
        self.assertIsInstance(xml_content, bytes)
        self.assertGreater(len(xml_content), 100)
        self.assertEqual(survey.form_id, "odk_form_valid_no_settings")
        self.assertIsInstance(survey.version, str)
Beispiel #7
0
    def test_parse_xls_form_valid(self):
        with open("iaso/tests/fixtures/odk_form_valid_sample1_2020022401.xls",
                  "rb") as xls_file:
            survey = parse_xls_form(xls_file)

        self.assertIsInstance(survey, Survey)
        self.assertEqual(survey.generate_file_name("xml"),
                         "odk_form_valid_sample1_2020022401.xml")
        xml_content = survey.to_xml()
        self.assertIsInstance(xml_content, bytes)
        self.assertGreater(len(xml_content), 100)
        # check correctness of root data key
        self.assertIn(f'<data id="sample1" version="2020022401">',
                      xml_content.decode("utf-8"))
        self.assertEqual(survey.form_id, "sample1")
        self.assertEqual(survey.version, "2020022401")