def get(self, *args, **kwargs): name = self.get_argument('name', None) affiliation = self.get_argument('affiliation', None) if name is None and affiliation is None: # Retrieve the list of all the StudyPerson sp = [{ 'name': p.name, 'affiliation': p.affiliation } for p in StudyPerson.iter()] self.write(json_encode(sp)) self.finish() elif name is not None and affiliation is not None: try: p = StudyPerson.from_name_and_affiliation(name, affiliation) except QiitaDBLookupError: self.fail('Person not found', 404) return self.write({ 'address': p.address, 'phone': p.phone, 'email': p.email, 'id': p.id }) self.finish() else: arg_name = 'name' if name is None else 'affiliation' raise MissingArgumentError(arg_name)
def test_post_new_person(self): body = {'name': 'Boaty McBoatFace', 'affiliation': 'UCSD', 'email': '*****@*****.**', 'phone': '720-876-5309'} response = self.post('/api/v1/person', data=body, headers=self.headers) self.assertEqual(response.code, 201) obs = json_decode(response.body) exp = StudyPerson.from_name_and_affiliation(body['name'], body['affiliation']).id self.assertEqual(exp, obs['id'])
def test_post_new_person(self): body = { 'name': 'Boaty McBoatFace', 'affiliation': 'UCSD', 'email': '*****@*****.**', 'phone': '720-876-5309' } response = self.post('/api/v1/person', data=body, headers=self.headers) self.assertEqual(response.code, 201) obs = json_decode(response.body) exp = StudyPerson.from_name_and_affiliation(body['name'], body['affiliation']).id self.assertEqual(exp, obs['id'])
def get(self, *args, **kwargs): name = self.get_argument('name', None) affiliation = self.get_argument('affiliation', None) if name is None and affiliation is None: # Retrieve the list of all the StudyPerson sp = [{'name': p.name, 'affiliation': p.affiliation} for p in StudyPerson.iter()] self.write(json_encode(sp)) self.finish() elif name is not None and affiliation is not None: try: p = StudyPerson.from_name_and_affiliation(name, affiliation) except QiitaDBLookupError: self.fail('Person not found', 404) return self.write({'address': p.address, 'phone': p.phone, 'email': p.email, 'id': p.id}) self.finish() else: arg_name = 'name' if name is None else 'affiliation' raise MissingArgumentError(arg_name)
def post(self): try: payload = json_decode(self.request.body) except ValueError: self.fail('Could not parse body', 400) return required = { 'title', 'study_abstract', 'study_description', 'study_alias', 'owner', 'contacts' } if not required.issubset(payload): self.fail('Not all required arguments provided', 400) return title = payload['title'] study_abstract = payload['study_abstract'] study_desc = payload['study_description'] study_alias = payload['study_alias'] notes = payload['notes'] owner = payload['owner'] if not User.exists(owner): self.fail('Unknown user', 403) return else: owner = User(owner) contacts = payload['contacts'] if Study.exists(title): self.fail('Study title already exists', 409) return pi_name = contacts['principal_investigator'][0] pi_aff = contacts['principal_investigator'][1] if not StudyPerson.exists(pi_name, pi_aff): self.fail('Unknown principal investigator', 403) return else: pi = StudyPerson.from_name_and_affiliation(pi_name, pi_aff) lp_name = contacts['lab_person'][0] lp_aff = contacts['lab_person'][1] if not StudyPerson.exists(lp_name, lp_aff): self.fail('Unknown lab person', 403) return else: lp = StudyPerson.from_name_and_affiliation(lp_name, lp_aff) info = { 'lab_person_id': lp, 'principal_investigator_id': pi, 'study_abstract': study_abstract, 'study_description': study_desc, 'study_alias': study_alias, 'notes': notes, # TODO: we believe it is accurate that mixs is false and # metadata completion is false as these cannot be known # at study creation here no matter what. # we do not know what should be done with the timeseries. 'mixs_compliant': False, 'metadata_complete': False, 'timeseries_type_id': 1 } study = Study.create(owner, title, info) self.set_status(201) self.write({'id': study.id}) self.finish()