Beispiel #1
0
  def testUserUpdatesDevelopers(self):
    uud = userupdates.UserUpdatesDevelopers(None, None, self.services)

    self.mox.StubOutWithMock(self.services.user_star, 'LookupStarredItemIDs')
    self.services.user_star.LookupStarredItemIDs(
        self.mr.cnxn, self.mr.viewed_user_auth.user_id).AndReturn(
            [self.user_id])

    self.mox.StubOutWithMock(activities, 'GatherUpdatesData')
    activities.GatherUpdatesData(
        self.services, self.mr, mox.IgnoreArg(),
        user_ids=[self.user_id],
        project_ids=None,
        ending=uud._ENDING,
        updates_page_url=uud._UPDATES_PAGE_URL,
        highlight=uud._HIGHLIGHT).AndReturn({})

    self.mox.ReplayAll()

    page_data = uud.GatherPageData(self.mr)
    self.mox.VerifyAll()
    self.assertEqual(3, len(page_data))
    self.assertEqual('st5', page_data['user_tab_mode'])
    self.assertEqual('yes', page_data['viewing_user_page'])
    self.assertEqual(uud._TAB_MODE, page_data['user_updates_tab_mode'])
Beispiel #2
0
    def GatherPageData(self, mr):
        """Build up a dictionary of data values to use when rendering the page."""
        # TODO(jrobbins): re-implement
        # if self.CheckRevelationCaptcha(mr, mr.errors):
        #   mr.viewed_user_auth.user_view.RevealEmail()

        page_data = {
            'user_tab_mode': 'st5',
            'viewing_user_page': ezt.boolean(True),
            'user_updates_tab_mode': self._TAB_MODE,
        }

        user_ids = self._GetUserIDsForUpdates(mr)
        project_ids = self._GetProjectIDsForUpdates(mr)
        page_data.update(
            activities.GatherUpdatesData(
                self.services,
                mr,
                self.profiler,
                user_ids=user_ids,
                project_ids=project_ids,
                ending=self._ENDING,
                updates_page_url=self._UPDATES_PAGE_URL,
                highlight=self._HIGHLIGHT))

        return page_data
Beispiel #3
0
  def testUserUpdatesProjects(self):
    uup = userupdates.UserUpdatesProjects(None, None, self.services)

    self.mox.StubOutWithMock(sitewide_helpers, 'GetViewableStarredProjects')
    sitewide_helpers.GetViewableStarredProjects(
        self.mr.cnxn, self.services, self.mr.viewed_user_auth.user_id,
        self.mr.auth.effective_ids, self.mr.auth.user_pb).AndReturn(
            [self.project])

    self.mox.StubOutWithMock(activities, 'GatherUpdatesData')
    activities.GatherUpdatesData(
        self.services, self.mr, mox.IgnoreArg(),
        user_ids=None,
        project_ids=[self.project_id],
        ending=uup._ENDING,
        updates_page_url=uup._UPDATES_PAGE_URL,
        highlight=uup._HIGHLIGHT).AndReturn({})

    self.mox.ReplayAll()

    page_data = uup.GatherPageData(self.mr)
    self.mox.VerifyAll()
    self.assertEqual(3, len(page_data))
    self.assertEqual('st5', page_data['user_tab_mode'])
    self.assertEqual('yes', page_data['viewing_user_page'])
    self.assertEqual(uup._TAB_MODE, page_data['user_updates_tab_mode'])
Beispiel #4
0
    def _GatherUpdates(self, mr):
        """Gathers and returns activity streams data."""

        url = '/p/%s%s' % (mr.project_name, urls.UPDATES_LIST)
        return activities.GatherUpdatesData(self.services,
                                            mr,
                                            project_ids=[mr.project_id],
                                            ending='by_user',
                                            updates_page_url=url,
                                            autolink=self.services.autolink)
