Пример #1
0
  def testSubmitProposal(self):
    mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
    mentor.createOtherUser('*****@*****.**')
    mentor.createMentor(self.org)
    mentor.notificationSettings(
        new_proposals=True, public_comments=True, private_comments=True)

    other_mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
    other_mentor.createOtherUser('*****@*****.**')
    other_mentor.createMentor(self.org)
    other_mentor.notificationSettings()

    self.data.createStudent()
    self.data.notificationSettings()
    self.timeline.studentSignup()
    url = '/gsoc/proposal/submit/' + self.org.key().name()
    response = self.get(url)
    self.assertProposalTemplatesUsed(response)

    # test proposal POST
    override = {
        'program': self.gsoc, 'score': 0, 'nr_scores': 0, 'mentor': None,
        'org': self.org, 'status': 'pending', 'accept_as_project': False,
        'is_editable_post_deadline': False, 'extra': None, 'has_mentor': False,
    }
    response, properties = self.modelPost(url, GSoCProposal, override)
    self.assertResponseRedirect(response)

    self.assertEmailSent(to=mentor.profile.email, n=1)
    self.assertEmailNotSent(to=other_mentor.profile.email)

    proposal = GSoCProposal.all().get()
    self.assertPropertiesEqual(properties, proposal)
Пример #2
0
  def testProposalsSubmissionLimit(self):
    self.gsoc.apps_tasks_limit = 5
    self.gsoc.put()

    mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
    mentor.createOtherUser('*****@*****.**')
    mentor.createMentor(self.org)
    mentor.notificationSettings(
        new_proposals=True, public_comments=True, private_comments=True)

    other_mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
    other_mentor.createOtherUser('*****@*****.**')
    other_mentor.createMentor(self.org)
    other_mentor.notificationSettings()

    self.data.createStudent()
    self.data.notificationSettings()
    self.timeline.studentSignup()

    override = {
        'program': self.gsoc, 'score': 0, 'nr_scores': 0, 'mentor': None,
        'org': self.org, 'status': 'pending', 'accept_as_project': False,
        'is_editable_post_deadline': False, 'extra': None, 'has_mentor': False,
    }

    url = '/gsoc/proposal/submit/' + self.org.key().name()

    # Try to submit proposals four times.
    for i in range(5):
      response, properties = self.modelPost(url, GSoCProposal, override)
      self.assertResponseRedirect(response)

    response, properties = self.modelPost(url, GSoCProposal, override)
    self.assertResponseForbidden(response)
Пример #3
0
 def createStudent(self, email, n_proposals):
   """Creates a student with proposals.
   """
   student = GSoCProfileHelper(self.gsoc, self.dev_test)
   student.createOtherUser(email)
   student.createStudentWithProposals(self.org, self.mentor.profile,
                                      n=n_proposals)
   student.notificationSettings()
   return student
Пример #4
0
 def createStudent(self, email, n_proposals):
   """Creates a student with proposals.
   """
   student = GSoCProfileHelper(self.gsoc, self.dev_test)
   student.createOtherUser(email)
   student.createStudentWithProposals(self.org, self.mentor.profile,
                                      n=n_proposals)
   student.notificationSettings()
   return student
Пример #5
0
    def testRequestMentor(self):
        admin = GSoCProfileHelper(self.gsoc, self.dev_test)
        admin.createOtherUser('*****@*****.**')
        admin.createOrgAdmin(self.org)
        admin.notificationSettings(new_requests=True)

        other_admin = GSoCProfileHelper(self.gsoc, self.dev_test)
        other_admin.createOtherUser('*****@*****.**')
        other_admin.createOrgAdmin(self.org)
        other_admin.notificationSettings()

        # test GET
        self.data.createProfile()
        url = '/gsoc/request/' + self.org.key().name()
        response = self.get(url)
        self.assertRequestTemplatesUsed(response)

        # test POST
        override = {
            'status': 'pending',
            'role': 'mentor',
            'type': 'Request',
            'user': self.data.user,
            'org': self.org
        }
        response, properties = self.modelPost(url, GSoCRequest, override)

        request = GSoCRequest.all().get()
        self.assertPropertiesEqual(properties, request)

        self.assertEmailSent(to=admin.profile.email, n=1)
        self.assertEmailNotSent(to=other_admin.profile.email)

        # test withdrawing a request
        url = '/gsoc/request/%s/%s/%s' % (self.gsoc.key().name(),
                                          request.parent_key().name(),
                                          request.key().id())

        postdata = {'action': 'Withdraw'}
        response = self.post(url, postdata)
        self.assertResponseRedirect(response)
        request = GSoCRequest.all().get()
        self.assertEqual('withdrawn', request.status)

        # test that you can resubmit
        postdata = {'action': 'Resubmit'}
        response = self.post(url, postdata)
        self.assertResponseRedirect(response)
        request = GSoCRequest.all().get()
        self.assertEqual('pending', request.status)
