def testForNonStudentProfile(self): """Tests that True is returned if a non-student profile exists.""" # seed a non-student profile profile_utils.seedNDBProfile(self.program.key(), user=self.user) result = validate.hasNonStudentProfileForProgram( self.user.key, self.program.key()) self.assertTrue(result)
def testForStudentProfile(self): """Tests that False is returned if a student profile exists.""" # seed a student profile profile_utils.seedNDBStudent(self.program, user=self.user) result = validate.hasNonStudentProfileForProgram( self.user.key, self.program.key()) self.assertFalse(result)
def testForNonActiveProfile(self): """Tests that False is returned if a profile is not active.""" # seed a non-student, banned profile profile_utils.seedNDBProfile( self.program.key(), user=self.user, status=profile_model.Status.BANNED) result = validate.hasNonStudentProfileForProgram( self.user.key, self.program.key()) self.assertFalse(result)
def testForNonActiveProfile(self): """Tests that False is returned if a profile is not active.""" # seed a non-student, banned profile profile_utils.seedNDBProfile(self.program.key(), user=self.user, status=profile_model.Status.BANNED) result = validate.hasNonStudentProfileForProgram( self.user.key, self.program.key()) self.assertFalse(result)
def validateBackupAdminProfile(self, backup_admin_user, profile_model): """Validates if backup admin has a profile for the current program. Args: backup_admin_user: User entity for the backup admin. profile_model: Model class from which the profile must be fetched. Raises: django_forms.ValidationError if the backup admin does not have a profile. """ if not validate.hasNonStudentProfileForProgram( backup_admin_user.key, self.request_data.program.key(), models=self.request_data.models): redirector = self.request_data.redirect.createProfile('org_admin') raise django_forms.ValidationError( DEF_BACKUP_ADMIN_NO_PROFILE % ( self.request_data.program.name, self._getCreateProfileURL(redirector)))
def canTakeOrgApp(self): """A user can take the GSoC org app if he has org admin profile in the program. """ self.isLoggedIn() program = self.data.program # TODO(nathaniel): Eliminate this state-setting call. self.data.redirect.createProfile('org_admin') msg = DEF_NO_ORG_ADMIN_PROFILE % ( program.short_name, self.data.redirect.urlOf('create_gsoc_profile', secure=True)) if not self.data.ndb_user: raise exception.Forbidden(message=msg) if not validate.hasNonStudentProfileForProgram( self.data.ndb_user.key, self.data.program.key(), models=self.data.models): raise exception.Forbidden(message=msg)
def testForNoProfile(self): """Tests that False is returned if no profile for the user exists.""" result = validate.hasNonStudentProfileForProgram( self.user.key, self.program.key()) self.assertFalse(result)