blob: c17eb4ba6fd2ba373a1731d11c53cdaba0d2d0de [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001# Copyright 2016 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style
3# license that can be found in the LICENSE file or at
4# https://developers.google.com/open-source/licenses/bsd
5
6"""Unittests for monorail.feature.activities."""
7from __future__ import print_function
8from __future__ import division
9from __future__ import absolute_import
10
11import unittest
12
Adrià Vilanova Martínez9f9ade52022-10-10 23:20:11 +020013try:
14 from mox3 import mox
15except ImportError:
16 import mox
Copybara854996b2021-09-07 19:36:02 +000017
18from features import activities
19from framework import framework_views
20from framework import profiler
21from proto import tracker_pb2
22from proto import user_pb2
23from services import service_manager
24from testing import fake
25from testing import testing_helpers
26
27
28class ActivitiesTest(unittest.TestCase):
29
30 def setUp(self):
31 self.services = service_manager.Services(
32 config=fake.ConfigService(),
33 issue=fake.IssueService(),
34 user=fake.UserService(),
35 usergroup=fake.UserGroupService(),
36 project=fake.ProjectService(),
37 )
38
39 self.project_name = 'proj'
40 self.project_id = 987
41 self.project = self.services.project.TestAddProject(
42 self.project_name, project_id=self.project_id,
43 process_inbound_email=True)
44
45 self.issue_id = 11
46 self.issue_local_id = 100
47 self.issue = tracker_pb2.Issue()
48 self.issue.issue_id = self.issue_id
49 self.issue.project_id = self.project_id
50 self.issue.local_id = self.issue_local_id
51 self.services.issue.TestAddIssue(self.issue)
52
53 self.comment_id = 123
54 self.comment_timestamp = 120
55 self.user = self.services.user.TestAddUser('testuser@example.com', 2)
56 self.user_id = self.user.user_id
57 self.mr_after = 1234
58
59 self.mox = mox.Mox()
60
61 def tearDown(self):
62 self.mox.UnsetStubs()
63 self.mox.ResetAll()
64
65 def testActivities_NoUpdates(self):
66 mr = testing_helpers.MakeMonorailRequest()
67 updates_data = activities.GatherUpdatesData(
68 self.services, mr, project_ids=[256],
69 user_ids=None, ending=None, updates_page_url=None, autolink=None,
70 highlight=None)
71
72 self.assertIsNone(updates_data['pagination'])
73 self.assertIsNone(updates_data['no_stars'])
74 self.assertIsNone(updates_data['updates_data'])
75 self.assertEqual('yes', updates_data['no_activities'])
76 self.assertIsNone(updates_data['ending_type'])
77
78 def createAndAssertUpdates(self, project_ids=None, user_ids=None,
79 ascending=True):
80 comment_1 = tracker_pb2.IssueComment(
81 id=self.comment_id, issue_id=self.issue_id,
82 project_id=self.project_id, user_id=self.user_id,
83 content='this is the 1st comment',
84 timestamp=self.comment_timestamp)
85 self.mox.StubOutWithMock(self.services.issue, 'GetIssueActivity')
86
87 after = 0
88 if ascending:
89 after = self.mr_after
90 self.services.issue.GetIssueActivity(
91 mox.IgnoreArg(), num=50, before=0, after=after, project_ids=project_ids,
92 user_ids=user_ids, ascending=ascending).AndReturn([comment_1])
93
94 self.mox.ReplayAll()
95
96 mr = testing_helpers.MakeMonorailRequest()
97 if ascending:
98 mr.after = self.mr_after
99
100 updates_page_url='testing/testing'
101 updates_data = activities.GatherUpdatesData(
102 self.services, mr, project_ids=project_ids,
103 user_ids=user_ids, ending=None, autolink=None,
104 highlight='highlightme', updates_page_url=updates_page_url)
105 self.mox.VerifyAll()
106
107 if mr.after:
108 pagination = updates_data['pagination']
109 self.assertIsNone(pagination.last)
110 self.assertEqual(
111 '%s?before=%d' %
112 (updates_page_url.split('/')[-1], self.comment_timestamp),
113 pagination.next_url)
114 self.assertEqual(
115 '%s?after=%d' %
116 (updates_page_url.split('/')[-1], self.comment_timestamp),
117 pagination.prev_url)
118
119 activity_view = updates_data['updates_data'].older[0]
120 self.assertEqual(
121 '<a class="ot-issue-link"\n \n '
122 'href="/p//issues/detail?id=%s#c_ts%s"\n >'
123 'issue %s</a>\n\n()\n\n\n\n\n \n commented on' % (
124 self.issue_local_id, self.comment_timestamp, self.issue_local_id),
125 activity_view.escaped_title)
126 self.assertEqual(
127 '<span class="ot-issue-comment">\n this is the 1st comment\n</span>',
128 activity_view.escaped_body)
129 self.assertEqual('highlightme', activity_view.highlight)
130 self.assertEqual(self.project_name, activity_view.project_name)
131
132 def testActivities_AscendingProjectUpdates(self):
133 self.createAndAssertUpdates(project_ids=[self.project_id], ascending=True)
134
135 def testActivities_DescendingProjectUpdates(self):
136 self.createAndAssertUpdates(project_ids=[self.project_id], ascending=False)
137
138 def testActivities_AscendingUserUpdates(self):
139 self.createAndAssertUpdates(user_ids=[self.user_id], ascending=True)
140
141 def testActivities_DescendingUserUpdates(self):
142 self.createAndAssertUpdates(user_ids=[self.user_id], ascending=False)
143
144 def testActivities_SpecifyProjectAndUser(self):
145 self.createAndAssertUpdates(
146 project_ids=[self.project_id], user_ids=[self.user_id], ascending=False)