Example #1
0
  def testProjectWithMoreMentors(self):
    """Tests for a mentor for project that have more mentors."""
    # seed a few extra mentors for the same project
    for _ in range(5):
      other_mentor = profile_utils.seedNDBProfile(
          self.program.key(), mentor_for=[self.organization_one.key])
      self.project_one.mentors.append(other_mentor.key.to_old_key())
    self.project_one.put()

    # assign our mentor to the project too
    self.project_one.mentors.append(self.mentor.key.to_old_key())
    self.project_one.put()

    # the mentor has a project
    has_projects = project_logic.hasMentorProjectAssigned(self.mentor)
    self.assertTrue(has_projects)

    # the mentor has a project for organization one
    has_projects = project_logic.hasMentorProjectAssigned(
        self.mentor, org_key=self.organization_one.key)
    self.assertTrue(has_projects)

    # the mentor still does not have projects for organization two
    has_projects = project_logic.hasMentorProjectAssigned(
        self.mentor, org_key=self.organization_two.key)
    self.assertFalse(has_projects)
Example #2
0
    def testProjectWithMoreMentors(self):
        """Tests for a mentor for project that have more mentors."""
        # seed a few extra mentors for the same project
        for _ in range(5):
            other_mentor = profile_utils.seedNDBProfile(
                self.program.key(), mentor_for=[self.organization_one.key])
            self.project_one.mentors.append(other_mentor.key.to_old_key())
        self.project_one.put()

        # assign our mentor to the project too
        self.project_one.mentors.append(self.mentor.key.to_old_key())
        self.project_one.put()

        # the mentor has a project
        has_projects = project_logic.hasMentorProjectAssigned(self.mentor)
        self.assertTrue(has_projects)

        # the mentor has a project for organization one
        has_projects = project_logic.hasMentorProjectAssigned(
            self.mentor, org_key=self.organization_one.key)
        self.assertTrue(has_projects)

        # the mentor still does not have projects for organization two
        has_projects = project_logic.hasMentorProjectAssigned(
            self.mentor, org_key=self.organization_two.key)
        self.assertFalse(has_projects)
Example #3
0
  def testMentorWithoutProjects(self):
    """Tests for a mentor with no projects."""
    has_projects = project_logic.hasMentorProjectAssigned(self.mentor)
    self.assertFalse(has_projects)

    has_projects = project_logic.hasMentorProjectAssigned(
        self.mentor, org_key=self.organization_one.key)
    self.assertFalse(has_projects)
Example #4
0
    def testMentorWithoutProjects(self):
        """Tests for a mentor with no projects."""
        has_projects = project_logic.hasMentorProjectAssigned(self.mentor)
        self.assertFalse(has_projects)

        has_projects = project_logic.hasMentorProjectAssigned(
            self.mentor, org_key=self.organization_one.key)
        self.assertFalse(has_projects)
Example #5
0
  def testMentorWithProject(self):
    """Tests for a mentor with one project for one organization."""
    # assign one project to the mentor
    self.project_one.mentors = [self.mentor.key.to_old_key()]
    self.project_one.put()

    # the mentor has a project
    has_projects = project_logic.hasMentorProjectAssigned(self.mentor)
    self.assertTrue(has_projects)

    # the mentor has a project for organization one
    has_projects = project_logic.hasMentorProjectAssigned(
        self.mentor, org_key=self.organization_one.key)
    self.assertTrue(has_projects)

    # the mentor still does not have projects for organization two
    has_projects = project_logic.hasMentorProjectAssigned(
        self.mentor, org_key=self.organization_two.key)
    self.assertFalse(has_projects)
Example #6
0
    def testMentorWithProject(self):
        """Tests for a mentor with one project for one organization."""
        # assign one project to the mentor
        self.project_one.mentors = [self.mentor.key.to_old_key()]
        self.project_one.put()

        # the mentor has a project
        has_projects = project_logic.hasMentorProjectAssigned(self.mentor)
        self.assertTrue(has_projects)

        # the mentor has a project for organization one
        has_projects = project_logic.hasMentorProjectAssigned(
            self.mentor, org_key=self.organization_one.key)
        self.assertTrue(has_projects)

        # the mentor still does not have projects for organization two
        has_projects = project_logic.hasMentorProjectAssigned(
            self.mentor, org_key=self.organization_two.key)
        self.assertFalse(has_projects)
Example #7
0
  def testMentorWithProjectForOtherOrg(self):
    """Tests for a mentor who has a project for another organization."""
    # set our profile a mentor for organization two
    self.mentor.mentor_for.append(self.organization_two.key)
    self.mentor.put()

    # seed a project for organization two
    student = profile_utils.seedNDBStudent(self.program)
    project_utils.seedProject(
        student, self.program.key(), org_key=self.organization_two.key,
        mentor_key=self.mentor.key)

    # the mentor has a project
    has_projects = project_logic.hasMentorProjectAssigned(self.mentor)
    self.assertTrue(has_projects)

    # the mentor has only a project for organization two
    has_projects = project_logic.hasMentorProjectAssigned(
        self.mentor, org_key=self.organization_one.key)
    self.assertFalse(has_projects)
