def test_generated_sections(self):
     self._publish_single_level_repeat_form()
     self._submit_fixture_instance("new_repeats", "01")
     xls_df_builder = XLSDataFrameBuilder(self.user.username,
                                          self.xform.id_string)
     expected_section_keys = [self.survey_name, u"kids_details"]
     section_keys = xls_df_builder.sections.keys()
     self.assertEqual(sorted(expected_section_keys), sorted(section_keys))
 def test_query_mongo(self):
     """
     Test querying for record count and records using
     AbstractDataFrameBuilder._query_mongo
     """
     self._publish_single_level_repeat_form()
     # submit 3 instances
     for i in range(3):
         self._submit_fixture_instance("new_repeats", "01")
     df_builder = XLSDataFrameBuilder(self.user.username,
                                      self.xform.id_string)
     record_count = df_builder._query_mongo(count=True)
     self.assertEqual(record_count, 3)
     cursor = df_builder._query_mongo()
     records = [record for record in cursor]
     self.assertTrue(len(records), 3)
     # test querying using limits
     cursor = df_builder._query_mongo(start=2, limit=2)
     records = [record for record in cursor]
     self.assertTrue(len(records), 1)
Beispiel #3
0
 def test_query_mongo(self):
     """
     Test querying for record count and records using
     AbstractDataFrameBuilder._query_mongo
     """
     self._publish_single_level_repeat_form()
     # submit 3 instances
     for i in range(3):
         self._submit_fixture_instance("new_repeats", "01")
     df_builder = XLSDataFrameBuilder(self.user.username,
                                      self.xform.id_string)
     record_count = df_builder._query_mongo(count=True)
     self.assertEqual(record_count, 3)
     cursor = df_builder._query_mongo()
     records = [record for record in cursor]
     self.assertTrue(len(records), 3)
     # test querying using limits
     cursor = df_builder._query_mongo(start=2, limit=2)
     records = [record for record in cursor]
     self.assertTrue(len(records), 1)
Beispiel #4
0
 def test_xlsx_output_when_data_exceeds_limits(self):
     self._publish_xls_fixture_set_xform("xlsx_output")
     self._submit_fixture_instance("xlsx_output", "01")
     xls_builder = XLSDataFrameBuilder(username=self.user.username,
                                       id_string=self.xform.id_string)
     self.assertEqual(xls_builder.exceeds_xls_limits, True)
     # test that the view returns an xlsx file instead
     url = reverse('xls_export', kwargs={
         'username': self.user.username,
         'id_string': self.xform.id_string
     })
     self.response = self.client.get(url)
     self.assertEqual(self.response.status_code, 200)
     self.assertEqual(self.response["content-type"],
                      'application/vnd.openxmlformats')
Beispiel #5
0
 def test_xlsx_export_for_repeats(self):
     """
     Make sure exports run fine when the xlsx file has multiple sheets
     """
     self._publish_xls_fixture_set_xform("new_repeats")
     self._submit_fixture_instance("new_repeats", "01")
     XLSDataFrameBuilder(username=self.user.username,
                         id_string=self.xform.id_string)
     # test that the view returns an xlsx file instead
     url = reverse('xls_export', kwargs={
         'username': self.user.username,
         'id_string': self.xform.id_string
     })
     params = {
         'xlsx': 'true'  # force xlsx
     }
     self.response = self.client.get(url, params)
     self.assertEqual(self.response.status_code, 200)
     self.assertEqual(self.response["content-type"],
                      'application/vnd.openxmlformats')
 def _xls_data_for_dataframe(self):
     xls_df_builder = XLSDataFrameBuilder(self.user.username,
                                          self.xform.id_string)
     cursor = xls_df_builder._query_mongo()
     return xls_df_builder._format_for_dataframe(cursor)
Beispiel #7
0
 def _xls_data_for_dataframe(self):
     xls_df_builder = XLSDataFrameBuilder(self.user.username,
                                          self.xform.id_string)
     cursor = xls_df_builder._query_mongo()
     return xls_df_builder._format_for_dataframe(cursor)