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

Unified Diff: appengine/monorail/project/test/projectadmin_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/projectadmin_test.py
diff --git a/appengine/monorail/project/test/projectadmin_test.py b/appengine/monorail/project/test/projectadmin_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..8f816425e7bba39bdbaf0258247a9aece24e16c9
--- /dev/null
+++ b/appengine/monorail/project/test/projectadmin_test.py
@@ -0,0 +1,76 @@
+# 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
+
+"""Unit tests for projectadmin module."""
+
+import unittest
+
+from framework import permissions
+from project import projectadmin
+from proto import project_pb2
+from services import service_manager
+from testing import fake
+from testing import testing_helpers
+
+
+class ProjectAdminTest(unittest.TestCase):
+ """Unit tests for the ProjectAdmin servlet class."""
+
+ def setUp(self):
+ services = service_manager.Services(
+ project=fake.ProjectService(),
+ user=fake.UserService())
+ self.servlet = projectadmin.ProjectAdmin('req', 'res', services=services)
+ self.project = services.project.TestAddProject(
+ 'proj', summary='a summary', description='a description')
+ self.request, self.mr = testing_helpers.GetRequestObjects(
+ project=self.project)
+
+ def testAssertBasePermission(self):
+ # Contributors cannot edit the project
+ mr = testing_helpers.MakeMonorailRequest(
+ project=self.project,
+ perms=permissions.CONTRIBUTOR_ACTIVE_PERMISSIONSET)
+ self.assertRaises(permissions.PermissionException,
+ self.servlet.AssertBasePermission, mr)
+
+ # Signed-out users cannot edit the project
+ mr.perms = permissions.READ_ONLY_PERMISSIONSET
+ self.assertRaises(permissions.PermissionException,
+ self.servlet.AssertBasePermission, mr)
+
+ # Non-member users cannot edit the project
+ mr.perms = permissions.USER_PERMISSIONSET
+ self.assertRaises(permissions.PermissionException,
+ self.servlet.AssertBasePermission, mr)
+
+ # Owners can edit the project
+ mr.perms = permissions.OWNER_ACTIVE_PERMISSIONSET
+ self.servlet.AssertBasePermission(mr)
+
+ def testGatherPageData(self):
+ # Project has all default values.
+ page_data = self.servlet.GatherPageData(self.mr)
+ self.assertEqual('a summary', page_data['initial_summary'])
+ self.assertEqual('a description', page_data['initial_description'])
+ self.assertEqual(
+ int(project_pb2.ProjectAccess.ANYONE), page_data['initial_access'].key)
+
+ self.assertFalse(page_data['process_inbound_email'])
+ self.assertFalse(page_data['only_owners_remove_restrictions'])
+ self.assertFalse(page_data['only_owners_see_contributors'])
+
+ # Now try some alternate Project field values.
+ self.project.only_owners_remove_restrictions = True
+ self.project.only_owners_see_contributors = True
+ page_data = self.servlet.GatherPageData(self.mr)
+ self.assertTrue(page_data['only_owners_remove_restrictions'])
+ self.assertTrue(page_data['only_owners_see_contributors'])
+
+ # TODO(jrobbins): many more tests needed.
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « appengine/monorail/project/test/project_views_test.py ('k') | appengine/monorail/project/test/projectadminadvanced_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698