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