blob: 725b123d41b4de70705f663ccd7c8042622725ed [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.sitewide.userupdates."""
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 services import service_manager
20from sitewide import sitewide_helpers
21from sitewide import userupdates
22from testing import fake
23from testing import testing_helpers
24
25
26class ProjectUpdatesTest(unittest.TestCase):
27
28 def setUp(self):
29 self.services = service_manager.Services(
30 project=fake.ProjectService(),
31 user_star=fake.UserStarService())
32
33 self.user_id = 2
34 self.project_id = 987
35 self.project = self.services.project.TestAddProject(
36 'proj', project_id=self.project_id)
37
38 self.mr = testing_helpers.MakeMonorailRequest(
39 services=self.services, project=self.project)
40 self.mr.cnxn = 'fake cnxn'
41 self.mr.viewed_user_auth.user_id = 100
42
43 self.mox = mox.Mox()
44
45 def tearDown(self):
46 self.mox.UnsetStubs()
47 self.mox.ResetAll()
48
49 def testUserUpdatesProjects(self):
50 uup = userupdates.UserUpdatesProjects(None, None, self.services)
51
52 self.mox.StubOutWithMock(sitewide_helpers, 'GetViewableStarredProjects')
53 sitewide_helpers.GetViewableStarredProjects(
54 self.mr.cnxn, self.services, self.mr.viewed_user_auth.user_id,
55 self.mr.auth.effective_ids, self.mr.auth.user_pb).AndReturn(
56 [self.project])
57
58 self.mox.StubOutWithMock(activities, 'GatherUpdatesData')
59 activities.GatherUpdatesData(
60 self.services, self.mr, user_ids=None,
61 project_ids=[self.project_id],
62 ending=uup._ENDING,
63 updates_page_url=uup._UPDATES_PAGE_URL,
64 highlight=uup._HIGHLIGHT).AndReturn({})
65
66 self.mox.ReplayAll()
67
68 page_data = uup.GatherPageData(self.mr)
69 self.mox.VerifyAll()
70 self.assertEqual(3, len(page_data))
71 self.assertEqual('st5', page_data['user_tab_mode'])
72 self.assertEqual('yes', page_data['viewing_user_page'])
73 self.assertEqual(uup._TAB_MODE, page_data['user_updates_tab_mode'])
74
75 def testUserUpdatesDevelopers(self):
76 uud = userupdates.UserUpdatesDevelopers(None, None, self.services)
77
78 self.mox.StubOutWithMock(self.services.user_star, 'LookupStarredItemIDs')
79 self.services.user_star.LookupStarredItemIDs(
80 self.mr.cnxn, self.mr.viewed_user_auth.user_id).AndReturn(
81 [self.user_id])
82
83 self.mox.StubOutWithMock(activities, 'GatherUpdatesData')
84 activities.GatherUpdatesData(
85 self.services, self.mr, user_ids=[self.user_id],
86 project_ids=None, ending=uud._ENDING,
87 updates_page_url=uud._UPDATES_PAGE_URL,
88 highlight=uud._HIGHLIGHT).AndReturn({})
89
90 self.mox.ReplayAll()
91
92 page_data = uud.GatherPageData(self.mr)
93 self.mox.VerifyAll()
94 self.assertEqual(3, len(page_data))
95 self.assertEqual('st5', page_data['user_tab_mode'])
96 self.assertEqual('yes', page_data['viewing_user_page'])
97 self.assertEqual(uud._TAB_MODE, page_data['user_updates_tab_mode'])
98
99 def testUserUpdatesIndividual(self):
100 uui = userupdates.UserUpdatesIndividual(None, None, self.services)
101
102 self.mox.StubOutWithMock(activities, 'GatherUpdatesData')
103 activities.GatherUpdatesData(
104 self.services, self.mr,
105 user_ids=[self.mr.viewed_user_auth.user_id],
106 project_ids=None, ending=uui._ENDING,
107 updates_page_url=uui._UPDATES_PAGE_URL,
108 highlight=uui._HIGHLIGHT).AndReturn({})
109
110 self.mox.ReplayAll()
111
112 page_data = uui.GatherPageData(self.mr)
113 self.mox.VerifyAll()
114 self.assertEqual(3, len(page_data))
115 self.assertEqual('st5', page_data['user_tab_mode'])
116 self.assertEqual('yes', page_data['viewing_user_page'])
117 self.assertEqual(uui._TAB_MODE, page_data['user_updates_tab_mode'])