Пример #6
0
    def testUpdateProposal(self):
        """Test update proposals.
    """
        mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
        mentor.createOtherUser('*****@*****.**')
        mentor.createMentor(self.org)
        mentor.notificationSettings(proposal_updates=True)

        self.data.createStudentWithProposal(self.org, mentor.profile)
        self.data.notificationSettings()
        self.timeline.studentSignup()

        proposal = GSoCProposal.all().get()

        url = '/gsoc/proposal/update/%s/%s' % (self.gsoc.key().name(),
                                               proposal.key().id())
        response = self.get(url)
        self.assertProposalTemplatesUsed(response)

        override = {
            'program': self.gsoc,
            'score': 0,
            'nr_scores': 0,
            'has_mentor': True,
            'mentor': mentor.profile,
            'org': self.org,
            'status': 'pending',
            'action': 'Update',
            'is_publicly_visible': False,
            'extra': None,
            'accept_as_project': False,
            'is_editable_post_deadline': False
        }
        response, properties = self.modelPost(url, GSoCProposal, override)
        self.assertResponseRedirect(response)

        properties.pop('action')

        proposal = GSoCProposal.all().get()
        self.assertPropertiesEqual(properties, proposal)

        # after update last_modified_on should be updated which is not equal
        # to created_on
        self.assertNotEqual(proposal.created_on, proposal.last_modified_on)

        self.assertEmailSent(to=mentor.profile.email, n=1)
Пример #7
0
  def testRequestMentor(self):
    admin = GSoCProfileHelper(self.gsoc, self.dev_test)
    admin.createOtherUser('*****@*****.**')
    admin.createOrgAdmin(self.org)
    admin.notificationSettings(new_requests=True)

    other_admin = GSoCProfileHelper(self.gsoc, self.dev_test)
    other_admin.createOtherUser('*****@*****.**')
    other_admin.createOrgAdmin(self.org)
    other_admin.notificationSettings()

    # test GET
    self.data.createProfile()
    url = '/gsoc/request/' + self.org.key().name()
    response = self.get(url)
    self.assertRequestTemplatesUsed(response)

    # test POST
    override = {'status': 'pending', 'role': 'mentor', 'type': 'Request',
                'user': self.data.user, 'org': self.org}
    response, properties = self.modelPost(url, GSoCRequest, override)

    request = GSoCRequest.all().get()
    self.assertPropertiesEqual(properties, request)

    self.assertEmailSent(to=admin.profile.email, n=1)
    self.assertEmailNotSent(to=other_admin.profile.email)

    # test withdrawing a request
    url = '/gsoc/request/%s/%s/%s' % (
        self.gsoc.key().name(),
        request.parent_key().name(),
        request.key().id())

    postdata = {'action': 'Withdraw'}
    response = self.post(url, postdata)
    self.assertResponseRedirect(response)
    request = GSoCRequest.all().get()
    self.assertEqual('withdrawn', request.status)

    # test that you can resubmit
    postdata = {'action': 'Resubmit'}
    response = self.post(url, postdata)
    self.assertResponseRedirect(response)
    request = GSoCRequest.all().get()
    self.assertEqual('pending', request.status)
