Пример #1
0
  def testNotActiveMentor(self):
    # seed invalid mentor for organization one
    profile_utils.seedNDBProfile(
        self.program.key(), mentor_for=[self.organization_one.key],
        status=profile_model.Status.BANNED)

    # not active mentor not returned
    mentors = profile_logic.getMentors(self.organization_one.key)
    self.assertEqual(mentors, [])

    # keys_only set to True does not return any keys
    mentors_keys = profile_logic.getMentors(
        self.organization_one.key, keys_only=True)
    self.assertEqual(mentors_keys, [])
Пример #2
0
  def testForOrgAdmin(self):
    # seed a new org admin for organization one
    org_admin = profile_utils.seedNDBProfile(
        self.program.key(), admin_for=[self.organization_one.key])

    # the org admin should be returned as it is also a mentor
    mentors = profile_logic.getMentors(self.organization_one.key)
    self.assertEqual(len(mentors), 1)
    self.assertEqual(mentors[0].key, org_admin.key)

    # keys_only set to True should return only the key
    mentor_keys = profile_logic.getMentors(
        self.organization_one.key, keys_only=True)
    self.assertEqual(len(mentor_keys), 1)
    self.assertEqual(mentor_keys[0], org_admin.key)
Пример #3
0
  def testManyMentors(self):
    seeded_mentors = set()
    for _ in range(5):
      seeded_mentors.add(
          profile_utils.seedNDBProfile(
              self.program.key(), mentor_for=[self.organization_one.key]).key)

    # all mentors should be returned
    mentors = profile_logic.getMentors(self.organization_one.key)
    self.assertEqual(len(mentors), 5)
    self.assertEqual(seeded_mentors, set([mentor.key for mentor in mentors]))

    # all mentors keys should be returned if keys_only set
    mentor_keys = profile_logic.getMentors(
        self.organization_one.key, keys_only=True)
    self.assertEqual(len(mentor_keys), 5)
    self.assertEqual(seeded_mentors, set(mentor_keys))
Пример #4
0
  def testOneMentor(self):
    # seed a new mentor for organization one
    mentor = profile_utils.seedNDBProfile(
        self.program.key(), mentor_for=[self.organization_one.key])

    # the mentor should be returned
    mentors = profile_logic.getMentors(self.organization_one.key)
    self.assertEqual(len(mentors), 1)
    self.assertEqual(mentors[0].key, mentor.key)

    # keys_only set to True should return only the key
    mentor_keys = profile_logic.getMentors(
        self.organization_one.key, keys_only=True)
    self.assertEqual(len(mentor_keys), 1)
    self.assertEqual(mentor_keys[0], mentor.key)

    # there is still no mentor for organization two
    mentors = profile_logic.getMentors(self.organization_two.key)
    self.assertEqual(mentors, [])
Пример #5
0
    def createFromForm(self, data):
        """Creates a new proposal based on the data inserted in the form.

    Args:
      data: A RequestData describing the current request.

    Returns:
      a newly created proposal entity or None
    """
        proposal_form = ProposalForm(data=data.POST)

        if not proposal_form.is_valid():
            return None

        # set the organization and program references
        proposal_properties = proposal_form.asDict()
        proposal_properties['org'] = data.url_ndb_org.key.to_old_key()
        proposal_properties['program'] = data.program

        # TODO(daniel): take care of notifications
        #extra_attrs = {
        #    GSoCProfile.notify_new_proposals: [True]
        #    }
        mentors = profile_logic.getMentors(data.url_ndb_org.key,
                                           extra_attrs=None)

        to_emails = [mentor.contact.email for mentor in mentors]

        def create_proposal_trx():
            profile = data.ndb_profile.key.get()
            profile.student_data.number_of_proposals += 1
            profile.put()

            proposal = GSoCProposal(parent=data.ndb_profile.key.to_old_key(),
                                    **proposal_properties)
            proposal.put()

            context = notifications.newProposalContext(data, proposal,
                                                       to_emails)
            sub_txn = mailer.getSpawnMailTaskTxn(context, parent=proposal)
            sub_txn()

            return proposal

        # return db.run_in_transaction(create_proposal_trx)
        return create_proposal_trx()
