示例#1
0
  def testHasMentorProposalAssigned(self):
    """Unit test for proposal_logic.hasMentorProposalAssigned function."""
    # seed a new mentor
    mentor = profile_utils.seedNDBProfile(
        self.program.key(), mentor_for=[self.foo_organization.key])

    # mentor has no proposals
    has_proposal = proposal_logic.hasMentorProposalAssigned(mentor)
    self.assertFalse(has_proposal)

    # seed a new proposal and assign the mentor
    student = profile_utils.seedNDBStudent(self.program)
    proposal_utils.seedProposal(
        student.key, self.program.key(), org_key=self.foo_organization.key,
        mentor_key=mentor.key)

    # mentor has a proposal now
    has_proposal = proposal_logic.hasMentorProposalAssigned(mentor)
    self.assertTrue(has_proposal)

    # mentor has also proposal for foo organization
    has_proposal = proposal_logic.hasMentorProposalAssigned(
        mentor, org_key=self.foo_organization.key)
    self.assertTrue(has_proposal)

    # mentor does not have proposal for bar organization
    has_proposal = proposal_logic.hasMentorProposalAssigned(
        mentor, org_key=self.bar_organization.key)
    self.assertFalse(has_proposal)
示例#2
0
    def testHasMentorProposalAssigned(self):
        """Unit test for proposal_logic.hasMentorProposalAssigned function."""
        # seed a new mentor
        mentor = profile_utils.seedNDBProfile(
            self.program.key(), mentor_for=[self.foo_organization.key])

        # mentor has no proposals
        has_proposal = proposal_logic.hasMentorProposalAssigned(mentor)
        self.assertFalse(has_proposal)

        # seed a new proposal and assign the mentor
        student = profile_utils.seedNDBStudent(self.program)
        proposal_utils.seedProposal(student.key,
                                    self.program.key(),
                                    org_key=self.foo_organization.key,
                                    mentor_key=mentor.key)

        # mentor has a proposal now
        has_proposal = proposal_logic.hasMentorProposalAssigned(mentor)
        self.assertTrue(has_proposal)

        # mentor has also proposal for foo organization
        has_proposal = proposal_logic.hasMentorProposalAssigned(
            mentor, org_key=self.foo_organization.key)
        self.assertTrue(has_proposal)

        # mentor does not have proposal for bar organization
        has_proposal = proposal_logic.hasMentorProposalAssigned(
            mentor, org_key=self.bar_organization.key)
        self.assertFalse(has_proposal)
示例#3
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
示例#4
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