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)
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)
class ProjectListTest(GSoCDjangoTestCase): """Tests project list page. """ def setUp(self): self.init() def assertProjectTemplatesUsed(self, response): """Asserts that all the templates from the dashboard were used. """ self.assertGSoCTemplatesUsed(response) self.assertTemplateUsed(response, 'v2/modules/gsoc/projects_list/base.html') self.assertTemplateUsed( response, 'v2/modules/gsoc/projects_list/_project_list.html') def testListProjects(self): self.timeline.studentsAnnounced() url = '/gsoc/projects/list/' + self.gsoc.key().name() response = self.get(url) self.assertProjectTemplatesUsed(response) response = self.getListResponse(url, 0) self.assertIsJsonResponse(response) data = response.context['data'][''] self.assertEqual(0, len(data)) self.mentor = GSoCProfileHelper(self.gsoc, self.dev_test) self.mentor.createMentor(self.org) self.data.createStudentWithProject(self.org, self.mentor.profile) response = self.getListResponse(url, 0) self.assertIsJsonResponse(response) data = response.context['data'][''] self.assertEqual(1, len(data))
class ProjectListTest(GSoCDjangoTestCase): """Tests project list page. """ def setUp(self): self.init() def assertProjectTemplatesUsed(self, response): """Asserts that all the templates from the dashboard were used. """ self.assertGSoCTemplatesUsed(response) self.assertTemplateUsed(response, "v2/modules/gsoc/projects_list/base.html") self.assertTemplateUsed(response, "v2/modules/gsoc/projects_list/_project_list.html") def testListProjects(self): self.timeline.studentsAnnounced() url = "/gsoc/projects/list/" + self.gsoc.key().name() response = self.get(url) self.assertProjectTemplatesUsed(response) response = self.getListResponse(url, 0) self.assertIsJsonResponse(response) data = response.context["data"][""] self.assertEqual(0, len(data)) self.mentor = GSoCProfileHelper(self.gsoc, self.dev_test) self.mentor.createMentor(self.org) self.data.createStudentWithProject(self.org, self.mentor.profile) response = self.getListResponse(url, 0) self.assertIsJsonResponse(response) data = response.context["data"][""] self.assertEqual(1, len(data))
class ProjectsPageTest(GSoCDjangoTestCase): """Test projects list for admin """ def setUp(self): self.init() def assertProjectsPage(self, response): """Asserts that all the templates from the accepted projects list were used and all contexts were passed. """ self.assertTrue('base_layout' in response.context) self.assertTrue('cbox' in response.context) if response.context['cbox']: self.assertGSoCColorboxTemplatesUsed(response) self.assertEqual(response.context['base_layout'], 'v2/modules/gsoc/base_colorbox.html') else: self.assertGSoCTemplatesUsed(response) self.assertEqual(response.context['base_layout'], 'v2/modules/gsoc/base.html') self.assertTemplateUsed(response, 'v2/modules/gsoc/admin/list.html') self.assertTemplateUsed(response, 'v2/modules/gsoc/admin/_projects_list.html') def testListProjects(self): self.data.createHost() self.timeline.studentsAnnounced() url = '/gsoc/admin/projects/' + self.org.key().name() response = self.get(url) self.assertProjectsPage(response) response = self.getListResponse(url, 0) self.assertIsJsonResponse(response) data = response.context['data'][''] self.assertEqual(0, len(data)) # test list with student's proposal self.mentor = GSoCProfileHelper(self.gsoc, self.dev_test) self.mentor.createMentor(self.org) self.data.createStudentWithProjects(self.org, self.mentor.profile, 1) response = self.getListResponse(url, 0) self.assertIsJsonResponse(response) data = response.context['data'][''] self.assertEqual(1, len(data)) # rendered inside cbox iframe url += '?cbox=true' response = self.get(url) self.assertProjectsPage(response)
def createMentor(self, email, organization): """Creates a mentor for the given organization. """ profile_helper = GSoCProfileHelper(self.program, dev_test=False) profile_helper.createOtherUser(email) mentor = profile_helper.createMentor(organization) return mentor
def testTakeEvalForStudent(self): eval = self.evaluation.createStudentEvaluation() mentor_profile = GSoCProfileHelper(self.gsoc, self.dev_test) mentor_profile.createOtherUser('*****@*****.**') mentor = mentor_profile.createMentor(self.org) self.data.createStudentWithProject(self.org, mentor) project = GSoCProject.all().get() base_url = '/gsoc/eval/student' suffix = "%s/%s/%s/%s" % ( self.gsoc.key().name(), eval.link_id, project.parent().link_id, project.key().id()) url = '%s/%s' % (base_url, suffix) # test student evaluation show GET for a for a student who # has another project in a different organization response = self.get(url) self.assertEvaluationTakeTemplateUsed(response) self.assertContains(response, '%s' % (eval.title)) self.assertContains(response, 'Project: %s' % (project.title)) self.assertEqual(response.context['page_name'], '%s' % (eval.title)) form = response.context['forms'][0] self.assertFormFromSchema(form, eval.schema) postdata = { 'frm-t1309871149671-item': 'one line text message', 'frm-t1309871322655-item': ['Option 2', 'Option 3'], 'frm-t1309871157535-item': """A quick brown fox jumped over a lazy dog. A quick brown fox jumped over a lazy dog. A quick brown fox jumped over a lazy dog. A quick brown fox jumped over a lazy dog.""", } response = self.post(url, postdata) self.assertResponseOK(response) self.assertFormError( response, 'form', 'frm-t1310822212610-item', 'This field is required.') postdata = { 'frm-t1309871149671-item': 'one line text message', 'frm-t1309871322655-item': ['Option 2', 'Option 3'], 'frm-t1309871157535-item': """A quick brown fox jumped over a lazy dog. A quick brown fox jumped over a lazy dog. A quick brown fox jumped over a lazy dog. A quick brown fox jumped over a lazy dog.""", 'frm-t1310822212610-item': "Wa Wa", } response = self.post(url, postdata) self.assertResponseRedirect(response, '%s?validated' % (url,)) self.ffPastEval(eval) response = self.get(url) show_url = '%s/show/%s' % (base_url, suffix) self.assertResponseRedirect(response, show_url)
def testWithdrawProjects(self): self.data.createHost() self.timeline.studentsAnnounced() url = '/gsoc/withdraw_projects/' + self.gsoc.key().name() response = self.get(url) self.assertWithdrawProjects(response) # list response without any projects response = self.getListResponse(url, 0) self.assertIsJsonResponse(response) data = response.context['data'][''] self.assertEqual(0, len(data)) # list response with projects mentor_profile_helper = GSoCProfileHelper(self.gsoc, self.dev_test) mentor_profile_helper.createOtherUser('*****@*****.**') mentor = mentor_profile_helper.createMentor(self.org) self.data.createStudentWithProposal(self.org, mentor) self.data.createStudentWithProject(self.org, mentor) response = self.getListResponse(url, 0) self.assertIsJsonResponse(response) data = response.context['data'][''] self.assertEqual(1, len(data))
def testShowEvalForStudent(self): eval = self.evaluation.createStudentEvaluation() mentor_profile = GSoCProfileHelper(self.gsoc, self.dev_test) mentor_profile.createOtherUser('*****@*****.**') mentor = mentor_profile.createMentor(self.org) self.data.createStudentWithProject(self.org, mentor) project = GSoCProject.all().get() suffix = "%s/%s/%s/%s" % ( self.gsoc.key().name(), eval.link_id, project.parent().link_id, project.key().id()) url = '/gsoc/eval/student/show/%s' % (suffix,) # test student evaluation show GET for a for a student who # has another project in a different organization response = self.get(url) self.assertEvaluationShowTemplateUsed(response) self.ffPastEval(eval) response = self.get(url) self.assertEvaluationShowTemplateUsed(response)
def testFeaturedProjectButton(self): self.timeline.studentsAnnounced() student = GSoCProfileHelper(self.gsoc, self.dev_test) student.createOtherUser('*****@*****.**') student.createStudent() self.data.createOrgAdmin(self.org) mentor = GSoCProfileHelper(self.gsoc, self.dev_test) mentor.createOtherUser('*****@*****.**') mentor_entity = mentor.createMentor(self.org) project = self.createProject({'parent': self.data.profile, 'mentor': mentor_entity}) suffix = "%s/%s/%d" % ( self.gsoc.key().name(), self.data.user.key().name(), project.key().id()) url = '/gsoc/project/featured/' + suffix postdata = {'value': 'unchecked'} response = self.post(url, postdata) self.assertResponseOK(response) project = GSoCProject.all().get() self.assertEqual(project.is_featured, True)
def testTakeEvalForStudentProjectWithAnotherOrg(self): url, eval, _ = self.getStudentEvalRecordProperties() other_org = self.createOrg() mentor_profile = GSoCProfileHelper(self.gsoc, self.dev_test) mentor_profile.createOtherUser('*****@*****.**') mentor = mentor_profile.createMentor(other_org) self.data.createStudentWithProject(other_org, mentor) # test student evaluation show GET for a for a student who # has another project in a different organization response = self.get(url) self.assertResponseForbidden(response) project = GSoCProject.all().get() suffix = "%s/%s/%s/%s" % ( self.gsoc.key().name(), eval.link_id, project.parent().link_id, project.key().id()) base_url = '/gsoc/eval/student' self.ffPastEval(eval) response = self.get(url) show_url = '%s/show/%s' % (base_url, suffix) self.assertResponseRedirect(response, show_url)
def testFeaturedProjectButton(self): self.timeline.studentsAnnounced() student = GSoCProfileHelper(self.gsoc, self.dev_test) student.createOtherUser('*****@*****.**') student.createStudent() self.data.createOrgAdmin(self.org) mentor = GSoCProfileHelper(self.gsoc, self.dev_test) mentor.createOtherUser('*****@*****.**') mentor_entity = mentor.createMentor(self.org) project = self.createProject({ 'parent': self.data.profile, 'mentor': mentor_entity }) suffix = "%s/%s/%d" % (self.gsoc.key().name(), self.data.user.key().name(), project.key().id()) url = '/gsoc/project/featured/' + suffix postdata = {'value': 'unchecked'} response = self.post(url, postdata) self.assertResponseOK(response) project = GSoCProject.all().get() self.assertEqual(project.is_featured, True)
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)
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)
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)
def testCreateEvaluationForStudent(self): link_id = LinkIDProvider(ProjectSurvey).getValue() suffix = "%s/%s" % (self.gsoc.key().name(), link_id) mentor_profile = GSoCProfileHelper(self.gsoc, self.dev_test) mentor_profile.createOtherUser('*****@*****.**') mentor = mentor_profile.createMentor(self.org) self.data.createStudentWithProject(self.org, mentor) # test review GET url = '/gsoc/eval/student/edit/' + suffix response = self.get(url) self.assertResponseForbidden(response)
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)
def testShowEvalForStudentProjectWithAnotherOrg(self): url, eval, _ = self.getStudentEvalRecordProperties(show=True) other_org = self.createOrg() mentor_profile = GSoCProfileHelper(self.gsoc, self.dev_test) mentor_profile.createOtherUser('*****@*****.**') mentor = mentor_profile.createMentor(other_org) self.data.createStudentWithProject(other_org, mentor) # test student evaluation show GET for a for a student who # has another project in a different organization response = self.get(url) self.assertResponseForbidden(response) self.ffPastEval(eval) response = self.get(url) self.assertResponseForbidden(response)
def testShowEvalForStudentProjectWithAnotherMentor(self): url, eval, _ = self.getStudentEvalRecordProperties(show=True) mentor_profile = GSoCProfileHelper(self.gsoc, self.dev_test) mentor_profile.createOtherUser('*****@*****.**') mentor = mentor_profile.createMentor(self.org) self.data.createStudentWithProject(self.org, mentor) # test student evaluation show GET for a for a student who # has another project whose mentor is different than the current # mentor but the project is in the same org response = self.get(url) self.assertResponseForbidden(response) self.ffPastEval(eval) response = self.get(url) self.assertResponseForbidden(response)
def testProjectDetails(self): self.data.createStudent() self.timeline.studentsAnnounced() mentor = GSoCProfileHelper(self.gsoc, self.dev_test) mentor.createOtherUser('*****@*****.**') mentor_entity = mentor.createMentor(self.org) project = self.createProject({ 'parent': self.data.profile, 'mentor': mentor_entity }) suffix = "%s/%s/%d" % (self.gsoc.key().name(), self.data.user.key().name(), project.key().id()) # test project details GET url = '/gsoc/project/' + suffix response = self.get(url) self.assertProjectDetailsTemplateUsed(response)
def testProjectDetails(self): self.data.createStudent() self.timeline.studentsAnnounced() mentor = GSoCProfileHelper(self.gsoc, self.dev_test) mentor.createOtherUser('*****@*****.**') mentor_entity = mentor.createMentor(self.org) project = self.createProject({'parent': self.data.profile, 'mentor': mentor_entity}) suffix = "%s/%s/%d" % ( self.gsoc.key().name(), self.data.user.key().name(), project.key().id()) # test project details GET url = '/gsoc/project/' + suffix response = self.get(url) self.assertProjectDetailsTemplateUsed(response)
def getStudentEvalRecordProperties(self, show=False): eval = self.evaluation.createStudentEvaluation() mentor_profile = GSoCProfileHelper(self.gsoc, self.dev_test) mentor_profile.createOtherUser('*****@*****.**') mentor = mentor_profile.createMentor(self.org) student_profile = GSoCProfileHelper(self.gsoc, self.dev_test) student_profile.createOtherUser('*****@*****.**') student_profile.createStudentWithProject(self.org, mentor) project = GSoCProject.all().get() suffix = "%s/%s/%s/%s" % ( self.gsoc.key().name(), eval.link_id, project.parent().link_id, project.key().id()) base_url = '/gsoc/eval/student' if show: url = '%s/show/%s' % (base_url, suffix) else: url = '%s/%s' % (base_url, suffix) return (url, eval, mentor)
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
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)
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)
def createMentor(self): """Creates a new mentor. """ profile_helper = GSoCProfileHelper(self.gsoc, self.dev_test) profile_helper.createOtherUser('*****@*****.**') self.mentor = profile_helper.createMentor(self.org)