def test_export_progress_updates(self): """ Test that after generate_export is called, we change out state to pending and after its complete, we change it to complete, if we fail between the two, updates, we have failed """ self._publish_transportation_form() # generate an export that fails because of the NoRecordsFound exception export = Export.objects.create(xform=self.xform, export_type=Export.XLS_EXPORT) # check that progress url says pending progress_url = reverse(export_progress, kwargs={ 'username': self.user.username, 'id_string': self.xform.id_string, 'export_type': 'xls' }) params = {'export_ids': [export.id]} response = self.client.get(progress_url, params) status = json.loads(response.content)[0] self.assertEqual(status["complete"], False) self.assertEqual(status["filename"], None) export.internal_status = Export.FAILED export.save() # check that progress url says failed progress_url = reverse(export_progress, kwargs={ 'username': self.user.username, 'id_string': self.xform.id_string, 'export_type': 'xls' }) params = {'export_ids': [export.id]} response = self.client.get(progress_url, params) status = json.loads(response.content)[0] self.assertEqual(status["complete"], True) self.assertEqual(status["filename"], None) # make a submission and create a valid export self._submit_transport_instance() create_xls_export( self.user.username, self.xform.id_string, export.id) params = {'export_ids': [export.id]} response = self.client.get(progress_url, params) status = json.loads(response.content)[0] self.assertEqual(status["complete"], True) self.assertIsNotNone(status["filename"])
def test_create_xls_export_non_existent_id(self): self._publish_transportation_form() # make a submission and create a valid export self._submit_transport_instance() non_existent_id = 42 result = create_xls_export( self.user.username, self.xform.id_string, non_existent_id) self.assertEqual(result, None)