def test_get_jobs_by_osu_id(self): jobs_res = utils.get_jobs_by_osu_id(jobs_osu_id) no_job_res = utils.get_jobs_by_osu_id(no_job_osu_id) # expect 200 if osuID is valid for res, res_osu_id in [(jobs_res, jobs_osu_id), (no_job_res, no_job_osu_id)]: self.assertEqual(res.status_code, 200) # test person with jobs self.assertGreater(self.length_of_response(jobs_res), 0) # test person without job self.assertEqual(self.length_of_response(no_job_res), 0) # expect 404 if osuID is not valid self.assertEqual( utils.get_person_by_osu_id(not_valid_osu_id).status_code, 404)
def test_date(self): iso_8601_full_date_pattern = re.compile(r'^\d{4}-\d{2}-\d{2}') person_res = utils.get_person_by_osu_id(osu_id) jobs_res = utils.get_jobs_by_osu_id(jobs_osu_id) dates = [person_res.json()['data']['attributes']['birthDate']] for job in jobs_res.json()['data']: attributes = job['attributes'] dates += [attributes['beginDate'], attributes['endDate']] for date in filter(None, dates): # validate ISO 8601 full-date format self.assertIsNotNone( iso_8601_full_date_pattern.match(date).group(0))
def test_self_link(self): person_ids_res = utils.get_person_by_ids({'osuID': osu_id}) for person in person_ids_res.json()['data']: self.assertEqual(person['links']['self'], api_url + osu_id) person_id_res = utils.get_person_by_osu_id(osu_id) self.assertEqual(person_id_res.json()['data']['links']['self'], api_url + osu_id) jobs_res = utils.get_jobs_by_osu_id(jobs_osu_id) for job in jobs_res.json()['data']: attributes = job['attributes'] position_number = attributes['positionNumber'] suffix = attributes['suffix'] expected_url = "{}{}/jobs?positionNumber={}&suffix={}".format( api_url, osu_id, position_number, suffix) self.assertEqual(job['links']['self'], expected_url)