blob: 4eae1abbd5e420f4420b00b521e81c4735d1e993 [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
13import mox
14
15from features import activities
16from framework import framework_views
17from framework import profiler
18from proto import tracker_pb2
19from proto import user_pb2
20from services import service_manager
21from testing import fake
22from testing import testing_helpers
23
24
25class ActivitiesTest(unittest.TestCase):
26
27 def setUp(self):
28 self.services = service_manager.Services(
29 config=fake.ConfigService(),
30 issue=fake.IssueService(),
31 user=fake.UserService(),
32 usergroup=fake.UserGroupService(),
33 project=fake.ProjectService(),
34 )
35
36 self.project_name = 'proj'
37 self.project_id = 987
38 self.project = self.services.project.TestAddProject(
39 self.project_name, project_id=self.project_id,
40 process_inbound_email=True)
41
42 self.issue_id = 11
43 self.issue_local_id = 100
44 self.issue = tracker_pb2.Issue()
45 self.issue.issue_id = self.issue_id
46 self.issue.project_id = self.project_id
47 self.issue.local_id = self.issue_local_id
48 self.services.issue.TestAddIssue(self.issue)
49
50 self.comment_id = 123
51 self.comment_timestamp = 120
52 self.user = self.services.user.TestAddUser('testuser@example.com', 2)
53 self.user_id = self.user.user_id
54 self.mr_after = 1234
55
56 self.mox = mox.Mox()
57
58 def tearDown(self):
59 self.mox.UnsetStubs()
60 self.mox.ResetAll()
61
62 def testActivities_NoUpdates(self):
63 mr = testing_helpers.MakeMonorailRequest()
64 updates_data = activities.GatherUpdatesData(
65 self.services, mr, project_ids=[256],
66 user_ids=None, ending=None, updates_page_url=None, autolink=None,
67 highlight=None)
68
69 self.assertIsNone(updates_data['pagination'])
70 self.assertIsNone(updates_data['no_stars'])
71 self.assertIsNone(updates_data['updates_data'])
72 self.assertEqual('yes', updates_data['no_activities'])
73 self.assertIsNone(updates_data['ending_type'])
74
75 def createAndAssertUpdates(self, project_ids=None, user_ids=None,
76 ascending=True):
77 comment_1 = tracker_pb2.IssueComment(
78 id=self.comment_id, issue_id=self.issue_id,
79 project_id=self.project_id, user_id=self.user_id,
80 content='this is the 1st comment',
81 timestamp=self.comment_timestamp)
82 self.mox.StubOutWithMock(self.services.issue, 'GetIssueActivity')
83
84 after = 0
85 if ascending:
86 after = self.mr_after
87 self.services.issue.GetIssueActivity(
88 mox.IgnoreArg(), num=50, before=0, after=after, project_ids=project_ids,
89 user_ids=user_ids, ascending=ascending).AndReturn([comment_1])
90
91 self.mox.ReplayAll()
92
93 mr = testing_helpers.MakeMonorailRequest()
94 if ascending:
95 mr.after = self.mr_after
96
97 updates_page_url='testing/testing'
98 updates_data = activities.GatherUpdatesData(
99 self.services, mr, project_ids=project_ids,
100 user_ids=user_ids, ending=None, autolink=None,
101 highlight='highlightme', updates_page_url=updates_page_url)
102 self.mox.VerifyAll()
103
104 if mr.after:
105 pagination = updates_data['pagination']
106 self.assertIsNone(pagination.last)
107 self.assertEqual(
108 '%s?before=%d' %
109 (updates_page_url.split('/')[-1], self.comment_timestamp),
110 pagination.next_url)
111 self.assertEqual(
112 '%s?after=%d' %
113 (updates_page_url.split('/')[-1], self.comment_timestamp),
114 pagination.prev_url)
115
116 activity_view = updates_data['updates_data'].older[0]
117 self.assertEqual(
118 '<a class="ot-issue-link"\n \n '
119 'href="/p//issues/detail?id=%s#c_ts%s"\n >'
120 'issue %s</a>\n\n()\n\n\n\n\n \n commented on' % (
121 self.issue_local_id, self.comment_timestamp, self.issue_local_id),
122 activity_view.escaped_title)
123 self.assertEqual(
124 '<span class="ot-issue-comment">\n this is the 1st comment\n</span>',
125 activity_view.escaped_body)
126 self.assertEqual('highlightme', activity_view.highlight)
127 self.assertEqual(self.project_name, activity_view.project_name)
128
129 def testActivities_AscendingProjectUpdates(self):
130 self.createAndAssertUpdates(project_ids=[self.project_id], ascending=True)
131
132 def testActivities_DescendingProjectUpdates(self):
133 self.createAndAssertUpdates(project_ids=[self.project_id], ascending=False)
134
135 def testActivities_AscendingUserUpdates(self):
136 self.createAndAssertUpdates(user_ids=[self.user_id], ascending=True)
137
138 def testActivities_DescendingUserUpdates(self):
139 self.createAndAssertUpdates(user_ids=[self.user_id], ascending=False)
140
141 def testActivities_SpecifyProjectAndUser(self):
142 self.createAndAssertUpdates(
143 project_ids=[self.project_id], user_ids=[self.user_id], ascending=False)