blob: 08624a20f02c9cc6fff88bca4c3350df7346b662 [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"""Unit tests for savedqueries feature."""
7from __future__ import print_function
8from __future__ import division
9from __future__ import absolute_import
10
11import unittest
12
13from features import savedqueries
14from framework import monorailrequest
15from framework import permissions
16from services import service_manager
17from testing import fake
18
19
20class SavedQueriesTest(unittest.TestCase):
21
22 def setUp(self):
23 self.services = service_manager.Services(
24 user=fake.UserService())
25 self.servlet = savedqueries.SavedQueries(
26 'req', 'res', services=self.services)
27 self.services.user.TestAddUser('a@example.com', 111)
28
29 def testAssertBasePermission(self):
30 """Only permit site admins and users viewing themselves."""
31 mr = monorailrequest.MonorailRequest(self.services)
32 mr.viewed_user_auth.user_id = 111
33 mr.auth.user_id = 222
34
35 self.assertRaises(permissions.PermissionException,
36 self.servlet.AssertBasePermission, mr)
37
38 mr.auth.user_id = 111
39 self.servlet.AssertBasePermission(mr)
40
41 mr.auth.user_id = 222
42 mr.auth.user_pb.is_site_admin = True
43 self.servlet.AssertBasePermission(mr)