def testAccessToTheList(self): """Tests only the host can access the list.""" user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) profile_utils.seedNDBStudent(self.program, user=user) response = self.get(self.url) self.assertResponseForbidden(response) 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())]) response = self.get(self.url) self.assertResponseForbidden(response) # check for an organization administrator user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) profile_utils.seedNDBProfile( self.program.key(), user=user, admin_for=[ndb.Key.from_old_key(self.org.key())]) response = self.get(self.url) self.assertResponseForbidden(response) user = profile_utils.seedNDBUser(host_for=[self.program]) profile_utils.loginNDB(user) response = self.get(self.url) self.assertResponseOK(response)
def testForNonLoggedInAccount(self): """Tests that None is returned for a not logged-in user.""" # seed a user but make sure that nobody is logged in profile_utils.seedNDBUser() profile_utils.logout() result = user_logic.getByCurrentAccount() self.assertIsNone(result)
def testCreateOrganizationChoices(self): """Tests that testCreateOrganizationChoices() returns the appropriate organization choices (if any) for a user.""" # Test that for an average user, all organizations are available user = profile_utils.seedNDBUser() profile_utils.loginNDB(user) self.profile = profile_utils.seedNDBProfile(self.program.key(), user=user) expected = set([ self.org_a.key(), self.org_b.key(), self.org_c.key(), self.org_d.key() ]) data = _getRequestData(self.profile) actual = set( map(lambda org: org.key(), gciconversation_create_view.createOrganizationChoices(data))) self.assertEqual(expected, actual) # Test that all organizations are available for a host of the program user = profile_utils.seedNDBUser(host_for=[self.program]) profile_utils.loginNDB(user) self.profile = profile_utils.seedNDBProfile(self.program.key(), user=user) expected = set([ self.org_a.key(), self.org_b.key(), self.org_c.key(), self.org_d.key() ]) data = _getRequestData(self.profile) actual = set( map(lambda org: org.key(), gciconversation_create_view.createOrganizationChoices(data))) self.assertEqual(expected, actual) # Test that all organizations are available for a developer user = profile_utils.seedNDBUser() profile_utils.loginNDB(user, is_admin=True) self.profile = profile_utils.seedNDBProfile(self.program.key(), user=user) expected = set([ self.org_a.key(), self.org_b.key(), self.org_c.key(), self.org_d.key() ]) data = _getRequestData(self.profile) actual = set( map(lambda org: org.key(), gciconversation_create_view.createOrganizationChoices(data))) self.assertEqual(expected, actual)
def testUserExists(self): """Tests that user entity is not existed for a taken username.""" # seed a user with a specific username profile_utils.seedNDBUser(user_id=TEST_USERNAME) # sign in a user with an account but with no user entity profile_utils.signInToGoogleAccount(TEST_EMAIL, TEST_ACCOUNT_ID) result = ndb.transaction(lambda: user_logic.createUser(TEST_USERNAME)) self.assertFalse(result)
def setUp(self): """Set up required for the cleaning logic tests. """ self.init() # Ensure that current user is created self.user = profile_utils.seedNDBUser() profile_utils.loginNDB(self.user) # Create another user self.another_user = profile_utils.seedNDBUser() # Create a dummy form object self.form = Form()
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 setUp(self): self.user = profile_utils.seedNDBUser() self.program = program_utils.seedProgram() self.gsoc_program = program_utils.seedGSoCProgram() self.gci_program = program_utils.seedGCIProgram() self.site = seeder_logic.seed(Site, {'key_name': 'site'}) self.organization = seeder_logic.seed(Organization) self.gsoc_organization = org_utils.seedSOCOrganization( self.gsoc_program.key()) self.gci_organization = seeder_logic.seed(GCIOrganization) self.program_key_name = self.program.key().name() self.gsoc_program_key_name = self.gsoc_program.key().name() self.gci_program_key_name = self.gci_program.key().name() self.site_key_name = self.site.key().name() self.org_key_name = self.organization.key().name() self.gsoc_org_key_name = self.gsoc_organization.key.id() self.gci_org_key_name = self.gci_organization.key().name()
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 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 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 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 createOrgApp(self, override=None): """Creates an organization application for the defined properties.""" if self.org_app: return self.org_app if self.program is None: self.createProgram() user = profile_utils.seedNDBUser() properties = { 'scope': self.program, 'program': self.program, 'modified_by': user.key.to_old_key(), 'created_by': user.key.to_old_key(), 'author': user.key.to_old_key(), 'schema': ('[["item"],{"item":{"field_type":"input_text",' '"required":false, "label":"test"}}]'), 'survey_content': None, 'key_name': '%s/%s/orgapp' % (self.program.prefix, self.program.key().name()), } properties.update(override or {}) self.org_app = self.seed(OrgAppSurvey, properties) return self.org_app
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 createDocumentForPrefix(self, prefix, user=None, override=None): """Creates a document for the specified properties. Args: prefix: Prefix for the document. user: User entity of the author for the document. override: A dict mapping additional properties to their values. Returns: The newly created Document entity. """ override = override or {} if not user: user = profile_utils.seedNDBUser() properties = { "modified_by": user.key.to_old_key(), "author": user.key.to_old_key(), "home_for": None, "prefix": prefix, "scope": self.program, "read_access": "public", "key_name": string_provider.DocumentKeyNameProvider(), } properties.update(override) return self.seed(document_model.Document, properties)
def seedApplicationSurvey(program_key, **kwargs): """Seeds a new organization application survey for the specified program. Args: program_key: Program key to create a survey for. kwargs: Optional values for other properties of the seeded entity. Returns: Newly seeded survey entity. """ user = profile_utils.seedNDBUser() program = db.get(program_key) properties = { 'scope': program_key, 'program': program_key, 'modified_by': user.key.to_old_key(), 'created_by': user.key.to_old_key(), 'author': user.key.to_old_key(), 'schema': ('[["item"],{"item":{"field_type":"input_text",' '"required":false, "label":"test"}}]'), 'survey_content': None, 'key_name': '%s/%s/orgapp' % (program.prefix, program_key.name()) } properties.update(kwargs) return seeder_logic.seed(OrgAppSurvey, properties)
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 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 setUp(self): """See unittest.TestCase.setUp for specification.""" # seed a program self.program = program_utils.seedProgram() # seed a user self.user = profile_utils.seedNDBUser()
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 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 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)