blob: dd7d252b996761ad24af4a01f0ba5dab2c78ea02 [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
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 framework import framework_helpers
19from framework import permissions
20from framework import template_helpers
21from proto import user_pb2
22from services import service_manager
23from sitewide import usersettings
24from testing import fake
25from testing import testing_helpers
26
27
28class UserSettingsTest(unittest.TestCase):
29
30 def setUp(self):
31 self.mox = mox.Mox()
32 self.services = service_manager.Services(user=fake.UserService())
Adrià Vilanova Martínez9f9ade52022-10-10 23:20:11 +020033 self.servlet = usersettings.UserSettings(services=self.services)
Copybara854996b2021-09-07 19:36:02 +000034
35 def tearDown(self):
36 self.mox.UnsetStubs()
37
38 def testAssertBasePermission(self):
39 mr = testing_helpers.MakeMonorailRequest()
40 mr.auth.user_id = 111
41
42 # The following should return without exception.
43 self.servlet.AssertBasePermission(mr)
44
45 # No logged in user means anonymous access, should raise error.
46 mr.auth.user_id = 0
47 self.assertRaises(permissions.PermissionException,
48 self.servlet.AssertBasePermission, mr)
49
50 def testGatherPageData(self):
51 self.mox.StubOutWithMock(
52 framework_helpers.UserSettings, 'GatherUnifiedSettingsPageData')
53 framework_helpers.UserSettings.GatherUnifiedSettingsPageData(
54 0, None, mox.IsA(user_pb2.User), mox.IsA(user_pb2.UserPrefs)
55 ).AndReturn({'unified': None})
56 self.mox.ReplayAll()
57
58 mr = testing_helpers.MakeMonorailRequest()
59 page_data = self.servlet.GatherPageData(mr)
60
61 self.assertItemsEqual(
62 ['logged_in_user_pb', 'unified', 'user_tab_mode',
63 'viewed_user', 'offer_saved_queries_subtab', 'viewing_self'],
64 list(page_data.keys()))
65 self.assertEqual(template_helpers.PBProxy(mr.auth.user_pb),
66 page_data['logged_in_user_pb'])
67
68 self.mox.VerifyAll()