Пример #8
0
    def testProposalsSubmissionLimit(self):
        self.gsoc.apps_tasks_limit = 5
        self.gsoc.put()

        mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
        mentor.createOtherUser('*****@*****.**')
        mentor.createMentor(self.org)
        mentor.notificationSettings(new_proposals=True,
                                    public_comments=True,
                                    private_comments=True)

        other_mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
        other_mentor.createOtherUser('*****@*****.**')
        other_mentor.createMentor(self.org)
        other_mentor.notificationSettings()

        self.data.createStudent()
        self.data.notificationSettings()
        self.timeline.studentSignup()

        override = {
            'program': self.gsoc,
            'score': 0,
            'nr_scores': 0,
            'mentor': None,
            'org': self.org,
            'status': 'pending',
            'accept_as_project': False,
            'is_editable_post_deadline': False,
            'extra': None,
            'has_mentor': False,
        }

        url = '/gsoc/proposal/submit/' + self.org.key().name()

        # Try to submit proposals four times.
        for i in range(5):
            response, properties = self.modelPost(url, GSoCProposal, override)
            self.assertResponseRedirect(response)

        response, properties = self.modelPost(url, GSoCProposal, override)
        self.assertResponseForbidden(response)
Пример #9
0
    def testRequestMentor(self):
        admin = GSoCProfileHelper(self.gsoc, self.dev_test)
        admin.createOtherUser("*****@*****.**")
        admin.createOrgAdmin(self.org)
        admin.notificationSettings(new_requests=True)

        other_admin = GSoCProfileHelper(self.gsoc, self.dev_test)
        other_admin.createOtherUser("*****@*****.**")
        other_admin.createOrgAdmin(self.org)
        other_admin.notificationSettings()

        # test GET
        self.data.createProfile()
        url = "/gsoc/request/" + self.org.key().name()
        response = self.get(url)
        self.assertRequestTemplatesUsed(response)

        # test POST
        override = {"status": "pending", "role": "mentor", "type": "Request", "user": self.data.user, "org": self.org}
        response, properties = self.modelPost(url, GSoCRequest, override)

        request = GSoCRequest.all().get()
        self.assertPropertiesEqual(properties, request)

        self.assertEmailSent(to=admin.profile.email, n=1)
        self.assertEmailNotSent(to=other_admin.profile.email)

        # test withdrawing a request
        url = "/gsoc/request/%s/%s" % (self.gsoc.key().name(), request.key().id())

        postdata = {"action": "Withdraw"}
        response = self.post(url, postdata)
        self.assertResponseRedirect(response)
        request = GSoCRequest.all().get()
        self.assertEqual("withdrawn", request.status)

        # test that you can resubmit
        postdata = {"action": "Resubmit"}
        response = self.post(url, postdata)
        self.assertResponseRedirect(response)
        request = GSoCRequest.all().get()
        self.assertEqual("pending", request.status)
Пример #10
0
    def testSubmitProposal(self):
        mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
        mentor.createOtherUser('*****@*****.**')
        mentor.createMentor(self.org)
        mentor.notificationSettings(new_proposals=True,
                                    public_comments=True,
                                    private_comments=True)

        other_mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
        other_mentor.createOtherUser('*****@*****.**')
        other_mentor.createMentor(self.org)
        other_mentor.notificationSettings()

        self.data.createStudent()
        self.data.notificationSettings()
        self.timeline.studentSignup()
        url = '/gsoc/proposal/submit/' + self.org.key().name()
        response = self.get(url)
        self.assertProposalTemplatesUsed(response)

        # test proposal POST
        override = {
            'program': self.gsoc,
            'score': 0,
            'nr_scores': 0,
            'mentor': None,
            'org': self.org,
            'status': 'pending',
            'accept_as_project': False,
            'is_editable_post_deadline': False,
            'extra': None,
            'has_mentor': False,
        }
        response, properties = self.modelPost(url, GSoCProposal, override)
        self.assertResponseRedirect(response)

        self.assertEmailSent(to=mentor.profile.email, n=1)
        self.assertEmailNotSent(to=other_mentor.profile.email)

        proposal = GSoCProposal.all().get()
        self.assertPropertiesEqual(properties, proposal)
