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']), self.domain, case_upload.upload_id) self.assertIsInstance(res.result, Ignore) update_state.assert_called_with( state=states.FAILURE, meta=get_interned_exception('Sorry, your session has expired. Please start over and try again.')) self.assertEqual(0, len(get_case_ids_in_domain(self.domain)))
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 _import_rows(self, rows, get_by_user_id): get_by_user_id.return_value = WebUser( _id=self.couch_user_id, domain=self.domain, username='******') case_upload_record = CaseUploadRecord( upload_id=uuid.uuid4(), task_id=uuid.uuid4(), domain=self.domain, ) case_upload_record.save() self.addCleanup(case_upload_record.delete) tracker = CaseUpload(case_upload_record.upload_id) # mock internals to have record_cases use our case_upload_record tracker.__dict__['_case_upload_record'] = case_upload_record config = self._get_config(rows[0]) xls_file = make_worksheet_wrapper(*rows) do_import(xls_file, config, self.domain, record_form_callback=tracker.record_form) return case_upload_record
def _import_rows(self, rows, get_by_user_id): get_by_user_id.return_value = WebUser( _id=self.couch_user_id, domain=self.domain, username='******') case_upload_record = CaseUploadRecord( upload_id=uuid.uuid4(), task_id=uuid.uuid4(), domain=self.domain, ) case_upload_record.save() self.addCleanup(case_upload_record.delete) tracker = CaseUpload(case_upload_record.upload_id) # mock internals to have record_cases use our case_upload_record tracker.__dict__['_case_upload_record'] = case_upload_record config = self._get_config(rows[0]) xls_file = make_worksheet_wrapper(*rows) do_import(xls_file, config, self.domain, record_form_callback=tracker.record_form) return case_upload_record