def validate_old_parameters(self, parameters, old_param): parameters[old_param] = False no_results = utils.get_person_by_ids(parameters) self.assertEqual(self.length_of_response(no_results), 0) parameters[old_param] = True person = utils.get_person_by_ids(parameters) self.assertEqual(self.length_of_response(person), 1)
def test_bad_name_request(self): self.assertEqual( utils.get_person_by_ids({ 'firstName': 'foo' }).status_code, 400) self.assertEqual( utils.get_person_by_ids({ 'lastName': 'foo' }).status_code, 400)
def test_too_many_osu_id_request(self): id_list = [ str(random.randint(930000000, 939999999)) for _ in range(50) ] valid_parameters = self.osu_id_parameter_from_list(id_list) persons = utils.get_person_by_ids(valid_parameters) self.assertEqual(persons.status_code, 200) id_list.append("foo") invalid_parameters = self.osu_id_parameter_from_list(id_list) too_many_ids = utils.get_person_by_ids(invalid_parameters) self.assertEqual(too_many_ids.status_code, 400)
def test_fuzzy_name_search(self): person_res = utils.get_person_by_ids({ 'firstName': fuzzy_name_person['first_name'], 'lastName': fuzzy_name_person['last_name'] }) self.assertEqual(self.length_of_response(person_res), 1)
def test_name_search(self): person_res = utils.get_person_by_ids({ 'firstName': regular_name_person['first_name'], 'lastName': regular_name_person['last_name'] }) self.assertEqual(person_res.status_code, 200) self.assertLess(person_res.elapsed.total_seconds(), 3) self.assertEqual(self.length_of_response(person_res), 1)
def test_name_alias(self): for person_name in alias_persons: person_res = utils.get_person_by_ids({ 'firstName': person_name['first_name_alias'], 'lastName': person_name['last_name'] }) person = person_res.json()['data'][0]['attributes'] self.assertEqual(person['firstName'], person_name['first_name']) self.assertEqual(person['lastName'], person_name['last_name'])
def test_multiple_osu_id(self): osu_id_list = [jobs_osu_id, no_job_osu_id] parameters = self.osu_id_parameter_from_list(osu_id_list) persons = utils.get_person_by_ids(parameters) self.assertEqual(persons.status_code, 200) persons_response_body = persons.json() response_osu_id_list = [ person['id'] for person in persons_response_body['data'] ] self.assertEqual(len(response_osu_id_list), len(osu_id_list)) for id in osu_id_list: self.assertTrue(osu_id in response_osu_id_list)
def test_person_by_ids(self): # expect 400 if identifiers are included together self.assertEqual( utils.get_person_by_ids({ 'osuID': osu_id, 'onid': onid }).status_code, 400) self.assertEqual( utils.get_person_by_ids({ 'osuID': osu_id, 'osuUID': osuuid }).status_code, 400) self.assertEqual( utils.get_person_by_ids({ 'onid': onid, 'osuUID': osuuid }).status_code, 400) self.assertEqual( utils.get_person_by_ids({ 'osuID': osu_id, 'onid': onid, 'osuUID': osuuid }).status_code, 400) # expect 200 if there is only one identifier and valid osu_id_res = utils.get_person_by_ids({'osuID': osu_id}) onid_res = utils.get_person_by_ids({'onid': onid}) osuuid_res = utils.get_person_by_ids({'osuUID': osuuid}) self.assertEqual(osu_id_res.status_code, 200) self.assertEqual(onid_res.status_code, 200) self.assertEqual(osuuid_res.status_code, 200) # test person data self.assertIsNotNone(osu_id_res.json()['data']) self.assertEqual(osu_id_res.json()['data'][0]['type'], 'person') # identifiers and return ids should matched person_data = osu_id_res.json()['data'][0] ids_list = [(person_data['id'], osu_id), (person_data['attributes']['username'], onid), (person_data['attributes']['osuUID'], osuuid)] for res_id, param_id in ids_list: self.assertEqual(res_id, param_id) self.assertIsInstance(res_id, str) # should return the same person if queried by each identifier self.assertTrue( osu_id_res.content == onid_res.content == osuuid_res.content)
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)