def test_create_studyperson(self): new = StudyPerson.create('SomeDude', '*****@*****.**', 'affil', '111 fake street', '111-121-1313') self.assertEqual(new.id, 4) obs = self.conn_handler.execute_fetchall( "SELECT * FROM qiita.study_person WHERE study_person_id = 4") self.assertEqual(obs, [[4, 'SomeDude', '*****@*****.**', 'affil', '111 fake street', '111-121-1313']])
def test_create_studyperson(self): new = StudyPerson.create('SomeDude', '*****@*****.**', 'affil', '111 fake street', '111-121-1313') self.assertEqual(new.id, 4) obs = self.conn_handler.execute_fetchall( "SELECT * FROM qiita.study_person WHERE study_person_id = 4") self.assertEqual(obs, [[ 4, 'SomeDude', '*****@*****.**', 'affil', '111 fake street', '111-121-1313' ]])
def post(self, *args, **kwargs): name = self.get_argument('name') affiliation = self.get_argument('affiliation') email = self.get_argument('email') phone = self.get_argument('phone', None) address = self.get_argument('address', None) if StudyPerson.exists(name, affiliation): self.fail('Person already exists', 409) return p = StudyPerson.create(name=name, affiliation=affiliation, email=email, phone=phone, address=address) self.set_status(201) self.write({'id': p.id}) self.finish()
def _get_study_person_id(self, index, new_people_info): """Returns the id of the study person, creating if needed If index < 0, means that we need to create a new study person, and its information is stored in new_people_info[index] Parameters ---------- index : int The index of the study person new_people_info : list of tuples The information of the new study persons added through the interface Returns ------- int the study person id """ # If the ID is less than 0, then this is a new person if index < 0: return StudyPerson.create(*new_people_info[index]).id return index
def setUp(self): StudyPerson.create('SomeDude', '*****@*****.**', 'some', '111 fake street', '111-121-1313') User.create('*****@*****.**', 'password') self.config1 = CONFIG_1 self.config2 = CONFIG_2
def test_create_studyperson_already_exists(self): obs = StudyPerson.create('LabDude', '*****@*****.**', 'knight lab') self.assertEqual(obs.name, 'LabDude') self.assertEqual(obs.email, '*****@*****.**')
def post(self, study=None): the_study = None form_factory = StudyEditorExtendedForm if study: # Check study and user access the_study = self._check_study_exists_and_user_access(study) # If the study is public, we use the short version of the form if the_study.status == 'public': form_factory = StudyEditorForm # Get the form data from the request arguments form_data = form_factory() form_data.process(data=self.request.arguments) # Get information about new people that need to be added to the DB new_people_info = zip(self.get_arguments('new_people_names'), self.get_arguments('new_people_emails'), self.get_arguments('new_people_affiliations'), self.get_arguments('new_people_phones'), self.get_arguments('new_people_addresses')) # New people will be indexed with negative numbers, so we reverse # the list here new_people_info.reverse() index = int(form_data.data['principal_investigator'][0]) if index < 0: # If the ID is less than 0, then this is a new person PI = StudyPerson.create( new_people_info[index][0], new_people_info[index][1], new_people_info[index][2], new_people_info[index][3] or None, new_people_info[index][4] or None).id else: PI = index if form_data.data['lab_person'][0]: index = int(form_data.data['lab_person'][0]) if index < 0: # If the ID is less than 0, then this is a new person lab_person = StudyPerson.create( new_people_info[index][0], new_people_info[index][1], new_people_info[index][2], new_people_info[index][3] or None, new_people_info[index][4] or None).id else: lab_person = index else: lab_person = None # TODO: Get the portal type from... somewhere # TODO: MIXS compliant? Always true, right? info = { 'portal_type_id': 1, 'lab_person_id': lab_person, 'principal_investigator_id': PI, 'metadata_complete': False, 'mixs_compliant': True, 'study_description': form_data.data['study_description'][0], 'study_alias': form_data.data['study_alias'][0], 'study_abstract': form_data.data['study_abstract'][0]} if 'timeseries' in form_data.data and form_data.data['timeseries']: info['timeseries_type_id'] = form_data.data['timeseries'][0] study_title = form_data.data['study_title'][0] if the_study: # We are under editing, so just update the values the_study.title = study_title the_study.info = info msg = ('Study <a href="/study/description/%d">%s</a> ' 'successfully updated' % (the_study.id, form_data.data['study_title'][0])) else: # create the study # TODO: Fix this EFO once ontology stuff from emily is added the_study = Study.create(User(self.current_user), study_title, efo=[1], info=info) msg = ('Study <a href="/study/description/%d">%s</a> ' 'successfully created' % (the_study.id, form_data.data['study_title'][0])) # Add the environmental packages if ('environmental_packages' in form_data.data and form_data.data['environmental_packages']): the_study.environmental_packages = form_data.data[ 'environmental_packages'] if form_data.data['pubmed_id'][0]: # The user can provide a comma-seprated list pmids = form_data.data['pubmed_id'][0].split(',') # Make sure that we strip the spaces from the pubmed ids the_study.pmids = [pmid.strip() for pmid in pmids] self.render('index.html', message=msg, level='success', user=self.current_user)
def post(self): # Get the form data from the request arguments form_data = CreateStudyForm() form_data.process(data=self.request.arguments) # Get information about new people that need to be added to the DB new_people_info = zip(self.get_arguments('new_people_names'), self.get_arguments('new_people_emails'), self.get_arguments('new_people_affiliations'), self.get_arguments('new_people_phones'), self.get_arguments('new_people_addresses')) # New people will be indexed with negative numbers, so we reverse # the list here new_people_info.reverse() index = int(form_data.data['principal_investigator'][0]) if index < 0: # If the ID is less than 0, then this is a new person PI = StudyPerson.create( new_people_info[index][0], new_people_info[index][1], new_people_info[index][2], new_people_info[index][3] or None, new_people_info[index][4] or None).id else: PI = index if form_data.data['lab_person'][0]: index = int(form_data.data['lab_person'][0]) if index < 0: # If the ID is less than 0, then this is a new person lab_person = StudyPerson.create( new_people_info[index][0], new_people_info[index][1], new_people_info[index][2], new_people_info[index][3] or None, new_people_info[index][4] or None).id else: lab_person = index else: lab_person = None # create the study # TODO: Get the portal type from... somewhere # TODO: Time series types; right now it's True/False; from emily? # TODO: MIXS compliant? Always true, right? info = { 'timeseries_type_id': 1, 'portal_type_id': 1, 'lab_person_id': lab_person, 'principal_investigator_id': PI, 'metadata_complete': False, 'mixs_compliant': True, 'study_description': form_data.data['study_description'][0], 'study_alias': form_data.data['study_alias'][0], 'study_abstract': form_data.data['study_abstract'][0]} # TODO: Fix this EFO once ontology stuff from emily is added theStudy = Study.create(User(self.current_user), form_data.data['study_title'][0], efo=[1], info=info) if form_data.data['pubmed_id'][0]: theStudy.add_pmid(form_data.data['pubmed_id'][0]) # TODO: change this redirect to something more sensible self.redirect('/')
def test_create_studyperson_already_exists(self): obs = StudyPerson.create("LabDude", "*****@*****.**", "knight lab") self.assertEqual(obs.name, "LabDude") self.assertEqual(obs.email, "*****@*****.**")
def test_create_studyperson(self): new = StudyPerson.create("SomeDude", "*****@*****.**", "affil", "111 fake street", "111-121-1313") self.assertEqual(new.id, 4) obs = self.conn_handler.execute_fetchall("SELECT * FROM qiita.study_person WHERE study_person_id = 4") self.assertEqual(obs, [[4, "SomeDude", "*****@*****.**", "affil", "111 fake street", "111-121-1313"]])