OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is govered 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 """Unittest for People List servlet.""" |
| 7 |
| 8 import unittest |
| 9 |
| 10 from framework import monorailrequest |
| 11 from framework import permissions |
| 12 from project import peoplelist |
| 13 from services import service_manager |
| 14 from testing import fake |
| 15 from testing import testing_helpers |
| 16 |
| 17 |
| 18 class PeopleListTest(unittest.TestCase): |
| 19 """Tests for the PeopleList servlet.""" |
| 20 |
| 21 def setUp(self): |
| 22 services = service_manager.Services( |
| 23 project=fake.ProjectService(), |
| 24 user=fake.UserService(), |
| 25 usergroup=fake.UserGroupService()) |
| 26 services.user.TestAddUser('jrobbins@gmail.com', 111L) |
| 27 services.user.TestAddUser('jrobbins@jrobbins.org', 222L) |
| 28 services.user.TestAddUser('jrobbins@chromium.org', 333L) |
| 29 services.user.TestAddUser('imso31337@gmail.com', 999L) |
| 30 self.project = services.project.TestAddProject('proj') |
| 31 self.project.owner_ids.extend([111L]) |
| 32 self.project.committer_ids.extend([222L]) |
| 33 self.project.contributor_ids.extend([333L]) |
| 34 self.servlet = peoplelist.PeopleList('req', 'res', services=services) |
| 35 |
| 36 def VerifyAccess(self, exception_expected): |
| 37 mr = testing_helpers.MakeMonorailRequest( |
| 38 path='/p/proj/people/list', |
| 39 project=self.project, |
| 40 perms=permissions.OWNER_ACTIVE_PERMISSIONSET) |
| 41 self.servlet.AssertBasePermission(mr) |
| 42 # Owner never raises PermissionException. |
| 43 |
| 44 mr = testing_helpers.MakeMonorailRequest( |
| 45 path='/p/proj/people/list', |
| 46 project=self.project, |
| 47 perms=permissions.COMMITTER_ACTIVE_PERMISSIONSET) |
| 48 self.servlet.AssertBasePermission(mr) |
| 49 # Committer never raises PermissionException. |
| 50 |
| 51 mr = testing_helpers.MakeMonorailRequest( |
| 52 path='/p/proj/people/list', |
| 53 project=self.project, |
| 54 perms=permissions.CONTRIBUTOR_ACTIVE_PERMISSIONSET) |
| 55 if exception_expected: |
| 56 self.assertRaises(permissions.PermissionException, |
| 57 self.servlet.AssertBasePermission, mr) |
| 58 else: |
| 59 self.servlet.AssertBasePermission(mr) |
| 60 # No PermissionException raised |
| 61 |
| 62 # Sign-out users |
| 63 mr = testing_helpers.MakeMonorailRequest( |
| 64 path='/p/proj/people/detail?u=555', |
| 65 project=self.project, |
| 66 perms=permissions.READ_ONLY_PERMISSIONSET) |
| 67 if exception_expected: |
| 68 self.assertRaises(permissions.PermissionException, |
| 69 self.servlet.AssertBasePermission, mr) |
| 70 else: |
| 71 self.servlet.AssertBasePermission(mr) |
| 72 |
| 73 # Non-membr users |
| 74 mr = testing_helpers.MakeMonorailRequest( |
| 75 path='/p/proj/people/detail?u=555', |
| 76 project=self.project, |
| 77 perms=permissions.USER_PERMISSIONSET) |
| 78 if exception_expected: |
| 79 self.assertRaises(permissions.PermissionException, |
| 80 self.servlet.AssertBasePermission, mr) |
| 81 else: |
| 82 self.servlet.AssertBasePermission(mr) |
| 83 |
| 84 def testAssertBasePermission_Normal(self): |
| 85 self.VerifyAccess(False) |
| 86 |
| 87 def testAssertBasePermission_HideMembers(self): |
| 88 self.project.only_owners_see_contributors = True |
| 89 self.VerifyAccess(True) |
| 90 |
| 91 def testGatherPageData(self): |
| 92 mr = testing_helpers.MakeMonorailRequest( |
| 93 path='/p/proj/people/list', |
| 94 project=self.project, |
| 95 perms=permissions.OWNER_ACTIVE_PERMISSIONSET) |
| 96 mr.auth = monorailrequest.AuthData() |
| 97 page_data = self.servlet.GatherPageData(mr) |
| 98 |
| 99 self.assertEqual(1, page_data['total_num_owners']) |
| 100 # TODO(jrobbins): fill in tests for all other aspects. |
| 101 |
| 102 def testProcessFormData_Permission(self): |
| 103 """Only owners could add/remove members.""" |
| 104 mr = testing_helpers.MakeMonorailRequest( |
| 105 path='/p/proj/people/list', |
| 106 project=self.project, |
| 107 perms=permissions.CONTRIBUTOR_ACTIVE_PERMISSIONSET) |
| 108 self.assertRaises(permissions.PermissionException, |
| 109 self.servlet.ProcessFormData, mr, {}) |
| 110 |
| 111 mr = testing_helpers.MakeMonorailRequest( |
| 112 path='/p/proj/people/list', |
| 113 project=self.project, |
| 114 perms=permissions.OWNER_ACTIVE_PERMISSIONSET) |
| 115 self.servlet.ProcessFormData(mr, {}) |
| 116 |
| 117 |
| 118 if __name__ == '__main__': |
| 119 unittest.main() |
OLD | NEW |