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