Beispiel #5
0
    def testActivities_NoUpdates(self):
        mr = testing_helpers.MakeMonorailRequest()
        updates_data = activities.GatherUpdatesData(self.services,
                                                    mr,
                                                    project_ids=[256],
                                                    user_ids=None,
                                                    ending=None,
                                                    updates_page_url=None,
                                                    autolink=None,
                                                    highlight=None)

        self.assertIsNone(updates_data['pagination'])
        self.assertIsNone(updates_data['no_stars'])
        self.assertIsNone(updates_data['updates_data'])
        self.assertEqual('yes', updates_data['no_activities'])
        self.assertIsNone(updates_data['ending_type'])
Beispiel #6
0
    def testGatherPageData(self):
        self.mox.StubOutWithMock(activities, 'GatherUpdatesData')
        activities.GatherUpdatesData(
            self.services,
            self.mr,
            project_ids=[self.project_id],
            ending='by_user',
            updates_page_url='/p/%s/updates/list' % self.project_name,
            autolink=self.services.autolink).AndReturn({'test': 'testing'})
        self.mox.ReplayAll()

        page_data = self.project_updates.GatherPageData(self.mr)
        self.mox.VerifyAll()
        self.assertEquals(
            {
                'subtab_mode': None,
                'user_updates_tab_mode': None,
                'test': 'testing'
            }, page_data)
Beispiel #7
0
    def testUserUpdatesIndividual(self):
        uui = userupdates.UserUpdatesIndividual(None, None, self.services)

        self.mox.StubOutWithMock(activities, 'GatherUpdatesData')
        activities.GatherUpdatesData(
            self.services,
            self.mr,
            user_ids=[self.mr.viewed_user_auth.user_id],
            project_ids=None,
            ending=uui._ENDING,
            updates_page_url=uui._UPDATES_PAGE_URL,
            highlight=uui._HIGHLIGHT).AndReturn({})

        self.mox.ReplayAll()

        page_data = uui.GatherPageData(self.mr)
        self.mox.VerifyAll()
        self.assertEqual(3, len(page_data))
        self.assertEqual('st5', page_data['user_tab_mode'])
        self.assertEqual('yes', page_data['viewing_user_page'])
        self.assertEqual(uui._TAB_MODE, page_data['user_updates_tab_mode'])
    def createAndAssertUpdates(self,
                               project_ids=None,
                               user_ids=None,
                               ascending=True):
        user = user_pb2.MakeUser(self.user_id)
        comment_1 = tracker_pb2.IssueComment(id=self.comment_id,
                                             issue_id=self.issue_id,
                                             project_id=self.project_id,
                                             user_id=self.user_id,
                                             content='this is the 1st comment',
                                             timestamp=self.comment_timestamp)
        self.mox.StubOutWithMock(self.services.issue, 'GetComments')

        created_order = 'created'
        field = 'project_id' if project_ids else 'commenter_id'
        where_clauses = [('Issue.id = Comment.issue_id', [])]
        if project_ids:
            where_clauses.append(('Comment.project_id IN (%s)', project_ids))
        if user_ids:
            where_clauses.append(('Comment.commenter_id IN (%s)', user_ids))
        if ascending:
            where_clauses.append(('created > %s', [self.mr_after]))
        else:
            created_order += ' DESC'
        self.services.issue.GetComments(
            mox.IgnoreArg(),
            deleted_by=None,
            joins=[('Issue', [])],
            limit=activities.UPDATES_PER_PAGE + 1,
            order_by=[(created_order, [])],
            use_clause='USE INDEX (%s) USE INDEX FOR ORDER BY (%s)' %
            (field, field),
            where=where_clauses).AndReturn([comment_1])

        self.mox.StubOutWithMock(framework_views, 'MakeAllUserViews')
        framework_views.MakeAllUserViews(mox.IgnoreArg(), self.services.user,
                                         [self.user_id],
                                         []).AndReturn({self.user_id: user})

        self.mox.ReplayAll()

        mr = testing_helpers.MakeMonorailRequest()
        if ascending:
            mr.after = self.mr_after

        updates_page_url = 'testing/testing'
        updates_data = activities.GatherUpdatesData(
            self.services,
            mr,
            profiler.Profiler(),
            project_ids=project_ids,
            user_ids=user_ids,
            ending=None,
            autolink=None,
            highlight='highlightme',
            updates_page_url=updates_page_url)
        self.mox.VerifyAll()

        if mr.after:
            pagination = updates_data['pagination']
            self.assertIsNone(pagination.last)
            self.assertEquals(
                '%s?before=%d' %
                (updates_page_url.split('/')[-1], self.comment_timestamp),
                pagination.next_url)
            self.assertEquals(
                '%s?after=%d' %
                (updates_page_url.split('/')[-1], self.comment_timestamp),
                pagination.prev_url)

        activity_view = updates_data['updates_data'].older[0]
        self.assertEqual(
            '<a class="ot-issue-link"\n \n '
            'href="/p//issues/detail?id=%s#c_ts%s"\n >'
            'issue %s</a>\n\n()\n\n\n\n\n \n commented on' %
            (self.issue_local_id, self.comment_timestamp, self.issue_local_id),
            activity_view.escaped_title)
        self.assertEqual(
            '<span class="ot-issue-comment">\n this is the 1st comment\n</span>',
            activity_view.escaped_body)
        self.assertEqual('highlightme', activity_view.highlight)
        self.assertEqual(self.project_name, activity_view.project_name)
