def testAnonymousDeniedAccess(self): """Tests that logged-out users are denied access.""" access_checker = access.ProgramAdministratorAccessChecker() with self.assertRaises(exception.UserError) as context: access_checker.checkAccess(self.data, None) self.assertEqual(context.exception.message, access._MESSAGE_NOT_PROGRAM_ADMINISTRATOR)
def testProgramAdministratorsAllowedAccess(self): """Tests that a program administrator is allowed access.""" # make the user a program administrator self.user.host_for = [ndb.Key.from_old_key(self.program.key())] self.user.put() access_checker = access.ProgramAdministratorAccessChecker() access_checker.checkAccess(self.data, None)
def testStudentDeniedAccess(self): """Tests that students are denied access.""" # seed a profile who is a student profile_utils.seedNDBStudent(self.program, user=self.user) access_checker = access.ProgramAdministratorAccessChecker() with self.assertRaises(exception.UserError) as context: access_checker.checkAccess(self.data, None) self.assertEqual(context.exception.message, access._MESSAGE_NOT_PROGRAM_ADMINISTRATOR)
def testMentorDeniedAccess(self): """Tests that a mentor is denied access.""" # seed a profile who is a mentor org = org_utils.seedOrganization(self.program.key()) profile_utils.seedNDBProfile(self.program.key(), user=self.user, mentor_for=[org.key]) access_checker = access.ProgramAdministratorAccessChecker() with self.assertRaises(exception.UserError) as context: access_checker.checkAccess(self.data, None) self.assertEqual(context.exception.message, access._MESSAGE_NOT_PROGRAM_ADMINISTRATOR)