Пример #11
0
  def testUpdateProposal(self):
    """Test update proposals.
    """
    mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
    mentor.createOtherUser('*****@*****.**')
    mentor.createMentor(self.org)
    mentor.notificationSettings(proposal_updates=True)

    self.data.createStudentWithProposal(self.org, mentor.profile)
    self.data.notificationSettings()
    self.timeline.studentSignup()

    proposal = GSoCProposal.all().get()

    url = '/gsoc/proposal/update/%s/%s' % (
        self.gsoc.key().name(), proposal.key().id())
    response = self.get(url)
    self.assertProposalTemplatesUsed(response)

    override = {
        'program': self.gsoc, 'score': 0, 'nr_scores': 0, 'has_mentor': True,
        'mentor': mentor.profile, 'org': self.org, 'status': 'pending',
        'action': 'Update', 'is_publicly_visible': False, 'extra': None,
        'accept_as_project': False, 'is_editable_post_deadline': False
    }
    response, properties = self.modelPost(url, GSoCProposal, override)
    self.assertResponseRedirect(response)

    properties.pop('action')

    proposal = GSoCProposal.all().get()
    self.assertPropertiesEqual(properties, proposal)

    # after update last_modified_on should be updated which is not equal
    # to created_on
    self.assertNotEqual(proposal.created_on, proposal.last_modified_on)

    self.assertEmailSent(to=mentor.profile.email, n=1)
Пример #12
0
 def createMentorWithSettings(self, email, notification_settings={}):
   mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
   mentor.createOtherUser(email)
   mentor.createMentor(self.org)
   mentor.notificationSettings(**notification_settings)
   return mentor
Пример #13
0
 def createMentorWithSettings(self, email, notification_settings={}):
     mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
     mentor.createOtherUser(email)
     mentor.createMentor(self.org)
     mentor.notificationSettings(**notification_settings)
     return mentor
