Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | # 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.""" |
| 7 | from __future__ import print_function |
| 8 | from __future__ import division |
| 9 | from __future__ import absolute_import |
| 10 | |
| 11 | import unittest |
| 12 | |
| 13 | from features import savedqueries |
| 14 | from framework import monorailrequest |
| 15 | from framework import permissions |
| 16 | from services import service_manager |
| 17 | from testing import fake |
| 18 | |
| 19 | |
| 20 | class 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) |