def testUserExists(self): """Tests that user entity is returned when it exists.""" user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) data = request_data.RequestData(None, None, None) self.assertEqual(data.ndb_user.key, user.key)
def testOrgAppCreateOrEditByMentor(self): """Tests that a mentor cannot create an organization application. """ # Make sure we do not have an org app for this test. self.org_app.delete() user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) profile_utils.seedNDBProfile( self.program.key(), user=user, mentor_for=[self.org.key]) url = '/gsoc/org/application/edit/' + self.gsoc.key().name() response = self.get(url) self.assertResponseForbidden(response) org_app_key_name = 'gsoc_program/%s/orgapp' % (self.gsoc.key().name(),) org_app = org_app_survey.OrgAppSurvey.get_by_key_name(org_app_key_name) self.assertIsNone(org_app) response = self.post(url, self.getOrgAppCreatePostData()) self.assertResponseForbidden(response) org_app = org_app_survey.OrgAppSurvey.get_by_key_name(org_app_key_name) self.assertIsNone(org_app)
def testCreateDocumentNoDashboardVisibility(self): user = profile_utils.seedNDBUser(host_for=[self.program]) profile_utils.loginNDB(user) url = '/gsoc/document/edit/gsoc_program/%s/doc' % self.gsoc.key().name( ) response = self.get(url) self.assertResponseOK(response) self.assertGSoCTemplatesUsed(response) self.assertTemplateUsed(response, 'modules/gsoc/document/base.html') self.assertTemplateUsed(response, 'modules/gsoc/_form.html') # test POST override = { 'prefix': 'gsoc_program', 'scope': self.gsoc, 'link_id': 'doc', 'key_name': DocumentKeyNameProvider(), 'modified_by': user.key.to_old_key(), 'home_for': None, 'author': user.key.to_old_key(), 'is_featured': None, 'write_access': 'admin', 'read_access': 'public', 'dashboard_visibility': [], } properties = seeder_logic.seed_properties(Document, properties=override) response = self.post(url, properties) self.assertResponseRedirect(response, url) key_name = properties['key_name'] document = Document.get_by_key_name(key_name) self.assertEqual(document.key().name(), key_name)
def testCreateProfile(self): self.timeline_helper.studentSignup() user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) self._updateDefaultProps(user) postdata = self.default_props response = self.post(self.student_url, postdata) self.assertResponseRedirect(response, self.validated_url) # hacky profile = profile_model.GCIProfile.all().get() profile.delete() postdata.update({ 'email': 'somerandominvalid@emailid', }) response = self.post(self.student_url, postdata) # yes! this is the protocol for form posts. We get an OK response # with the response containing the form's GET request page whenever # the form has an error and could not be posted. This is the architecture # chosen in order to save the form error state's while rendering the # error fields. self.assertResponseOK(response) error_dict = response.context['error'] self.assertIn('email', error_dict)
def testSanitization(self): user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) xss_payload = '><img src=http://www.google.com/images/srpr/logo4w.png>' role_url = '/%(program_type)s/profile/%(role)s/%(suffix)s' % { 'program_type': self.programType(), 'role': 'mentor', 'suffix': self.program.key().name(), } postdata = { 'link_id': xss_payload, 'user': user.key.to_old_key(), 'parent': user.key.to_old_key(), 'scope': self.program, 'status': 'active', 'email': xss_payload, 'mentor_for': [], 'org_admin_for': [], 'is_org_admin': False, 'is_mentor': False, 'birth_date': xss_payload, } response = self.post(role_url, postdata) self.assertNotIn(xss_payload, response.content) self.assertIn(html.escape(xss_payload), response.content)
def testWithdrawProjects(self): user = profile_utils.seedNDBUser(host_for=[self.program]) profile_utils.loginNDB(user) self.timeline_helper.studentsAnnounced() url = '/gsoc/withdraw_projects/' + self.program.key().name() response = self.get(url) self.assertResponseOK(response) 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 student = profile_utils.seedNDBStudent(self.program) project_utils.seedProject(student, self.program.key(), org_key=self.org.key) response = self.getListResponse(url, 0) self.assertIsJsonResponse(response) data = response.context['data'][''] self.assertEqual(1, len(data))
def testAssignMentor(self): student = profile_utils.seedSOCStudent(self.program) proposal = proposal_utils.seedProposal(student.key, self.program.key(), org_key=self.org.key, mentor=None) suffix = "%s/%s/%d" % (self.gsoc.key().name(), student.profile_id, proposal.key().id()) user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) mentor = profile_utils.seedNDBProfile(self.program.key(), user=user, mentor_for=[self.org.key]) url = '/gsoc/proposal/assign_mentor/' + suffix postdata = {'assign_mentor': mentor.key} response = self.post(url, postdata) self.assertResponseForbidden(response) proposal = GSoCProposal.all().get() mentor_key = GSoCProposal.mentor.get_value_for_datastore(proposal) self.assertIsNone(mentor_key)
def testProgramHostAccessGranted(self): """Asserts program administrators can access the page.""" user = profile_utils.seedNDBUser(host_for=[self.program]) profile_utils.loginNDB(user) response = self.get(self.url) self.assertResponseOK(response)
def testPersonalExtensionIsSet(self): """Tests that personal extension is set for an evaluation.""" self._seedProjectData() user = profile_utils.seedNDBUser(host_for=[self.program]) profile_utils.loginNDB(user) # seed midterm evaluation properties = {'link_id': project_survey_model.MIDTERM_EVAL} survey = survey_utils.SurveyHelper( self.gsoc, False).createStudentEvaluation(override=properties) # set personal extension start_date = date.today() end_date = date.today() post_data = { project_manage_view.MIDTERM_EXTENSION_FORM_NAME: 'test button', 'start_date': unicode(start_date), 'end_date': unicode(end_date) } response = self.post(self._getUrl(self.project), post_data) self.assertResponseRedirect(response) # check if personal extension is set properly extension = survey_logic.getPersonalExtension(self.student.key, survey.key()) self.assertIsNotNone(extension) self.assertEqual(start_date, extension.start_date.date()) self.assertEqual(end_date, extension.end_date.date())
def testStudentCannotAccess(self): user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) profile_utils.seedNDBStudent(self.program, user=user) response = self.get(self.url) self.assertErrorTemplatesUsed(response)
def testPageLoads(self): """Tests that page loads properly.""" user = profile_utils.seedNDBUser(host_for=[self.program]) profile_utils.loginNDB(user) response = self.get(_getOrgApplicationListPageListUrl(self.program)) self.assertResponseOK(response)
def testPostMethodNotAllowed(self): """Tests that POST method is not permitted.""" user = profile_utils.seedNDBUser(host_for=[self.program]) profile_utils.loginNDB(user) response = self.post(_getOrgAppShowUrl(self.org)) self.assertResponseMethodNotAllowed(response)
def testSendNewMessage(self): """Tests that sending a new connection message works.""" user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) profile = profile_utils.seedNDBProfile(self.program.key(), user=user, admin_for=[self.org.key]) last_modified = self.connection.last_modified post_data = { connection_view.MESSAGE_FORM_NAME: '', 'content': _TEST_MESSAGE_CONTENT, } response = self.post(_getManageAsOrgUrl(self.connection), post_data) self.assertResponseRedirect(response, _getManageAsOrgUrl(self.connection)) # check that a new message is created query = connection_model.ConnectionMessage.query( ancestor=self.connection.key) message = query.get() self.assertIsNotNone(message) self.assertEqual(message.content, _TEST_MESSAGE_CONTENT) self.assertFalse(message.is_auto_generated) self.assertEqual(message.author, profile.key) # check that last_modified property is updated self.assertGreater(self.connection.key.get().last_modified, last_modified)
def testSubmitProposalWhenInactive(self): """Test the submission of student proposals during the student signup period is not active. """ user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) profile_utils.seedNDBStudent(self.program, user=user) self.timeline_helper.orgSignup() url = '/gsoc/proposal/submit/' + self.org.key.id() response = self.get(url) self.assertResponseForbidden(response) self.timeline_helper.offSeason() url = '/gsoc/proposal/submit/' + self.org.key.id() response = self.get(url) self.assertResponseForbidden(response) self.timeline_helper.kickoff() url = '/gsoc/proposal/submit/' + self.org.key.id() response = self.get(url) self.assertResponseForbidden(response) self.timeline_helper.orgsAnnounced() url = '/gsoc/proposal/submit/' + self.org.key.id() response = self.get(url) self.assertResponseForbidden(response) self.timeline_helper.studentsAnnounced() url = '/gsoc/proposal/submit/' + self.org.key.id() response = self.get(url) self.assertResponseForbidden(response)
def testCreateDocumentNoDashboardVisibility(self): user = profile_utils.seedNDBUser(host_for=[self.program]) profile_utils.loginNDB(user) url = '/gsoc/document/edit/gsoc_program/%s/doc' % self.gsoc.key().name() response = self.get(url) self.assertResponseOK(response) self.assertGSoCTemplatesUsed(response) self.assertTemplateUsed(response, 'modules/gsoc/document/base.html') self.assertTemplateUsed(response, 'modules/gsoc/_form.html') # test POST override = { 'prefix': 'gsoc_program', 'scope': self.gsoc, 'link_id': 'doc', 'key_name': DocumentKeyNameProvider(), 'modified_by': user.key.to_old_key(), 'home_for': None, 'author': user.key.to_old_key(), 'is_featured': None, 'write_access': 'admin', 'read_access': 'public', 'dashboard_visibility': [], } properties = seeder_logic.seed_properties(Document, properties=override) response = self.post(url, properties) self.assertResponseRedirect(response, url) key_name = properties['key_name'] document = Document.get_by_key_name(key_name) self.assertEqual(document.key().name(), key_name)
def testAcceptTwoProposals(self): """Tests that two proposals can be accepted in the same request.""" user = profile_utils.seedNDBUser(host_for=[self.program]) profile_utils.loginNDB(user) mentor = profile_utils.seedNDBProfile( self.program.key(), mentor_for=[self.org.key]) student_one = profile_utils.seedNDBStudent(self.program) proposal_one = proposal_utils.seedProposal( student_one.key, self.program.key(), org_key=self.org.key, mentor_key=mentor.key) student_two = profile_utils.seedNDBStudent(self.program) proposal_two = proposal_utils.seedProposal( student_two.key, self.program.key(), org_key=self.org.key, mentor_key=mentor.key) list_data = [ {accept_withdraw_projects._PROPOSAL_KEY: str(proposal_one.key())}, {accept_withdraw_projects._PROPOSAL_KEY: str(proposal_two.key())} ] post_data = { 'button_id': 'accept', 'data': json.dumps(list_data), 'idx': 0, } self.post(self.url, post_data) # check if both proposals are accepted correctly proposal1 = proposal_model.GSoCProposal.get(proposal_one.key()) self.assertEqual(proposal1.status, proposal_model.STATUS_ACCEPTED) proposal2 = proposal_model.GSoCProposal.get(proposal_two.key()) self.assertEqual(proposal2.status, proposal_model.STATUS_ACCEPTED)
def testDashboardAsStudentWithEval(self): user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) profile = profile_utils.seedNDBStudent(self.program, user=user) project_utils.seedProject(profile, self.program.key()) url = '/gsoc/dashboard/' + self.gsoc.key().name() response = self.get(url) self.assertResponseOK(response) self.assertDashboardComponentTemplatesUsed(response) response = self.getListResponse(url, 3) self.assertResponseForbidden(response) response = self.get(url) self.assertResponseOK(response) self.assertDashboardComponentTemplatesUsed(response) self.evaluation = SurveyHelper(self.gsoc, self.dev_test) self.evaluation.createStudentEvaluation( override={'link_id': 'midterm'}) response = self.getListResponse(url, 3) self.assertIsJsonResponse(response) data = json.loads(response.content) self.assertEqual(len(data['data']['']), 1) self.evaluation.createStudentEvaluation(override={'link_id': 'final'}) response = self.getListResponse(url, 3) self.assertIsJsonResponse(response) data = json.loads(response.content) self.assertEqual(len(data['data']['']), 2)
def testAcceptProposal(self): """Tests that a proposal is correctly accepted.""" user = profile_utils.seedNDBUser(host_for=[self.program]) profile_utils.loginNDB(user) mentor = profile_utils.seedNDBProfile( self.program.key(), mentor_for=[self.org.key]) student = profile_utils.seedNDBStudent(self.program) proposal = proposal_utils.seedProposal( student.key, self.program.key(), org_key=self.org.key, mentor_key=mentor.key) list_data = [{accept_withdraw_projects._PROPOSAL_KEY: str(proposal.key())}] post_data = { 'button_id': 'accept', 'data': json.dumps(list_data), 'idx': 0, } self.post(self.url, post_data) # check if proposal is accepted correctly proposal = proposal_model.GSoCProposal.get(proposal.key()) self.assertEqual(proposal.status, proposal_model.STATUS_ACCEPTED) # check if a project is created project = project_model.GSoCProject.all().ancestor( student.key.to_old_key()).get() self.assertEqual(project.status, project_model.STATUS_ACCEPTED) self.assertEqual(project.proposal.key(), proposal.key()) # check if number of projects is updated student = student.key.get() self.assertEqual(student.student_data.number_of_projects, 1)
def testCleanHtmlContent(self): """Tests that html content can be cleaned. """ field_name = 'test_html' clean_field = cleaning.clean_html_content(field_name) # Test that normal html can be cleaned expected = html = '<div>f9-+@4</div>' self.form.cleaned_data = {field_name: html} self.assertEqual(clean_field(self.form), expected) # Test that normal html can be cleaned html = '<html>f9-+@4</html>' self.form.cleaned_data = {field_name: html} expected = html.replace('<', '<').replace('>', '>') actual = clean_field(self.form) self.assertEqual(actual, expected) expected = html = u'\ua000' self.form.cleaned_data = {field_name: html} self.assertEqual(clean_field(self.form), expected) # Test that input with scripts will be encoded as well html = '<script></script>' self.form.cleaned_data = {field_name: html} actual = clean_field(self.form) expected = html.replace('<', '<').replace('>', '>') self.assertEqual(actual, expected) # Test that input can contain scripts when the current user is a developer profile_utils.loginNDB(self.user, is_admin=True) expected = html = '<script></script>' self.form.cleaned_data = {field_name: html} self.assertEqual(clean_field(self.form), expected)
def testDashboardAsStudentWithEval(self): user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) profile = profile_utils.seedNDBStudent(self.program, user=user) project_utils.seedProject(profile, self.program.key()) url = '/gsoc/dashboard/' + self.gsoc.key().name() response = self.get(url) self.assertResponseOK(response) self.assertDashboardComponentTemplatesUsed(response) response = self.getListResponse(url, 3) self.assertResponseForbidden(response) response = self.get(url) self.assertResponseOK(response) self.assertDashboardComponentTemplatesUsed(response) self.evaluation = SurveyHelper(self.gsoc, self.dev_test) self.evaluation.createStudentEvaluation(override={'link_id': 'midterm'}) response = self.getListResponse(url, 3) self.assertIsJsonResponse(response) data = json.loads(response.content) self.assertEqual(len(data['data']['']), 1) self.evaluation.createStudentEvaluation(override={'link_id': 'final'}) response = self.getListResponse(url, 3) self.assertIsJsonResponse(response) data = json.loads(response.content) self.assertEqual(len(data['data']['']), 2)
def testAssignMentor(self): student = profile_utils.seedSOCStudent(self.program) proposal = proposal_utils.seedProposal( student.key, self.program.key(), org_key=self.org.key, mentor=None) suffix = "%s/%s/%d" % ( self.gsoc.key().name(), student.profile_id, proposal.key().id()) user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) mentor = profile_utils.seedNDBProfile( self.program.key(), user=user, mentor_for=[self.org.key]) url = '/gsoc/proposal/assign_mentor/' + suffix postdata = {'assign_mentor': mentor.key} response = self.post(url, postdata) self.assertResponseForbidden(response) proposal = GSoCProposal.all().get() mentor_key = GSoCProposal.mentor.get_value_for_datastore(proposal) self.assertIsNone(mentor_key)
def testDashboardAsStudent(self): user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) profile_utils.seedNDBStudent(self.program, user=user) response = self.get(self._getDashboardUrl()) self.assertResponseOK(response)
def testStudentAccessForbidden(self): user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) profile_utils.seedNDBStudent(self.program, user=user) response = self.get(self._getUrl()) self.assertErrorTemplatesUsed(response)
def testPostPublish(self): user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) profile = profile_utils.seedNDBProfile( self.program.key(), user=user, admin_for=[ndb.Key.from_old_key(self.org.key())]) # check if Unpublished task may be published self._testPostPublish(profile, 'Unpublished', 'Open', 'publish') # check if Unapproved task may be published self._testPostPublish(profile, task_model.UNAPPROVED, 'Open', 'publish') # check if Open task may be unpublished self._testPostPublish(profile, 'Open', 'Unpublished', 'unpublish') # check if Reopened task may not be changed self._testPostPublish( profile, task_model.REOPENED, task_model.REOPENED, 'publish') self._testPostPublish( profile, task_model.REOPENED, task_model.REOPENED, 'unpublish') # check if Claimed task may not be changed self._testPostPublish(profile, 'Claimed', 'Claimed', 'publish') self._testPostPublish(profile, 'Claimed', 'Claimed', 'unpublish') # check if ActionNeeded task may not be changed self._testPostPublish(profile, 'ActionNeeded', 'ActionNeeded', 'publish') self._testPostPublish(profile, 'ActionNeeded', 'ActionNeeded', 'unpublish') # check if Closed task may not be changed self._testPostPublish(profile, 'Closed', 'Closed', 'publish') self._testPostPublish(profile, 'Closed', 'Closed', 'unpublish')
def testOrgAppCreateOrEditByProgramAdmin(self): """Tests that program admin can create an organization application. """ # Make sure we do not have an org app for this test. self.org_app.delete() user = profile_utils.seedNDBUser(host_for=[self.program]) profile_utils.loginNDB(user) url = '/gsoc/org/application/edit/' + self.gsoc.key().name() response = self.get(url) self.assertResponseOK(response) self.assertOrgAppCreateOrEditTemplatesUsed(response) org_app_key_name = 'gsoc_program/%s/orgapp' % (self.gsoc.key().name(),) org_app = org_app_survey.OrgAppSurvey.get_by_key_name(org_app_key_name) self.assertIsNone(org_app) response = self.post(url, self.getOrgAppCreatePostData()) print response.content self.assertResponseRedirect(response, url + '?validated') org_app = org_app_survey.OrgAppSurvey.get_by_key_name(org_app_key_name) self.assertNotEqual(org_app, None)
def testSubmitAnotherForm(self): """Tests that another form may be resubmitted by a student.""" self.timeline_helper.formSubmission() user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) student = profile_utils.seedSOCStudent(self.program, user=user) project_utils.seedProject( student, self.program.key(), org_key=self.org.key) # set initial tax form blob_key = self.createBlob('initial_tax_form.pdf') student.student_data.tax_form = blob_key student.put() # submit a new tax form with tempfile.NamedTemporaryFile() as test_file: # check for the enrollment form url = self._getTaxFormUrl() postdata = {'tax_form': test_file} response = self.post(url, postdata) self.assertResponseRedirect( response, self._getTaxFormUrl(validated=True)) # check if the form has been submitted student = student.key.get() self.assertIsNotNone(student.student_data.tax_form) self.assertEqual(os.path.basename(test_file.name), student.student_data.tax_form)
def testListProposals(self): user = profile_utils.seedNDBUser(host_for=[self.program]) profile_utils.loginNDB(user) self.timeline_helper.studentSignup() url = '/gsoc/admin/proposals/' + self.org.key.id() response = self.get(url) self.assertResponseOK(response) self.assertProposalsPage(response) response = self.getListResponse(url, 0) self.assertIsJsonResponse(response) data = response.context['data'][''] self.assertEqual(0, len(data)) # test list with student's proposal student = profile_utils.seedSOCStudent(self.program) proposal_utils.seedProposal( student.key, self.program.key(), org_key=self.org.key) response = self.getListResponse(url, 0) self.assertIsJsonResponse(response) data = response.context['data'][''] self.assertEqual(1, len(data))
def testPostButtonAssign(self): """Tests the assign button.""" user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) profile_utils.seedNDBProfile( self.program.key(), user=user, mentor_for=[ndb.Key.from_old_key(self.org.key())]) student = profile_utils.seedNDBStudent(self.program) self.task.status = 'ClaimRequested' self.task.student = student.key.to_old_key() self.task.put() url = _taskPageURL(self.task) response = self.buttonPost(url, 'button_assign') # check if the task is properly assigned and a deadline has been set task = task_model.GCITask.get(self.task.key()) self.assertResponseRedirect(response) self.assertEqual(task.status, 'Claimed') self.assertEqual( task_model.GCITask.student.get_value_for_datastore(task), student.key.to_old_key()) self.assertTrue(task.deadline) # check if a comment has been created comments = self.task.comments() self.assertEqual(len(comments), 1) self.assertMailSentToSubscribers(comments[0]) # check if the update task has been enqueued self.assertTasksInQueue(n=1, url=_taskUpdateURL(task)) self.assertBasicTaskView()
def testResubmitProposal(self): self.timeline_helper.studentSignup() mentor = profile_utils.seedNDBProfile( self.program.key(), mentor_for=[self.org.key]) # TODO(daniel): take care of notifications: notify_proposal_updates=True user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) student = profile_utils.seedSOCStudent(self.program, user) proposal = proposal_utils.seedProposal( student.key, self.program.key(), org_key=self.org.key, mentor_key=mentor.key, status=proposal_model.STATUS_WITHDRAWN) # TODO(daniel): take care of notifications # self.profile_helper.notificationSettings() url = '/gsoc/proposal/update/%s/%s/%s' % ( self.gsoc.key().name(), student.profile_id, proposal.key().id()) # resubmit proposal postdata = {'action': 'Resubmit'} self.post(url, postdata) # check if the proposal is resubmitted proposal = proposal_model.GSoCProposal.get(proposal.key()) self.assertEqual(proposal_model.STATUS_PENDING, proposal.status) student = student.key.get() # check if number of proposals is increased self.assertEqual(student.student_data.number_of_proposals, 1)
def testPostButtonNeedsWork(self): """Tests the needs more work for task button.""" user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) profile_utils.seedNDBProfile( self.program.key(), user=user, mentor_for=[ndb.Key.from_old_key(self.org.key())]) student = profile_utils.seedNDBStudent(self.program) self.task.status = 'NeedsReview' self.task.student = student.key.to_old_key() self.task.put() url = _taskPageURL(self.task) response = self.buttonPost(url, 'button_needs_work') # check if the task is properly closed task = task_model.GCITask.get(self.task.key()) self.assertResponseRedirect(response) self.assertEqual(task.status, 'NeedsWork') self.assertEqual( task_model.GCITask.student.get_value_for_datastore(task), student.key.to_old_key()) self.assertIsNone(task.deadline) # check if a comment has been created comments = self.task.comments() self.assertEqual(len(comments), 1) self.assertMailSentToSubscribers(comments[0]) self.assertBasicTaskView()
def testLoneUserAccessDenied(self): """Tests that users without profiles cannot access the page.""" user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) response = self.get(self.take_url) self.assertResponseForbidden(response)
def testPostButtonExtendDeadline(self): """Tests the extend deadline button.""" user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) profile_utils.seedNDBProfile( self.program.key(), user=user, mentor_for=[ndb.Key.from_old_key(self.org.key())]) student = profile_utils.seedNDBStudent(self.program) # set it in the future so that the auto state transfer doesn't trigger deadline = datetime.datetime.utcnow() + datetime.timedelta(hours=24) self.task.status = 'Claimed' self.task.student = student.key.to_old_key() self.task.deadline = deadline self.task.put() url = _taskPageURL(self.task) response = self.buttonPost( url, 'button_extend_deadline', {'hours': 1}) task = task_model.GCITask.get(self.task.key()) self.assertResponseRedirect(response) delta = task.deadline - deadline self.assertTrue(delta.seconds == 3600) # check if a comment has been created comments = self.task.comments() self.assertEqual(len(comments), 1) self.assertMailSentToSubscribers(comments[0]) self.assertBasicTaskView()
def testLoneUserAccessDenied(self): """Asserts lone users cannot access the page.""" user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) response = self.get(self.url) self.assertResponseForbidden(response)
def testPostButtonClaim(self): """Tests the claim task button.""" form = forms_to_submit_utils.FormsToSubmitHelper().createBlobStoreForm() user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) student = profile_utils.seedNDBStudent( self.program, user=user, student_data_properties={'enrollment_form': form, 'consent_form':form}) url = _taskPageURL(self.task) response = self.buttonPost(url, 'button_claim') # check if the task is properly claimed task = task_model.GCITask.get(self.task.key()) self.assertResponseRedirect(response) self.assertEqual(task.status, 'ClaimRequested') self.assertEqual( task_model.GCITask.student.get_value_for_datastore(task), student.key.to_old_key()) # check if a comment has been created comments = self.task.comments() self.assertEqual(len(comments), 1) self.assertMailSentToSubscribers(comments[0]) self.assertBasicTaskView()
def testListProposals(self): user = profile_utils.seedNDBUser(host_for=[self.program]) profile_utils.loginNDB(user) self.timeline_helper.studentSignup() url = '/gsoc/admin/proposals/' + self.org.key.id() response = self.get(url) self.assertResponseOK(response) self.assertProposalsPage(response) response = self.getListResponse(url, 0) self.assertIsJsonResponse(response) data = response.context['data'][''] self.assertEqual(0, len(data)) # test list with student's proposal student = profile_utils.seedSOCStudent(self.program) proposal_utils.seedProposal(student.key, self.program.key(), org_key=self.org.key) response = self.getListResponse(url, 0) self.assertIsJsonResponse(response) data = response.context['data'][''] self.assertEqual(1, len(data))
def testPostButtonUnclaim(self): """Tests the unclaim task button.""" user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) student = profile_utils.seedNDBStudent(self.program, user=user) self.task.status = 'ClaimRequested' self.task.student = student.key.to_old_key() self.task.put() url = _taskPageURL(self.task) response = self.buttonPost(url, 'button_unclaim') # check if the task is properly opened task = task_model.GCITask.get(self.task.key()) self.assertResponseRedirect(response) self.assertEqual(task.status, task_model.REOPENED) self.assertIsNone(task.student) self.assertIsNone(task.deadline) # check if a comment has been created comments = self.task.comments() self.assertEqual(len(comments), 1) self.assertMailSentToSubscribers(comments[0]) self.assertBasicTaskView()
def testPageLoads(self): """Tests that page loads properly.""" user = profile_utils.seedNDBUser() profile_utils.loginNDB(user, is_admin=True) response = self.get('/site/edit') self.assertResponseOK(response)
def testPostSubmitWork(self): """Tests for submitting work.""" user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) student = profile_utils.seedNDBStudent(self.program, user=user) self.task.status = 'Claimed' self.task.student = student.key.to_old_key() # set deadline to far future self.task.deadline = datetime.datetime.utcnow() + datetime.timedelta(days=1) self.task.put() no_work = self.task.workSubmissions() self.assertEqual(len(no_work), 0) work_url = 'http://www.example.com/' work_data = { 'url_to_work': work_url } url = '%s?submit_work' % _taskPageURL(self.task) response = self.post(url, work_data) self.assertResponseRedirect(response) one_work = self.task.workSubmissions() self.assertEqual(len(one_work), 1) work = one_work[0] self.assertEqual(work_url, work.url_to_work) self.assertBasicTaskView()
def testUserWithNoProfileAccessGranted(self): """Tests that access is granted for a user with no profile.""" user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) access_checker = access.HasNoProfileAccessChecker() access_checker.checkAccess(self.data, None)
def testNonDeveloperAccessDenied(self): """Tests that access is denied for users who are not developers.""" user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) response = self.get(_getUserSettingsUrl(user)) self.assertResponseForbidden(response)
def testEditProgramAsDeveloper(self): user = profile_utils.seedNDBUser() profile_utils.loginNDB(user, is_admin=True) url = '/gci/program/edit/' + self.gci.key().name() response = self.get(url) self.assertProgramTemplatesUsed(response)
def testHostCanAccess(self): user = profile_utils.seedNDBUser(host_for=[self.program]) profile_utils.loginNDB(user) response = self.get(self.url) self.assertPageTemplatesUsed(response) self.assertResponseOK(response)