def testImportNone(self, update_state): res = bulk_import_async.delay(self._config(['anything']), self.domain, None) self.assertIsInstance(res.result, Ignore) update_state.assert_called_with( state=states.FAILURE, meta={'errors': 'Sorry, your session has expired. Please start over and try again.'}) self.assertEqual(0, len(get_case_ids_in_domain(self.domain)))
def trigger_upload(self, domain, config): from corehq.apps.case_importer.tasks import bulk_import_async task = bulk_import_async.delay(config, domain, self.upload_id) original_filename = transient_file_store.get_filename(self.upload_id) with open(self.get_tempfile()) as f: case_upload_file_meta = persistent_file_store.write_file(f, original_filename) CaseUploadRecord( domain=domain, upload_id=self.upload_id, task_id=task.task_id, couch_user_id=config.couch_user_id, case_type=config.case_type, upload_file_meta=case_upload_file_meta, ).save()
def trigger_upload(self, domain, config): from corehq.apps.case_importer.tasks import bulk_import_async task = bulk_import_async.delay(config, domain, self.upload_id) original_filename = transient_file_store.get_filename(self.upload_id) with open(self.get_tempfile(), 'rb') as f: case_upload_file_meta = persistent_file_store.write_file( f, original_filename, domain) CaseUploadRecord( domain=domain, upload_id=self.upload_id, task_id=task.task_id, couch_user_id=config.couch_user_id, case_type=config.case_type, upload_file_meta=case_upload_file_meta, ).save()
def testImportFileMissing(self, update_state): # by using a made up upload_id, we ensure it's not referencing any real file case_upload = CaseUploadRecord(upload_id=str(uuid.uuid4()), task_id=str(uuid.uuid4())) case_upload.save() res = bulk_import_async.delay( self._config(['anything']).to_json(), self.domain, case_upload.upload_id) self.assertIsInstance(res.result, Ignore) update_state.assert_called_with( state=states.FAILURE, meta=get_interned_exception( 'There was an unexpected error retrieving the file you uploaded. ' 'Please try again and contact support if the problem persists.' )) self.assertEqual( 0, len(CommCareCase.objects.get_case_ids_in_domain(self.domain)))
def trigger_upload(self, domain, config, comment=None): """ Save a CaseUploadRecord and trigger a task that runs the upload The task triggered by this must call case_upload.wait_for_case_upload_record() before using it to avoid a race condition. """ from corehq.apps.case_importer.tasks import bulk_import_async original_filename = transient_file_store.get_filename(self.upload_id) with open(self.get_tempfile(), 'rb') as f: case_upload_file_meta = persistent_file_store.write_file( f, original_filename, domain) task = bulk_import_async.delay(config, domain, self.upload_id) CaseUploadRecord( domain=domain, comment=comment, upload_id=self.upload_id, task_id=task.task_id, couch_user_id=config.couch_user_id, case_type=config.case_type, upload_file_meta=case_upload_file_meta, ).save()