Пример #1
0
 def test_allow_export_download_for_basic_auth(self):
     extra = {
         'HTTP_AUTHORIZATION': http_auth_string(self.login_username,
             self.login_password)
     }
     # create export
     export = create_csv_export(self.user.username, self.xform.id_string)
     self.assertTrue(isinstance(export, Export))
     url = reverse(export_download, kwargs={
         'username': self.user.username,
         'id_string': self.xform.id_string,
         'export_type': export.export_type,
         'filename': export.filename
     })
     response = self.anon.get(url, **extra)
     self.assertEqual(response.status_code, 200)
Пример #2
0
 def test_duplicate_export_filename_is_renamed(self):
     self._publish_transportation_form()
     self._submit_transport_instance()
     # create an export object in the db
     # TODO: only works if the time we time we generate the basename is exact to the second with the time the 2nd export is created
     basename = "%s_%s" % (self.xform.id_string,
                           datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S"))
     filename = basename + ".csv"
     export = Export.objects.create(xform=self.xform,
         export_type=Export.CSV_EXPORT, filename=filename)
     # 2nd export
     export_2 = create_csv_export(username=self.user.username,
         id_string=self.xform.id_string)
     if export.created_on.timetuple() == export_2.created_on.timetuple():
         new_filename = increment_index_in_filename(filename)
         self.assertEqual(new_filename, export_2.filename)
     else:
         stdout.write("duplicate export filename test skipped because export times differ.")
Пример #3
0
 def test_404_on_export_io_error(self):
     """
     Test that we return a 404 when the response_with_mimetype_and_name encounters an IOError
     """
     self._publish_transportation_form()
     self._submit_transport_instance()
     export = create_csv_export(username=self.user.username,
         id_string=self.xform.id_string)
     export_url = reverse(export_download, kwargs={
         "username": self.user.username,
         "id_string": self.xform.id_string,
         "export_type": Export.CSV_EXPORT,
         "filename": export.filename
     })
     # delete the export
     export.delete()
     # access the export
     response = self.client.get(export_url)
     self.assertEqual(response.status_code, 404)
Пример #4
0
 def test_export_download_url(self):
     self._publish_transportation_form()
     self._submit_transport_instance()
     export = create_csv_export(username=self.user.username,
         id_string=self.xform.id_string)
     csv_export_url = reverse(export_download, kwargs={
         "username": self.user.username,
         "id_string": self.xform.id_string,
         "export_type": Export.CSV_EXPORT,
         "filename": export.filename
     })
     response = self.client.get(csv_export_url)
     self.assertEqual(response.status_code, 200)
     # test xls
     export = create_xls_export(username=self.user.username,
         id_string=self.xform.id_string)
     xls_export_url = reverse(export_download, kwargs={
         "username": self.user.username,
         "id_string": self.xform.id_string,
         "export_type": Export.XLS_EXPORT,
         "filename": export.filename
     })
     response = self.client.get(xls_export_url)
     self.assertEqual(response.status_code, 200)