Пример #14
0
class AcceptProposalsTest(MailTestCase, GSoCDjangoTestCase, TaskQueueTestCase):
  """Tests for accept_proposals task.
  """

  ACCEPT_URL = '/tasks/gsoc/accept_proposals/accept'
  REJECT_URL = '/tasks/gsoc/accept_proposals/reject'
  MAIN_URL = '/tasks/gsoc/accept_proposals/main'

  def setUp(self):

    super(AcceptProposalsTest, self).setUp()
    self.init()
    self.createHost()
    self.createMentor()
    self.acceptProposals()

  def createHost(self):
    """Sets program host.
    """
    self.host = self.data
    self.host.createHost()
    self.host.createProfile()

  def createMentor(self):
    """Creates a mentor for organization.
    """
    self.mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
    self.mentor.createOtherUser('*****@*****.**')
    self.mentor.createMentor(self.org)
    self.mentor.notificationSettings()

  def createStudent(self, email, n_proposals):
    """Creates a student with proposals.
    """
    student = GSoCProfileHelper(self.gsoc, self.dev_test)
    student.createOtherUser(email)
    student.createStudentWithProposals(self.org, self.mentor.profile,
                                       n=n_proposals)
    student.notificationSettings()
    return student

  def acceptProposals(self):
    """Set student proposals' acceptance state and make sure the organization
    has slots available.
    """
    self.student1 = self.createStudent('*****@*****.**',
                                       n_proposals=2)
    self.student1_proposals = GSoCProposal.all().ancestor(
        self.student1.profile)
    self.student2 = self.createStudent('*****@*****.**',
                                       n_proposals=3)
    self.student2_proposals = GSoCProposal.all().ancestor(
        self.student2.profile)

    self.assertEqual(self.student1_proposals.count(), 2)
    self.assertEqual(self.student2_proposals.count(), 3)

    #accept 1 of 2 proposal of student1
    proposal1 = self.student1_proposals[0]
    proposal1.accept_as_project = True
    proposal1.put()

    proposal2 = self.student1_proposals[1]
    proposal2.accept_as_project = False
    proposal2.put()

    #reject all proposals of student2
    for proposal in self.student2_proposals:
      proposal.accept_as_project = False
      proposal.put()

    self.org.slots = 5
    self.org.put()

    self.timeline.studentsAnnounced()

  def testConvertProposals(self):
    """Tests convert proposal task runs successfully.
    """
    post_data = {'program_key': self.gsoc.key().name()}
    response = self.post(self.MAIN_URL, post_data)
    self.assertEqual(response.status_code, httplib.OK)

    #assert accept task started for first org
    self.assertTasksInQueue(n=1, url=self.ACCEPT_URL)

    #assert main task started for next org
    self.assertTasksInQueue(n=1, url=self.MAIN_URL)

    #assert parameters to tasks
    for task in self.get_tasks():
      if task['url'] == self.ACCEPT_URL:
        expected_params = {'org_key':
                          urllib.quote_plus(self.org.key().id_or_name())}
        self.assertEqual(expected_params, task['params'])

      elif task['url'] == self.MAIN_URL:
        q = GSoCOrganization.all()
        q.filter('scope', self.gsoc)
        q.filter('status', 'active')
        q.get()
        expected_params = {'org_cursor': q.cursor(),
                           'program_key': urllib.quote_plus(
                               self.gsoc.key().name())}

        #as we can't know XSRF token, ignore it
        self.assertNotEqual(task['params'].get('xsrf_token'), None)
        task_params = task['params'].copy()
        del task_params['xsrf_token']

        self.assertEqual(expected_params, task_params)

  def testConverProposalsWithMissingParemeters(self):
    """Tests no tasks are queued if program_key is not supplied.
    """
    post_data = {}
    response = self.post(self.MAIN_URL, post_data)

    #assert no task started
    self.assertTasksInQueue(n=0, url=self.ACCEPT_URL)

  def testAcceptProposals(self):
    """Tests accept task for an organization.
    """
    from soc.modules.gsoc.models.program import GSoCProgramMessages
    properties = {
        'parent': self.gsoc,
    }
    self.seed(GSoCProgramMessages, properties)

    #assert current status of proposal to be accepted
    self.assertEqual(self.student1_proposals[0].status, 'pending')

    post_data = {'org_key': self.org.key().name(),
                 'program_key': self.gsoc.key().name()}
    response = self.post(self.ACCEPT_URL, post_data)

    #assert accepted student got proper emails
    self.assertEqual(response.status_code, httplib.OK)
    self.assertEmailSent(to=self.student1.profile.email,
                         subject='Congratulations!')
    self.assertEmailNotSent(to=self.student2.profile.email)

    #assert post status of proposal to be accepted
    self.assertEqual(self.student1_proposals[0].status, 'accepted')

    #assert a project created and associated with accepted student
    projects = GSoCProject.all().ancestor(self.student1.profile)
    self.assertEqual(projects.count(), 1)
    project = projects.get()
    self.assertEqual(project.status, 'accepted')

    #assert reject task is queued
    self.assertTasksInQueue(n=1, url=self.REJECT_URL)

    #assert parameters to task
    for task in self.get_tasks():
      if task['url'] == self.REJECT_URL:
        expected_params = {'org_key':
                           urllib.quote_plus(self.org.key().name()),
                           'program_key':
                           urllib.quote_plus(self.gsoc.key().name())}

        #ignore xsrf token
        self.assertNotEqual(task['params'].get('xsrf_token'), None)
        task_params = task['params'].copy()
        del task_params['xsrf_token']

        self.assertEqual(expected_params, task_params)


    # test reject proposals

    post_data = {'org_key': self.org.key().name(),
                 'program_key': self.gsoc.key().name()}
    response = self.post(self.REJECT_URL, post_data)
    self.assertEqual(response.status_code, httplib.OK)

    #assert post status of proposals
    self.assertEqual(self.student1_proposals[0].status, 'accepted')
    self.assertEqual(self.student1_proposals[1].status, 'rejected')
    self.assertEqual(self.student2_proposals[0].status, 'rejected')
    self.assertEqual(self.student2_proposals[1].status, 'rejected')
    self.assertEqual(self.student2_proposals[2].status, 'rejected')

    #assert student2 got a reject email
    self.assertEmailSent(to=self.student2.profile.email,
                         subject='Thank you for applying to %s'
                         % self.gsoc.name)
    #assert student2 got no accept email
    self.assertEmailNotSent(to=self.student2.profile.email,
                            subject='Congratulations!')
    #assert student1 got a reject email (already got an accept mail)
    self.assertEmailSent(to=self.student1.profile.email,
                        subject='Thank you for applying to %s'
                        % self.gsoc.name)

    #assert no projects are created for rejected student
    projects = GSoCProject.all().ancestor(self.student2.profile)
    self.assertEqual(projects.count(), 0)
