示例#1
0
 def testGetIssueAndComment_NoSuchComment(self):
     _request, mr = testing_helpers.GetRequestObjects(
         path='/p/proj/issues/original?id=1&seq=99', project=self.proj)
     with self.assertRaises(webapp2.HTTPException) as cm:
         self.servlet._GetIssueAndComment(mr)
     self.assertEquals(404, cm.exception.code)
示例#2
0
    def testProcessFormData_NonMembersCantEdit(self):
        """Non-members can comment, but never affect issue fields."""
        orig_prepsend = notify.PrepareAndSendIssueChangeNotification
        notify.PrepareAndSendIssueChangeNotification = lambda *args, **kwargs: None

        local_id_1 = self.services.issue.CreateIssue(self.cnxn, self.services,
                                                     self.project.project_id,
                                                     'summary_1', 'status',
                                                     111L, [], [], [], [],
                                                     111L, 'description_1')
        local_id_2 = self.services.issue.CreateIssue(self.cnxn, self.services,
                                                     self.project.project_id,
                                                     'summary_2', 'status',
                                                     111L, [], [], [], [],
                                                     111L, 'description_2')

        _amendments, _cmnt_pb = self.services.issue.ApplyIssueComment(
            self.cnxn,
            self.services,
            111L,
            self.project.project_id,
            local_id_2,
            'summary',
            'Duplicate',
            111L, [], [], [], [], [], [], [], [],
            local_id_1,
            comment='closing as a dup of 1')

        non_member_user_id = 999L
        post_data = fake.PostData({
            'merge_into': [''],  # non-member tries to remove merged_into
            'comment': ['thanks!'],
            'can': ['1'],
            'q': ['foo'],
            'colspec': ['bar'],
            'sort': 'baz',
            'groupby': 'qux',
            'start': ['0'],
            'num': ['100'],
            'pagegen': [str(int(time.time()) + 1)],
        })

        _, mr = testing_helpers.GetRequestObjects(
            user_info={'user_id': non_member_user_id},
            path='/p/proj/issues/detail.do?id=%d' % local_id_2,
            project=self.project,
            method='POST',
            perms=permissions.USER_PERMISSIONSET)
        mr.project_name = self.project.project_name
        mr.project = self.project

        self.mox.StubOutWithMock(self.servlet, 'CheckCaptcha')
        self.servlet.CheckCaptcha(mr, mox.IgnoreArg())
        self.mox.ReplayAll()

        # The form should be processed and redirect back to viewing the issue.
        redirect_url = self.servlet.ProcessFormData(mr, post_data)
        self.mox.VerifyAll()
        self.assertTrue(
            redirect_url.startswith(
                'http://127.0.0.1/p/proj/issues/detail?id=%d' % local_id_2))

        # BUT, issue should not have been edited because user lacked permission.
        updated_issue_2 = self.services.issue.GetIssueByLocalID(
            self.cnxn, self.project.project_id, local_id_2)
        self.assertEqual(local_id_1, updated_issue_2.merged_into)

        notify.PrepareAndSendIssueChangeNotification = orig_prepsend
示例#3
0
 def testGetIssueAndComment_Normal(self):
     _request, mr = testing_helpers.GetRequestObjects(
         path='/p/proj/issues/original?id=1&seq=1', project=self.proj)
     issue, comment = self.servlet._GetIssueAndComment(mr)
     self.assertEqual(self.issue_1, issue)
     self.assertEqual(self.comments[1].content, comment.content)
示例#4
0
 def testGatherPageData_BadUnicode(self):
     _request, mr = testing_helpers.GetRequestObjects(
         path='/p/proj/issues/original?id=1&seq=2', project=self.proj)
     page_data = self.servlet.GatherPageData(mr)
     self.assertEqual(1, page_data['local_id'])
     self.assertEqual(2, page_data['seq'])
示例#5
0
 def testGatherHelpData_Normal(self):
     project = fake.Project(project_name='proj')
     _request, mr = testing_helpers.GetRequestObjects(path='/p/proj',
                                                      project=project)
     help_data = self.page_class.GatherHelpData(mr, {})
     self.assertEqual(None, help_data['cue'])
 def testCheckStart_pass(self):
   request, _ = testing_helpers.GetRequestObjects(
     project=self.project)
   request.headers['X-AppEngine-Country'] = 'US'
   request.remote_addr = '192.168.1.0'
   self.ratelimiter.CheckStart(request)
示例#7
0
 def testFormatAbsoluteURL(self):
     _request, mr = testing_helpers.GetRequestObjects(
         path='/p/proj/some-path', headers={'Host': 'www.test.com'})
     self.assertEqual('http://www.test.com/p/proj/some/path',
                      framework_helpers.FormatAbsoluteURL(mr, '/some/path'))