blob: faed83151decc8873e30db82e51c37cb281cdef0 [file] [log] [blame]
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is govered by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
"""Tests for the user settings page."""
import unittest
import mox
from framework import framework_helpers
from framework import permissions
from framework import template_helpers
from proto import user_pb2
from services import service_manager
from sitewide import usersettings
from testing import fake
from testing import testing_helpers
class UserSettingsTest(unittest.TestCase):
def setUp(self):
self.mox = mox.Mox()
self.services = service_manager.Services(user=fake.UserService())
self.servlet = usersettings.UserSettings(
'req', 'res', services=self.services)
def tearDown(self):
self.mox.UnsetStubs()
def testAssertBasePermission(self):
mr = testing_helpers.MakeMonorailRequest()
mr.auth.user_id = 111L
# The following should return without exception.
self.servlet.AssertBasePermission(mr)
# No logged in user means anonymous access, should raise error.
mr.auth.user_id = 0L
self.assertRaises(permissions.PermissionException,
self.servlet.AssertBasePermission, mr)
def testGatherPageData(self):
self.mox.StubOutWithMock(
framework_helpers.UserSettings, 'GatherUnifiedSettingsPageData')
framework_helpers.UserSettings.GatherUnifiedSettingsPageData(
0L, None, mox.IsA(user_pb2.User)).AndReturn({'unified': None})
self.mox.ReplayAll()
mr = testing_helpers.MakeMonorailRequest()
page_data = self.servlet.GatherPageData(mr)
self.assertItemsEqual(
['logged_in_user_pb', 'unified', 'user_tab_mode',
'viewed_user', 'offer_saved_queries_subtab', 'viewing_self'],
page_data.keys())
self.assertEqual(template_helpers.PBProxy(mr.auth.user_pb),
page_data['logged_in_user_pb'])
self.mox.VerifyAll()
if __name__ == '__main__':
unittest.main()