Пример #15
0
  def testInviteOrgAdmin(self):
    # test GET
    self.data.createOrgAdmin(self.org)
    url = '/gsoc/invite/org_admin/' + self.org.key().name()
    response = self.get(url)
    self.assertInviteTemplatesUsed(response)

    # create other user to send invite to
    other_data = GSoCProfileHelper(self.gsoc, self.dev_test)
    other_data.createOtherUser('*****@*****.**')
    other_data.createProfile()
    other_data.notificationSettings(new_invites=True)
    other_user = other_data.user

    # test POST
    override = {
        'link_id': other_user.link_id, 'status': 'pending',
        'role': 'org_admin', 'user': other_user, 'org': self.org,
        'type': 'Invitation',
        'parent': other_user,
    }
    response, properties = self.modelPost(url, GSoCRequest, override)
    self.assertEmailSent(to=other_data.profile.email, n=1)

    invitation = GSoCRequest.all().get()
    properties.pop('link_id')
    self.assertPropertiesEqual(properties, invitation)

    other_data2 = GSoCProfileHelper(self.gsoc, self.dev_test)
    other_data2.createOtherUser('*****@*****.**')
    other_data2.createProfile()
    other_data2.notificationSettings()

    invitation.delete()
    override['link_id'] = '[email protected], [email protected]'
    other_data.notificationSettings()
    response, properties = self.modelPost(url, GSoCRequest, override)
    self.assertEmailSent(to=other_data.profile.email, n=1)

    invitations = GSoCRequest.all().fetch(2)
    self.assertEqual(2, len(invitations))
    invitation = invitations[0]
    properties.pop('link_id')
    self.assertPropertiesEqual(properties, invitation)
    properties['user'] = other_data2.user
    properties['parent'] = other_data2.user
    self.assertPropertiesEqual(properties, invitations[1])

    # test withdraw/resubmit invite
    url = '/gsoc/invitation/%s/%s/%s' % (
	self.gsoc.key().name(),
	invitation.parent_key().name(),
	invitation.key().id())

    other_data.notificationSettings(invite_handled=True)

    postdata = {'action': 'Withdraw'}
    response = self.post(url, postdata)
    self.assertResponseRedirect(response)
    invite = GSoCRequest.all().get()
    self.assertEqual('withdrawn', invite.status)
    self.assertEmailSent(to=other_data.profile.email, n=2)

    # test that you can resubmit
    postdata = {'action': 'Resubmit'}
    response = self.post(url, postdata)
    self.assertResponseRedirect(response)
    invite = GSoCRequest.all().get()
    self.assertEqual('pending', invite.status)
    self.assertEmailSent(to=other_data.profile.email, n=3)
