def test_exports_outdated_only_considers_successful_exports(self): self._publish_transportation_form() self._submit_transport_instance() # create a bad export export = Export.objects.create( xform=self.xform, export_type=Export.XLS_EXPORT, internal_status=Export.FAILED) self.assertTrue( Export.exports_outdated(self.xform, export.export_type))
def should_create_new_export(xform, export_type): """Determine whether or not a new export file for this xform and data type should be generated. This legacy logic is really ugly: the exports_outdated() really should *not* be a classmethod of Export, but doing it incrementally like this for now, until can do a more thorough overhaul later. """ from odk_viewer.models import Export # ugly! return Export.exports_outdated(xform, export_type=export_type)
def test_last_submission_time_empty(self): self._publish_transportation_form() self._submit_transport_instance() # create export export = generate_export(Export.XLS_EXPORT, 'xls', self.user.username, self.xform.id_string) # set time of last submission to None export.time_of_last_submission = None export.save() self.assertTrue(Export.exports_outdated(xform=self.xform, export_type=Export.XLS_EXPORT))
def test_last_submission_time_on_export(self): self._publish_transportation_form() self._submit_transport_instance() # create export xls_export = generate_export(Export.XLS_EXPORT, 'xls', self.user.username, self.xform.id_string) num_exports = Export.objects.filter(xform=self.xform, export_type=Export.XLS_EXPORT).count() # check that our function knows there are no more submissions self.assertFalse(Export.exports_outdated(xform=self.xform, export_type=Export.XLS_EXPORT)) # force new last submission date on xform last_submission = self.xform.surveys.order_by('-date_created')[0] last_submission.date_created += datetime.timedelta(hours=1) last_submission.save() # check that our function knows data has changed self.assertTrue(Export.exports_outdated(xform=self.xform, export_type=Export.XLS_EXPORT)) # check that requesting list url will generate a new export export_list_url = reverse(export_list, kwargs={ 'username': self.user.username, 'id_string': self.xform.id_string, 'export_type': Export.XLS_EXPORT }) response = self.client.get(export_list_url) self.assertEqual(Export.objects.filter(xform=self.xform, export_type=Export.XLS_EXPORT).count(), num_exports + 1) # make sure another export type causes auto-generation num_exports = Export.objects.filter(xform=self.xform, export_type=Export.CSV_EXPORT).count() export_list_url = reverse(export_list, kwargs={ 'username': self.user.username, 'id_string': self.xform.id_string, 'export_type': Export.CSV_EXPORT }) response = self.client.get(export_list_url) self.assertEqual(Export.objects.filter(xform=self.xform, export_type=Export.CSV_EXPORT).count(), num_exports + 1)
def should_create_new_export(xform, export_type): from odk_viewer.models import Export if Export.objects.filter(xform=xform, export_type=export_type).count() == 0\ or Export.exports_outdated(xform, export_type=export_type): return True return False