blob: d0247555c2152930feaae1723519cbc287a0bd8a [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# Copyright 2016 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
Copybara854996b2021-09-07 19:36:02 +00004
5"""Unittests for monorail.sitewide.userupdates."""
6from __future__ import print_function
7from __future__ import division
8from __future__ import absolute_import
9
10import unittest
11
Adrià Vilanova Martínez9f9ade52022-10-10 23:20:11 +020012try:
13 from mox3 import mox
14except ImportError:
15 import mox
Copybara854996b2021-09-07 19:36:02 +000016
17from features import activities
18from services import service_manager
19from sitewide import sitewide_helpers
20from sitewide import userupdates
21from testing import fake
22from testing import testing_helpers
23
24
25class ProjectUpdatesTest(unittest.TestCase):
26
27 def setUp(self):
28 self.services = service_manager.Services(
29 project=fake.ProjectService(),
30 user_star=fake.UserStarService())
31
32 self.user_id = 2
33 self.project_id = 987
34 self.project = self.services.project.TestAddProject(
35 'proj', project_id=self.project_id)
36
37 self.mr = testing_helpers.MakeMonorailRequest(
38 services=self.services, project=self.project)
39 self.mr.cnxn = 'fake cnxn'
40 self.mr.viewed_user_auth.user_id = 100
41
42 self.mox = mox.Mox()
43
44 def tearDown(self):
45 self.mox.UnsetStubs()
46 self.mox.ResetAll()
47
48 def testUserUpdatesProjects(self):
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010049 uup = userupdates.UserUpdatesProjects(self.services)
Copybara854996b2021-09-07 19:36:02 +000050
51 self.mox.StubOutWithMock(sitewide_helpers, 'GetViewableStarredProjects')
52 sitewide_helpers.GetViewableStarredProjects(
53 self.mr.cnxn, self.services, self.mr.viewed_user_auth.user_id,
54 self.mr.auth.effective_ids, self.mr.auth.user_pb).AndReturn(
55 [self.project])
56
57 self.mox.StubOutWithMock(activities, 'GatherUpdatesData')
58 activities.GatherUpdatesData(
59 self.services, self.mr, user_ids=None,
60 project_ids=[self.project_id],
61 ending=uup._ENDING,
62 updates_page_url=uup._UPDATES_PAGE_URL,
63 highlight=uup._HIGHLIGHT).AndReturn({})
64
65 self.mox.ReplayAll()
66
67 page_data = uup.GatherPageData(self.mr)
68 self.mox.VerifyAll()
69 self.assertEqual(3, len(page_data))
70 self.assertEqual('st5', page_data['user_tab_mode'])
71 self.assertEqual('yes', page_data['viewing_user_page'])
72 self.assertEqual(uup._TAB_MODE, page_data['user_updates_tab_mode'])
73
74 def testUserUpdatesDevelopers(self):
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010075 uud = userupdates.UserUpdatesDevelopers(self.services)
Copybara854996b2021-09-07 19:36:02 +000076
77 self.mox.StubOutWithMock(self.services.user_star, 'LookupStarredItemIDs')
78 self.services.user_star.LookupStarredItemIDs(
79 self.mr.cnxn, self.mr.viewed_user_auth.user_id).AndReturn(
80 [self.user_id])
81
82 self.mox.StubOutWithMock(activities, 'GatherUpdatesData')
83 activities.GatherUpdatesData(
84 self.services, self.mr, user_ids=[self.user_id],
85 project_ids=None, ending=uud._ENDING,
86 updates_page_url=uud._UPDATES_PAGE_URL,
87 highlight=uud._HIGHLIGHT).AndReturn({})
88
89 self.mox.ReplayAll()
90
91 page_data = uud.GatherPageData(self.mr)
92 self.mox.VerifyAll()
93 self.assertEqual(3, len(page_data))
94 self.assertEqual('st5', page_data['user_tab_mode'])
95 self.assertEqual('yes', page_data['viewing_user_page'])
96 self.assertEqual(uud._TAB_MODE, page_data['user_updates_tab_mode'])
97
98 def testUserUpdatesIndividual(self):
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010099 uui = userupdates.UserUpdatesIndividual(self.services)
Copybara854996b2021-09-07 19:36:02 +0000100
101 self.mox.StubOutWithMock(activities, 'GatherUpdatesData')
102 activities.GatherUpdatesData(
103 self.services, self.mr,
104 user_ids=[self.mr.viewed_user_auth.user_id],
105 project_ids=None, ending=uui._ENDING,
106 updates_page_url=uui._UPDATES_PAGE_URL,
107 highlight=uui._HIGHLIGHT).AndReturn({})
108
109 self.mox.ReplayAll()
110
111 page_data = uui.GatherPageData(self.mr)
112 self.mox.VerifyAll()
113 self.assertEqual(3, len(page_data))
114 self.assertEqual('st5', page_data['user_tab_mode'])
115 self.assertEqual('yes', page_data['viewing_user_page'])
116 self.assertEqual(uui._TAB_MODE, page_data['user_updates_tab_mode'])