Пример #16
0
class AcceptProposalsTest(MailTestCase, GSoCDjangoTestCase, TaskQueueTestCase):
  """Tests for accept_proposals task.
  """

  ACCEPT_URL = '/tasks/gsoc/accept_proposals/accept'
  REJECT_URL = '/tasks/gsoc/accept_proposals/reject'
  MAIN_URL = '/tasks/gsoc/accept_proposals/main'

  def setUp(self):

    super(AcceptProposalsTest, self).setUp()
    self.init()
    self.createHost()
    self.createMentor()
    self.acceptProposals()

  def createHost(self):
    """Sets program host.
    """
    self.host = self.data
    self.host.createHost()
    self.host.createProfile()

  def createMentor(self):
    """Creates a mentor for organization.
    """
    self.mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
    self.mentor.createOtherUser('*****@*****.**')
    self.mentor.createMentor(self.org)
    self.mentor.notificationSettings()

  def createStudent(self, email, n_proposals):
    """Creates a student with proposals.
    """
    student = GSoCProfileHelper(self.gsoc, self.dev_test)
    student.createOtherUser(email)
    student.createStudentWithProposals(self.org, self.mentor.profile,
                                       n=n_proposals)
    student.notificationSettings()
    return student

  def acceptProposals(self):
    """Set student proposals' acceptance state and make sure the organization
    has slots available.
    """
    self.student1 = self.createStudent('*****@*****.**',
                                       n_proposals=2)
    self.student1_proposals = GSoCProposal.all().ancestor(
        self.student1.profile)
    self.student2 = self.createStudent('*****@*****.**',
                                       n_proposals=3)
    self.student2_proposals = GSoCProposal.all().ancestor(
        self.student2.profile)

    self.assertEqual(self.student1_proposals.count(), 2)
    self.assertEqual(self.student2_proposals.count(), 3)

    #accept 1 of 2 proposal of student1
    proposal1 = self.student1_proposals[0]
    proposal1.accept_as_project = True
    proposal1.put()

    proposal2 = self.student1_proposals[1]
    proposal2.accept_as_project = False
    proposal2.put()

    #reject all proposals of student2
    for proposal in self.student2_proposals:
      proposal.accept_as_project = False
      proposal.put()

    self.org.slots = 5
    self.org.put()

    self.timeline.studentsAnnounced()

  def testConvertProposals(self):
    """Tests convert proposal task runs successfully.
    """
    post_data = {'program_key': self.gsoc.key().name()}
    response = self.post(self.MAIN_URL, post_data)
    self.assertEqual(response.status_code, httplib.OK)

    #assert accept task started for first org
    self.assertTasksInQueue(n=1, url=self.ACCEPT_URL)

    #assert main task started for next org
    self.assertTasksInQueue(n=1, url=self.MAIN_URL)

    #assert parameters to tasks
    for task in self.get_tasks():
      if task['url'] == self.ACCEPT_URL:
        expected_params = {'org_key':
                          urllib.quote_plus(self.org.key().id_or_name())}
        self.assertEqual(expected_params, task['params'])

      elif task['url'] == self.MAIN_URL:
        q = GSoCOrganization.all()
        q.filter('scope', self.gsoc)
        q.filter('status', 'active')
        q.get()
        expected_params = {'org_cursor': q.cursor(),
                           'program_key': urllib.quote_plus(
                               self.gsoc.key().name())}

        #as we can't know XSRF token, ignore it
        self.assertNotEqual(task['params'].get('xsrf_token'), None)
        task_params = task['params'].copy()
        del task_params['xsrf_token']

        self.assertEqual(expected_params, task_params)

  def testConverProposalsWithMissingParemeters(self):
    """Tests no tasks are queued if program_key is not supplied.
    """
    post_data = {}
    response = self.post(self.MAIN_URL, post_data)

    #assert no task started
    self.assertTasksInQueue(n=0, url=self.ACCEPT_URL)

  def testAcceptProposals(self):
    """Tests accept task for an organization.
    """
    #assert current status of proposal to be accepted
    self.assertEqual(self.student1_proposals[0].status, 'pending')

    post_data = {'org_key': self.org.key().name(),
                 'program_key': self.gsoc.key().name()}
    response = self.post(self.ACCEPT_URL, post_data)

    #assert accepted student got proper emails
    self.assertEqual(response.status_code, httplib.OK)
    self.assertEmailSent(to=self.student1.profile.email,
                         subject='Congratulations!')
    self.assertEmailNotSent(to=self.student2.profile.email)

    #assert post status of proposal to be accepted
    self.assertEqual(self.student1_proposals[0].status, 'accepted')

    #assert a project created and associated with accepted student
    projects = GSoCProject.all().ancestor(self.student1.profile)
    self.assertEqual(projects.count(), 1)
    project = projects.get()
    self.assertEqual(project.status, 'accepted')

    #assert reject task is queued
    self.assertTasksInQueue(n=1, url=self.REJECT_URL)

    #assert parameters to task
    for task in self.get_tasks():
      if task['url'] == self.REJECT_URL:
        expected_params = {'org_key':
                           urllib.quote_plus(self.org.key().name()),
                           'program_key':
                           urllib.quote_plus(self.gsoc.key().name())}

        #ignore xsrf token
        self.assertNotEqual(task['params'].get('xsrf_token'), None)
        task_params = task['params'].copy()
        del task_params['xsrf_token']

        self.assertEqual(expected_params, task_params)

  def testRejectProposals(self):
    """Tests reject task for an organization.
    """
    self.testAcceptProposals()
    post_data = {'org_key': self.org.key().name(),
                 'program_key': self.gsoc.key().name()}
    response = self.post(self.REJECT_URL, post_data)
    self.assertEqual(response.status_code, httplib.OK)

    #assert post status of proposals
    self.assertEqual(self.student1_proposals[0].status, 'accepted')
    self.assertEqual(self.student1_proposals[1].status, 'rejected')
    self.assertEqual(self.student2_proposals[0].status, 'rejected')
    self.assertEqual(self.student2_proposals[1].status, 'rejected')
    self.assertEqual(self.student2_proposals[2].status, 'rejected')

    #assert student2 got a reject email
    self.assertEmailSent(to=self.student2.profile.email,
                         subject='Thank you for applying to %s'
                         % self.gsoc.name)
    #assert student2 got no accept email
    self.assertEmailNotSent(to=self.student2.profile.email,
                            subject='Congratulations!')
    #assert student1 got a reject email (already got an accept mail)
    self.assertEmailSent(to=self.student1.profile.email,
                        subject='Thank you for applying to %s'
                        % self.gsoc.name)

    #assert no projects are created for rejected student
    projects = GSoCProject.all().ancestor(self.student2.profile)
    self.assertEqual(projects.count(), 0)
