blob: 54c14aed15bd8954a27604faf09955d3b395e755 [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"""Tests for the user settings page."""
7from __future__ import print_function
8from __future__ import division
9from __future__ import absolute_import
10
11import unittest
12
13import mox
14
15from framework import framework_helpers
16from framework import permissions
17from framework import template_helpers
18from proto import user_pb2
19from services import service_manager
20from sitewide import usersettings
21from testing import fake
22from testing import testing_helpers
23
24
25class UserSettingsTest(unittest.TestCase):
26
27 def setUp(self):
28 self.mox = mox.Mox()
29 self.services = service_manager.Services(user=fake.UserService())
30 self.servlet = usersettings.UserSettings(
31 'req', 'res', services=self.services)
32
33 def tearDown(self):
34 self.mox.UnsetStubs()
35
36 def testAssertBasePermission(self):
37 mr = testing_helpers.MakeMonorailRequest()
38 mr.auth.user_id = 111
39
40 # The following should return without exception.
41 self.servlet.AssertBasePermission(mr)
42
43 # No logged in user means anonymous access, should raise error.
44 mr.auth.user_id = 0
45 self.assertRaises(permissions.PermissionException,
46 self.servlet.AssertBasePermission, mr)
47
48 def testGatherPageData(self):
49 self.mox.StubOutWithMock(
50 framework_helpers.UserSettings, 'GatherUnifiedSettingsPageData')
51 framework_helpers.UserSettings.GatherUnifiedSettingsPageData(
52 0, None, mox.IsA(user_pb2.User), mox.IsA(user_pb2.UserPrefs)
53 ).AndReturn({'unified': None})
54 self.mox.ReplayAll()
55
56 mr = testing_helpers.MakeMonorailRequest()
57 page_data = self.servlet.GatherPageData(mr)
58
59 self.assertItemsEqual(
60 ['logged_in_user_pb', 'unified', 'user_tab_mode',
61 'viewed_user', 'offer_saved_queries_subtab', 'viewing_self'],
62 list(page_data.keys()))
63 self.assertEqual(template_helpers.PBProxy(mr.auth.user_pb),
64 page_data['logged_in_user_pb'])
65
66 self.mox.VerifyAll()