Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Unified Diff: appengine/monorail/project/test/peoplelist_test.py

Issue 1868553004: Open Source Monorail (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/monorail/project/test/peoplelist_test.py
diff --git a/appengine/monorail/project/test/peoplelist_test.py b/appengine/monorail/project/test/peoplelist_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..72c52755166925b58c0713dd87fab96897e2332a
--- /dev/null
+++ b/appengine/monorail/project/test/peoplelist_test.py
@@ -0,0 +1,119 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is govered by a BSD-style
+# license that can be found in the LICENSE file or at
+# https://developers.google.com/open-source/licenses/bsd
+
+"""Unittest for People List servlet."""
+
+import unittest
+
+from framework import monorailrequest
+from framework import permissions
+from project import peoplelist
+from services import service_manager
+from testing import fake
+from testing import testing_helpers
+
+
+class PeopleListTest(unittest.TestCase):
+ """Tests for the PeopleList servlet."""
+
+ def setUp(self):
+ services = service_manager.Services(
+ project=fake.ProjectService(),
+ user=fake.UserService(),
+ usergroup=fake.UserGroupService())
+ services.user.TestAddUser('jrobbins@gmail.com', 111L)
+ services.user.TestAddUser('jrobbins@jrobbins.org', 222L)
+ services.user.TestAddUser('jrobbins@chromium.org', 333L)
+ services.user.TestAddUser('imso31337@gmail.com', 999L)
+ self.project = services.project.TestAddProject('proj')
+ self.project.owner_ids.extend([111L])
+ self.project.committer_ids.extend([222L])
+ self.project.contributor_ids.extend([333L])
+ self.servlet = peoplelist.PeopleList('req', 'res', services=services)
+
+ def VerifyAccess(self, exception_expected):
+ mr = testing_helpers.MakeMonorailRequest(
+ path='/p/proj/people/list',
+ project=self.project,
+ perms=permissions.OWNER_ACTIVE_PERMISSIONSET)
+ self.servlet.AssertBasePermission(mr)
+ # Owner never raises PermissionException.
+
+ mr = testing_helpers.MakeMonorailRequest(
+ path='/p/proj/people/list',
+ project=self.project,
+ perms=permissions.COMMITTER_ACTIVE_PERMISSIONSET)
+ self.servlet.AssertBasePermission(mr)
+ # Committer never raises PermissionException.
+
+ mr = testing_helpers.MakeMonorailRequest(
+ path='/p/proj/people/list',
+ project=self.project,
+ perms=permissions.CONTRIBUTOR_ACTIVE_PERMISSIONSET)
+ if exception_expected:
+ self.assertRaises(permissions.PermissionException,
+ self.servlet.AssertBasePermission, mr)
+ else:
+ self.servlet.AssertBasePermission(mr)
+ # No PermissionException raised
+
+ # Sign-out users
+ mr = testing_helpers.MakeMonorailRequest(
+ path='/p/proj/people/detail?u=555',
+ project=self.project,
+ perms=permissions.READ_ONLY_PERMISSIONSET)
+ if exception_expected:
+ self.assertRaises(permissions.PermissionException,
+ self.servlet.AssertBasePermission, mr)
+ else:
+ self.servlet.AssertBasePermission(mr)
+
+ # Non-membr users
+ mr = testing_helpers.MakeMonorailRequest(
+ path='/p/proj/people/detail?u=555',
+ project=self.project,
+ perms=permissions.USER_PERMISSIONSET)
+ if exception_expected:
+ self.assertRaises(permissions.PermissionException,
+ self.servlet.AssertBasePermission, mr)
+ else:
+ self.servlet.AssertBasePermission(mr)
+
+ def testAssertBasePermission_Normal(self):
+ self.VerifyAccess(False)
+
+ def testAssertBasePermission_HideMembers(self):
+ self.project.only_owners_see_contributors = True
+ self.VerifyAccess(True)
+
+ def testGatherPageData(self):
+ mr = testing_helpers.MakeMonorailRequest(
+ path='/p/proj/people/list',
+ project=self.project,
+ perms=permissions.OWNER_ACTIVE_PERMISSIONSET)
+ mr.auth = monorailrequest.AuthData()
+ page_data = self.servlet.GatherPageData(mr)
+
+ self.assertEqual(1, page_data['total_num_owners'])
+ # TODO(jrobbins): fill in tests for all other aspects.
+
+ def testProcessFormData_Permission(self):
+ """Only owners could add/remove members."""
+ mr = testing_helpers.MakeMonorailRequest(
+ path='/p/proj/people/list',
+ project=self.project,
+ perms=permissions.CONTRIBUTOR_ACTIVE_PERMISSIONSET)
+ self.assertRaises(permissions.PermissionException,
+ self.servlet.ProcessFormData, mr, {})
+
+ mr = testing_helpers.MakeMonorailRequest(
+ path='/p/proj/people/list',
+ project=self.project,
+ perms=permissions.OWNER_ACTIVE_PERMISSIONSET)
+ self.servlet.ProcessFormData(mr, {})
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « appengine/monorail/project/test/peopledetail_test.py ('k') | appengine/monorail/project/test/project_helpers_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698