Пример #17
0
    def testInviteOrgAdmin(self):
        # test GET
        self.data.createOrgAdmin(self.org)
        url = '/gsoc/invite/org_admin/' + self.org.key().name()
        response = self.get(url)
        self.assertInviteTemplatesUsed(response)

        # create other user to send invite to
        other_data = GSoCProfileHelper(self.gsoc, self.dev_test)
        other_data.createOtherUser('*****@*****.**')
        other_data.createProfile()
        other_data.notificationSettings(new_invites=True)
        other_user = other_data.user

        # test POST
        override = {
            'link_id': other_user.link_id,
            'status': 'pending',
            'role': 'org_admin',
            'user': other_user,
            'org': self.org,
            'type': 'Invitation',
            'parent': other_user,
        }
        response, properties = self.modelPost(url, GSoCRequest, override)
        self.assertEmailSent(to=other_data.profile.email, n=1)

        invitation = GSoCRequest.all().get()
        properties.pop('link_id')
        self.assertPropertiesEqual(properties, invitation)

        other_data2 = GSoCProfileHelper(self.gsoc, self.dev_test)
        other_data2.createOtherUser('*****@*****.**')
        other_data2.createProfile()
        other_data2.notificationSettings()

        invitation.delete()
        override[
            'link_id'] = '[email protected], [email protected]'
        other_data.notificationSettings()
        response, properties = self.modelPost(url, GSoCRequest, override)
        self.assertEmailSent(to=other_data.profile.email, n=1)

        invitations = GSoCRequest.all().fetch(2)
        self.assertEqual(2, len(invitations))
        invitation = invitations[0]
        properties.pop('link_id')
        self.assertPropertiesEqual(properties, invitation)
        properties['user'] = other_data2.user
        properties['parent'] = other_data2.user
        self.assertPropertiesEqual(properties, invitations[1])

        # test withdraw/resubmit invite
        url = '/gsoc/invitation/%s/%s/%s' % (self.gsoc.key().name(),
                                             invitation.parent_key().name(),
                                             invitation.key().id())

        other_data.notificationSettings(invite_handled=True)

        postdata = {'action': 'Withdraw'}
        response = self.post(url, postdata)
        self.assertResponseRedirect(response)
        invite = GSoCRequest.all().get()
        self.assertEqual('withdrawn', invite.status)
        self.assertEmailSent(to=other_data.profile.email, n=2)

        # test that you can resubmit
        postdata = {'action': 'Resubmit'}
        response = self.post(url, postdata)
        self.assertResponseRedirect(response)
        invite = GSoCRequest.all().get()
        self.assertEqual('pending', invite.status)
        self.assertEmailSent(to=other_data.profile.email, n=3)