Пример #6
0
  def createFromForm(self, data):
    """Creates a new proposal based on the data inserted in the form.

    Args:
      data: A RequestData describing the current request.

    Returns:
      a newly created proposal entity or None
    """
    proposal_form = ProposalForm(data=data.POST)

    if not proposal_form.is_valid():
      return None

    # set the organization and program references
    proposal_properties = proposal_form.asDict()
    proposal_properties['org'] = data.url_ndb_org.key.to_old_key()
    proposal_properties['program'] = data.program

    # TODO(daniel): take care of notifications
    #extra_attrs = {
    #    GSoCProfile.notify_new_proposals: [True]
    #    }
    mentors = profile_logic.getMentors(
        data.url_ndb_org.key, extra_attrs=None)

    to_emails = [mentor.contact.email for mentor in mentors]

    def create_proposal_trx():
      profile = data.ndb_profile.key.get()
      profile.student_data.number_of_proposals += 1
      profile.put()

      proposal = GSoCProposal(
          parent=data.ndb_profile.key.to_old_key(),
          **proposal_properties)
      proposal.put()

      context = notifications.newProposalContext(data, proposal, to_emails)
      sub_txn = mailer.getSpawnMailTaskTxn(context, parent=proposal)
      sub_txn()

      return proposal

    # return db.run_in_transaction(create_proposal_trx)
    return create_proposal_trx()
Пример #7
0
  def testExtraAttrs(self):
    # seed female mentor for organization one
    mentor = profile_utils.seedNDBProfile(
        self.program.key(), mentor_for=[self.organization_one.key],
        gender=profile_model.Gender.FEMALE)

    # seed male mentor for organization one
    profile_utils.seedNDBProfile(
        self.program.key(), mentor_for=[self.organization_one.key],
        gender=profile_model.Gender.MALE)

    # retrieve only mentors with extra attrs
    extra_attrs = {profile_model.Profile.gender: [profile_model.Gender.FEMALE]}
    mentors = profile_logic.getMentors(
        self.organization_one.key, extra_attrs=extra_attrs)

    # only the female mentor should be returned
    self.assertEqual(1, len(mentors))
    self.assertEqual(mentors[0].key, mentor.key)
Пример #8
0
    def _updateFromForm(self, data):
        """Updates a proposal based on the data inserted in the form.

    Args:
      data: A RequestData describing the current request.

    Returns:
      an updated proposal entity or None
    """
        proposal_form = ProposalForm(data=data.POST,
                                     instance=data.url_proposal)

        if not proposal_form.is_valid():
            return None

        org_key = ndb.Key.from_old_key(
            GSoCProposal.org.get_value_for_datastore(data.url_proposal))
        # TODO(daniel): handle hotifications
        #extra_attrs = {
        #    GSoCProfile.notify_proposal_updates: [True]
        #    }
        mentors = profile_logic.getMentors(org_key, extra_attrs=None)

        to_emails = [i.contact.email for i in mentors]

        proposal_key = data.url_proposal.key()

        def update_proposal_txn():
            proposal = db.get(proposal_key)
            proposal_form.instance = proposal
            proposal = proposal_form.save(commit=True)

            context = notifications.updatedProposalContext(
                data, proposal, to_emails)
            sub_txn = mailer.getSpawnMailTaskTxn(context, parent=proposal)
            sub_txn()

            return proposal

        return db.run_in_transaction(update_proposal_txn)
Пример #9
0
  def _updateFromForm(self, data):
    """Updates a proposal based on the data inserted in the form.

    Args:
      data: A RequestData describing the current request.

    Returns:
      an updated proposal entity or None
    """
    proposal_form = ProposalForm(data=data.POST, instance=data.url_proposal)

    if not proposal_form.is_valid():
      return None

    org_key = ndb.Key.from_old_key(
        GSoCProposal.org.get_value_for_datastore(data.url_proposal))
    # TODO(daniel): handle hotifications
    #extra_attrs = {
    #    GSoCProfile.notify_proposal_updates: [True]
    #    }
    mentors = profile_logic.getMentors(org_key, extra_attrs=None)

    to_emails = [i.contact.email for i in mentors]

    proposal_key = data.url_proposal.key()

    def update_proposal_txn():
      proposal = db.get(proposal_key)
      proposal_form.instance = proposal
      proposal = proposal_form.save(commit=True)

      context = notifications.updatedProposalContext(data, proposal, to_emails)
      sub_txn = mailer.getSpawnMailTaskTxn(context, parent=proposal)
      sub_txn()

      return proposal

    return db.run_in_transaction(update_proposal_txn)