blob: 56758460064d6552aacfde857675c474bb0454f6 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# 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.
Copybara854996b2021-09-07 19:36:02 +00004
5"""Tests for the user settings page."""
6from __future__ import print_function
7from __future__ import division
8from __future__ import absolute_import
9
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010010import six
Copybara854996b2021-09-07 19:36:02 +000011import 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
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010021from mrproto import user_pb2
Copybara854996b2021-09-07 19:36:02 +000022from 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
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010061 six.assertCountEqual(
62 self, [
63 'logged_in_user_pb', 'unified', 'user_tab_mode', 'viewed_user',
64 'offer_saved_queries_subtab', 'viewing_self'
65 ], list(page_data.keys()))
Copybara854996b2021-09-07 19:36:02 +000066 self.assertEqual(template_helpers.PBProxy(mr.auth.user_pb),
67 page_data['logged_in_user_pb'])
68
69 self.mox.VerifyAll()