Example #8
0
    def testMentorWithProjectForOtherOrg(self):
        """Tests for a mentor who has a project for another organization."""
        # set our profile a mentor for organization two
        self.mentor.mentor_for.append(self.organization_two.key)
        self.mentor.put()

        # seed a project for organization two
        student = profile_utils.seedNDBStudent(self.program)
        project_utils.seedProject(student,
                                  self.program.key(),
                                  org_key=self.organization_two.key,
                                  mentor_key=self.mentor.key)

        # the mentor has a project
        has_projects = project_logic.hasMentorProjectAssigned(self.mentor)
        self.assertTrue(has_projects)

        # the mentor has only a project for organization two
        has_projects = project_logic.hasMentorProjectAssigned(
            self.mentor, org_key=self.organization_one.key)
        self.assertFalse(has_projects)
Example #9
0
  def testMentorWithMoreProjects(self):
    """Tests for a mentor with more projects."""
    # seed a few extra projects and assign our mentor
    for _ in range(5):
      student = profile_utils.seedNDBStudent(self.program)
      self.project_one = project_utils.seedProject(
          student, self.program.key(), org_key=self.organization_one.key,
          mentor_key=self.mentor.key)

    # the mentor has projects for organization one
    has_projects = project_logic.hasMentorProjectAssigned(
        self.mentor, org_key=self.organization_one.key)
    self.assertTrue(has_projects)
Example #10
0
    def testMentorWithMoreProjects(self):
        """Tests for a mentor with more projects."""
        # seed a few extra projects and assign our mentor
        for _ in range(5):
            student = profile_utils.seedNDBStudent(self.program)
            self.project_one = project_utils.seedProject(
                student,
                self.program.key(),
                org_key=self.organization_one.key,
                mentor_key=self.mentor.key)

        # the mentor has projects for organization one
        has_projects = project_logic.hasMentorProjectAssigned(
            self.mentor, org_key=self.organization_one.key)
        self.assertTrue(has_projects)
Example #11
0
def canResignAsMentorForOrg(profile, org_key):
    """Tells whether the specified profile can resign from their mentor role
  for the specified organization.

  A mentor may be removed from the list of mentors of an organization, if
  he or she does not have a proposal or a project assigned to mentor. Also,
  organization administrators have cannot resign from mentorship. They have
  to give up that role first.

  Please note that this function executes a non-ancestor query, so it cannot
  be safely used within transactions.

  Args:
    profile: the specified GSoCProfile entity
    org_key: organization key

  Returns:
    RichBool whose value is set to True, if the mentor is allowed to resign.
    Otherwise, RichBool whose value is set to False and extra part is a string
    that represents the reason why the user is not allowed to resign.
  """
    # TODO(daniel): figure out what to do with "possible_mentors"
    # user may be asked either to remove herself from those proposals or
    # its profile has to be removed in a safe way.

    if org_key not in profile.mentor_for:
        raise ValueError('The specified profile is not a mentor for %s' %
                         org_key.id())

    if org_key in profile.admin_for:
        return rich_bool.RichBool(False, IS_ORG_ADMIN)

    if proposal_logic.hasMentorProposalAssigned(profile, org_key=org_key):
        return rich_bool.RichBool(False, HAS_PROPOSAL_ASSIGNED)

    if project_logic.hasMentorProjectAssigned(profile, org_key=org_key):
        return rich_bool.RichBool(False, HAS_PROJECT_ASSIGNED)

    return rich_bool.TRUE
Example #12
0
def canResignAsMentorForOrg(profile, org_key):
  """Tells whether the specified profile can resign from their mentor role
  for the specified organization.

  A mentor may be removed from the list of mentors of an organization, if
  he or she does not have a proposal or a project assigned to mentor. Also,
  organization administrators have cannot resign from mentorship. They have
  to give up that role first.

  Please note that this function executes a non-ancestor query, so it cannot
  be safely used within transactions.

  Args:
    profile: the specified GSoCProfile entity
    org_key: organization key

  Returns:
    RichBool whose value is set to True, if the mentor is allowed to resign.
    Otherwise, RichBool whose value is set to False and extra part is a string
    that represents the reason why the user is not allowed to resign.
  """
  # TODO(daniel): figure out what to do with "possible_mentors"
  # user may be asked either to remove herself from those proposals or
  # its profile has to be removed in a safe way.

  if org_key not in profile.mentor_for:
    raise ValueError(
        'The specified profile is not a mentor for %s' % org_key.id())

  if org_key in profile.admin_for:
    return rich_bool.RichBool(False, IS_ORG_ADMIN)

  if proposal_logic.hasMentorProposalAssigned(profile, org_key=org_key):
    return rich_bool.RichBool(False, HAS_PROPOSAL_ASSIGNED)

  if project_logic.hasMentorProjectAssigned(profile, org_key=org_key):
    return rich_bool.RichBool(False, HAS_PROJECT_ASSIGNED)

  return rich_bool.TRUE