Example #1
0
 def test_exists_notindb(self):
     self.assertFalse(User.exists("*****@*****.**"))
Example #2
0
 def test_exists_invalid_email(self):
     with self.assertRaises(IncorrectEmailError):
         User.exists("notanemail.@badformat")
Example #3
0
 def test_exists(self):
     self.assertTrue(User.exists("*****@*****.**"))
Example #4
0
    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()
Example #5
0
 def test_exists_invaid_email(self):
     with self.assertRaises(IncorrectEmailError):
         User.exists("notanemail@badformat")
Example #6
0
 def test_exists_notindb(self):
     self.assertFalse(User.exists("*****@*****.**"))
Example #7
0
 def test_exists(self):
     self.assertTrue(User.exists("*****@*****.**"))