def api_names_to_ids(): """ Gets the IDs of names of a given category. Args: category (str) A category name such as `character`, `corporation`, `solar_system`, `alliance`, 'inventory_type`, or `region`. names (list of str) Names to retrieve. Only exact matches will be returned. Example: response = { 'info': { 'Twine Endashi': '1937622137', ... } } Error codes: Forbidden (403): If logged in user is not a recruiter or admin Bad request (400): If category is not a valid category """ args = request.get_json() category = args['category'] name_list = args['names'] return jsonify( get_names_to_ids(category, name_list, current_user=current_user))
def test_search_for_ascendance(self): response = get_names_to_ids('corporation', ['Ascendance'], current_user=self.admin) self.assertIn('info', response) data = response['info'] self.assertIn('Ascendance', data) self.assertEqual(data['Ascendance'], 98409330) self.assertEqual(len(data), 1)
def test_search_for_applicant_as_recruiter(self): response = get_names_to_ids('character', [self.applicant.name], current_user=self.recruiter) self.assertIn('info', response) data = response['info'] self.assertIn(self.applicant.name, data) self.assertEqual(data[self.applicant.name], self.applicant.id) self.assertEqual(len(data), 1)
def test_search_for_querious(self): response = get_names_to_ids('region', ['Querious'], current_user=self.admin) self.assertIn('info', response) data = response['info'] self.assertIn('Querious', data) self.assertEqual(data['Querious'], 10000050) self.assertEqual(len(data), 1)
def test_search_for_jita(self): response = get_names_to_ids('system', ['Jita'], current_user=self.admin) self.assertIn('info', response) data = response['info'] self.assertIn('Jita', data) self.assertEqual(data['Jita'], 30000142) self.assertEqual(len(data), 1)
def test_search_for_two_characters_full_match(self): response = get_names_to_ids( 'character', [self.applicant.name, self.not_applicant.name], current_user=self.admin) self.assertIn('info', response) data = response['info'] self.assertIn(self.applicant.name, data) self.assertEqual(data[self.applicant.name], self.applicant.id) self.assertIn(self.not_applicant.name, data) self.assertEqual(data[self.not_applicant.name], self.not_applicant.id) self.assertEqual(len(data), 2)
def test_search_invalid_category(self): with self.assertRaises(BadRequestException): get_names_to_ids('type', ['Tritanium'], current_user=self.admin)
def test_search_no_not_applicant_access(self): with self.assertRaises(ForbiddenException): get_names_to_ids('character', [self.applicant.name], current_user=self.not_applicant)
def test_search_no_applicant_access(self): with self.assertRaises(ForbiddenException): response = get_names_to_ids('character', [self.applicant.name], current_user=self.applicant) self.assertIn('info', response)
def test_search_no_result(self): response = get_names_to_ids('character', ['erajlfdskhaahouirwaeiouw'], current_user=self.admin) self.assertIn('info', response) data = response['info'] self.assertEqual(len(data), 0)