Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | # 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. |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 4 | |
| 5 | """Unittests for monorail.sitewide.userupdates.""" |
| 6 | from __future__ import print_function |
| 7 | from __future__ import division |
| 8 | from __future__ import absolute_import |
| 9 | |
| 10 | import unittest |
| 11 | |
Adrià Vilanova Martínez | 9f9ade5 | 2022-10-10 23:20:11 +0200 | [diff] [blame] | 12 | try: |
| 13 | from mox3 import mox |
| 14 | except ImportError: |
| 15 | import mox |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 16 | |
| 17 | from features import activities |
| 18 | from services import service_manager |
| 19 | from sitewide import sitewide_helpers |
| 20 | from sitewide import userupdates |
| 21 | from testing import fake |
| 22 | from testing import testing_helpers |
| 23 | |
| 24 | |
| 25 | class 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ínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 49 | uup = userupdates.UserUpdatesProjects(self.services) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 50 | |
| 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ínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 75 | uud = userupdates.UserUpdatesDevelopers(self.services) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 76 | |
| 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ínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 99 | uui = userupdates.UserUpdatesIndividual(self.services) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 100 | |
| 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']) |