Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | # 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. |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 4 | |
| 5 | """Unit tests for savedqueries feature.""" |
| 6 | from __future__ import print_function |
| 7 | from __future__ import division |
| 8 | from __future__ import absolute_import |
| 9 | |
| 10 | import unittest |
| 11 | |
| 12 | from features import savedqueries |
| 13 | from framework import monorailrequest |
| 14 | from framework import permissions |
| 15 | from services import service_manager |
| 16 | from testing import fake |
| 17 | |
| 18 | |
| 19 | class SavedQueriesTest(unittest.TestCase): |
| 20 | |
| 21 | def setUp(self): |
| 22 | self.services = service_manager.Services( |
| 23 | user=fake.UserService()) |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 24 | self.servlet = savedqueries.SavedQueries(services=self.services) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 25 | 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) |