def test_no_recruiter_access(self): with self.assertRaises(ForbiddenException): set_roles(self.other_recruiter.id, is_recruiter=True, current_user=self.recruiter) with self.assertRaises(ForbiddenException): set_roles(self.other_recruiter.id, is_recruiter=False, current_user=self.recruiter)
def test_demote_admin(self): response = set_roles(self.admin.id, is_admin=False, current_user=self.admin) self.assertEqual(response, {'status': 'ok'}) self.assertIsNone(self.admin.admin) self.assertIsNone(self.admin.recruiter)
def test_promote_applicant_to_admin(self): response = set_roles(self.applicant.id, is_admin=True, current_user=self.admin) self.assertEqual(response, {'status': 'ok'}) self.assertTrue(self.applicant.admin) self.assertIsNone(Application.get_for_user(self.applicant.id))
def test_remove_senior_recruiter(self): response = set_roles(self.senior_recruiter.id, is_recruiter=False, is_senior_recruiter=False, current_user=self.admin) self.assertEqual(response, {'status': 'ok'}) self.assertIsNone(self.senior_recruiter.recruiter)
def test_promote_recruiter_to_admin(self): self.assertFalse(self.recruiter.admin) response = set_roles(self.recruiter.id, is_admin=True, current_user=self.admin) self.assertEqual(response, {'status': 'ok'}) self.assertTrue(self.recruiter.admin) self.assertTrue(self.recruiter.recruiter)
def test_promote_user_to_senior_recruiter(self): response = set_roles(self.not_applicant.id, is_recruiter=False, is_senior_recruiter=True, current_user=self.admin) self.assertEqual(response, {'status': 'ok'}) self.assertTrue(self.not_applicant.recruiter) self.assertTrue(self.not_applicant.recruiter.is_senior)
def test_switch_recruiter_to_admin(self): response = set_roles(self.other_recruiter.id, is_recruiter=False, is_admin=True, current_user=self.admin) self.assertEqual(response, {'status': 'ok'}) self.assertIsNone(self.other_recruiter.recruiter) self.assertTrue(self.other_recruiter.admin)
def test_demote_senior_recruiter_explicit(self): response = set_roles(self.senior_recruiter.id, is_recruiter=True, is_senior_recruiter=False, current_user=self.admin) self.assertEqual(response, {'status': 'ok'}) self.assertTrue(self.senior_recruiter.recruiter) self.assertFalse(self.senior_recruiter.recruiter.is_senior)
def test_promote_active_recruiter_to_senior(self): response = set_roles(self.recruiter.id, is_senior_recruiter=True, current_user=self.admin) self.assertEqual(response, {'status': 'ok'}) self.assertTrue(self.recruiter.recruiter.is_senior) self.assertTrue( db.session.query(db.exists().where( db.and_(Application.user_id == self.applicant.id, Application.is_concluded == False))).scalar())
def api_set_roles(user_id): """ Sets roles of a given user. If senior_recruiter is set to True, recruiter will be ignored as an input. If the parameters are not given, that role will be unchanged. Args: user_id (int) if missing/None uses the logged in user is_recruiter (bool, optional) is_senior_recruiter (bool, optional) is_admin (bool, optional) Returned data is of the form {'info': [user_1, user_2, ...]}. Each user dictionary has the keys `id`, `name`, `is_admin`, `is_senior_recruiter`, and `is_recruiter`. Returns: response (dict) Error codes: Forbidden (403): If logged in user is not an admin. """ recruiter = query_param_to_python(request.args.get('is_recruiter', None)) senior_recruiter = query_param_to_python(request.args.get('is_senior_recruiter', None)) admin = query_param_to_python(request.args.get('is_admin', None)) set_result = set_roles( user_id, is_recruiter=recruiter, is_senior_recruiter=senior_recruiter, is_admin=admin, current_user=current_user, ) if set_result.get('status', '') == 'ok': return jsonify(get_users(current_user=current_user)) return set_result
def test_no_applicant_access(self): with self.assertRaises(ForbiddenException): set_roles(self.applicant.id, is_admin=True, current_user=self.applicant)
def test_promote_user_to_admin(self): response = set_roles(self.not_applicant.id, is_admin=True, current_user=self.admin) self.assertEqual(response, {'status': 'ok'}) self.assertTrue(self.not_applicant.admin)