Beispiel #9
0
    def createAndAssertUpdates(self,
                               project_ids=None,
                               user_ids=None,
                               ascending=True):
        user = user_pb2.MakeUser(self.user_id)
        comment_1 = tracker_pb2.IssueComment(id=self.comment_id,
                                             issue_id=self.issue_id,
                                             project_id=self.project_id,
                                             user_id=self.user_id,
                                             content='this is the 1st comment',
                                             timestamp=self.comment_timestamp)
        self.mox.StubOutWithMock(self.services.issue, 'GetIssueActivity')

        after = 0
        if ascending:
            after = self.mr_after
        self.services.issue.GetIssueActivity(mox.IgnoreArg(),
                                             num=50,
                                             before=0,
                                             after=after,
                                             project_ids=project_ids,
                                             user_ids=user_ids,
                                             ascending=ascending).AndReturn(
                                                 [comment_1])

        self.mox.StubOutWithMock(framework_views, 'MakeAllUserViews')
        framework_views.MakeAllUserViews(mox.IgnoreArg(), self.services.user,
                                         [self.user_id],
                                         []).AndReturn({self.user_id: user})

        self.mox.ReplayAll()

        mr = testing_helpers.MakeMonorailRequest()
        if ascending:
            mr.after = self.mr_after

        updates_page_url = 'testing/testing'
        updates_data = activities.GatherUpdatesData(
            self.services,
            mr,
            project_ids=project_ids,
            user_ids=user_ids,
            ending=None,
            autolink=None,
            highlight='highlightme',
            updates_page_url=updates_page_url)
        self.mox.VerifyAll()

        if mr.after:
            pagination = updates_data['pagination']
            self.assertIsNone(pagination.last)
            self.assertEquals(
                '%s?before=%d' %
                (updates_page_url.split('/')[-1], self.comment_timestamp),
                pagination.next_url)
            self.assertEquals(
                '%s?after=%d' %
                (updates_page_url.split('/')[-1], self.comment_timestamp),
                pagination.prev_url)

        activity_view = updates_data['updates_data'].older[0]
        self.assertEqual(
            '<a class="ot-issue-link"\n \n '
            'href="/p//issues/detail?id=%s#c_ts%s"\n >'
            'issue %s</a>\n\n()\n\n\n\n\n \n commented on' %
            (self.issue_local_id, self.comment_timestamp, self.issue_local_id),
            activity_view.escaped_title)
        self.assertEqual(
            '<span class="ot-issue-comment">\n this is the 1st comment\n</span>',
            activity_view.escaped_body)
        self.assertEqual('highlightme', activity_view.highlight)
        self.assertEqual(self.project_name, activity_view.project_name)