def study_delete_req(study_id, user_id): """Delete a given study Parameters ---------- study_id : int Study id to delete user_id : str User requesting the deletion Returns ------- dict Status of deletion, in the format {status: status, message: message} """ access_error = check_access(study_id, user_id) if access_error: return access_error status = 'success' try: Study.delete(int(study_id)) msg = '' except Exception as e: status = 'error' msg = 'Unable to delete study: %s' % str(e) return {'status': status, 'message': msg}
def study_delete_req(study_id, user_id): """Delete a given study Parameters ---------- study_id : int Study id to delete user_id : str User requesting the deletion Returns ------- dict Status of deletion, in the format {status: status, message: message} """ access_error = check_access(study_id, user_id) if access_error: return access_error status = 'success' try: Study.delete(int(study_id)) msg = '' except Exception as e: status = 'error' msg = 'Unable to delete study: %s' % str(e) return { 'status': status, 'message': msg }
def delete_study(self, study, user, callback): """Delete study Parameters ---------- study : Study The current study object user : User The current user object callback : function The callback function to call with the results once the processing is done and it fails """ study_id = study.id study_title = study.title try: Study.delete(study_id) # redirecting to list but also passing messages # we need to change the request.method to GET self.request.method = 'GET' ListStudiesHandler(self.application, self.request)._execute( [t(self.request) for t in self.application.transforms], message=('Study "%s" has been deleted' % study_title), msg_level='success') except Exception as e: msg = "Couldn't remove study %d: %s" % (study_id, str(e)) msg_level = "danger" callback((msg, msg_level, 'study_information_tab', None, None))
def delete_study(self, study, user, callback): """Delete study Parameters ---------- study : Study The current study object user : User The current user object callback : function The callback function to call with the results once the processing is done and it fails """ study_id = study.id study_title = study.title try: Study.delete(study_id) # redirecting to list but also passing messages # we need to change the request.method to GET self.request.method = 'GET' ListStudiesHandler(self.application, self.request)._execute( [t(self.request) for t in self.application.transforms], message=('Study "%s" has been deleted' % study_title), msg_level='success') except Exception as e: msg = "Couldn't remove study %d: %s" % (study_id, str(e)) msg_level = "danger" callback((msg, msg_level, 'study_information_tab', None, None))
def tearDown(self): for fp in self._clean_up_files: if exists(fp): remove(fp) study_id = self.new_study.id for pt in self.new_study.prep_templates(): PrepTemplate.delete(pt.id) if SampleTemplate.exists(study_id): SampleTemplate.delete(study_id) Study.delete(study_id)
def test_delete(self): title = "Fried chicken microbiome" study = Study.create(User('*****@*****.**'), title, [1], self.info) study.delete(study.id) self.assertFalse(study.exists(title)) with self.assertRaises(QiitaDBError): Study.delete(1) with self.assertRaises(QiitaDBUnknownIDError): Study.delete(41)
def tearDown(self): for fp in self._clean_up_files: if exists(fp): remove(fp) study_id = self.new_study.id for pt in self.new_study.prep_templates(): PrepTemplate.delete(pt.id) if SampleTemplate.exists(study_id): SampleTemplate.delete(study_id) Study.delete(study_id)
def test_delete(self): title = "Fried chicken microbiome" # the study is assigned to investigation 1 study = Study.create(User("*****@*****.**"), title, [1], self.info, Investigation(1)) # sharing with other user study.share(User("*****@*****.**")) study.delete(study.id) self.assertFalse(study.exists(title)) with self.assertRaises(QiitaDBError): Study.delete(1) with self.assertRaises(QiitaDBUnknownIDError): Study.delete(41)