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

Unified Diff: appengine/monorail/sitewide/test/projectcreate_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/sitewide/test/projectcreate_test.py
diff --git a/appengine/monorail/sitewide/test/projectcreate_test.py b/appengine/monorail/sitewide/test/projectcreate_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..f4a4f9ca773f0878e348034efc7bd07a5b720d92
--- /dev/null
+++ b/appengine/monorail/sitewide/test/projectcreate_test.py
@@ -0,0 +1,123 @@
+# 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
+
+"""Unittests for the Project Creation servlet."""
+
+import unittest
+
+import settings
+from framework import permissions
+from proto import project_pb2
+from proto import site_pb2
+from services import service_manager
+from sitewide import projectcreate
+from testing import fake
+from testing import testing_helpers
+
+
+class ProjectCreateTest(unittest.TestCase):
+
+ def setUp(self):
+ services = service_manager.Services()
+ self.servlet = projectcreate.ProjectCreate('req', 'res', services=services)
+
+ def CheckAssertBasePermissions(
+ self, restriction, expect_admin_ok, expect_nonadmin_ok):
+ old_project_creation_restriction = settings.project_creation_restriction
+ settings.project_creation_restriction = restriction
+
+ # Anon users can never do it
+ mr = testing_helpers.MakeMonorailRequest(
+ perms=permissions.GetPermissions(None, {}, None))
+ self.assertRaises(
+ permissions.PermissionException,
+ self.servlet.AssertBasePermission, mr)
+
+ mr = testing_helpers.MakeMonorailRequest()
+ if expect_admin_ok:
+ self.servlet.AssertBasePermission(mr)
+ else:
+ self.assertRaises(
+ permissions.PermissionException,
+ self.servlet.AssertBasePermission, mr)
+
+ mr = testing_helpers.MakeMonorailRequest(
+ perms=permissions.GetPermissions(mr.auth.user_pb, {111L}, None))
+ if expect_nonadmin_ok:
+ self.servlet.AssertBasePermission(mr)
+ else:
+ self.assertRaises(
+ permissions.PermissionException,
+ self.servlet.AssertBasePermission, mr)
+
+ settings.project_creation_restriction = old_project_creation_restriction
+
+ def testAssertBasePermission(self):
+ self.CheckAssertBasePermissions(
+ site_pb2.UserTypeRestriction.ANYONE, True, True)
+ self.CheckAssertBasePermissions(
+ site_pb2.UserTypeRestriction.ADMIN_ONLY, True, False)
+ self.CheckAssertBasePermissions(
+ site_pb2.UserTypeRestriction.NO_ONE, False, False)
+
+ def testGatherPageData(self):
+ mr = testing_helpers.MakeMonorailRequest()
+ page_data = self.servlet.GatherPageData(mr)
+ self.assertEqual('', page_data['initial_name'])
+ self.assertEqual('', page_data['initial_summary'])
+ self.assertEqual('', page_data['initial_description'])
+ self.assertEqual([], page_data['labels'])
+
+ def testGatherHelpData(self):
+ project = project_pb2.Project()
+ mr = testing_helpers.MakeMonorailRequest(project=project)
+
+ # Users not near the lifetime limit see no cue card.
+ help_data = self.servlet.GatherHelpData(mr, {})
+ self.assertEqual(None, help_data['cue_remaining_projects'])
+
+ # User who is near the lifetime limit will see a cue card.
+ mr.auth.user_pb.project_creation_limit.lifetime_count = 20
+ help_data = self.servlet.GatherHelpData(mr, {})
+ self.assertEqual(5, help_data['cue_remaining_projects'])
+
+ # User far under custom lifetime limit won't see a cue card.
+ mr.auth.user_pb.project_creation_limit.lifetime_limit = 100
+ mr.auth.user_pb.project_creation_limit.lifetime_count = 20
+ help_data = self.servlet.GatherHelpData(mr, {})
+ self.assertEqual(None, help_data['cue_remaining_projects'])
+
+ # User near custom lifetime limit will see a cue card.
+ mr.auth.user_pb.project_creation_limit.lifetime_limit = 100
+ mr.auth.user_pb.project_creation_limit.lifetime_count = 91
+ help_data = self.servlet.GatherHelpData(mr, {})
+ self.assertEqual(9, help_data['cue_remaining_projects'])
+
+
+class CheckProjectNameJSONTest(unittest.TestCase):
+ def setUp(self):
+ services = service_manager.Services(project=fake.ProjectService())
+ self.project = services.project.TestAddProject('proj')
+ self.servlet = projectcreate.CheckProjectNameJSON(
+ 'req', 'res', services=services)
+
+ def testHandleRequestNameTaken(self):
+ mr = testing_helpers.MakeMonorailRequest(
+ project=self.project, user_info={'user_id': 222L}, method='POST',
+ params={'project': self.project.project_name})
+ json_data = self.servlet.HandleRequest(mr)
+ self.assertEqual('That project name is not available.',
+ json_data['error_message'])
+
+ def testHandleRequestNameNotTaken(self):
+ mr = testing_helpers.MakeMonorailRequest(
+ project=self.project, user_info={'user_id': 222L}, method='POST',
+ params={'project': 'not-taken'})
+ json_data = self.servlet.HandleRequest(mr)
+ self.assertEqual('', json_data['error_message'])
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « appengine/monorail/sitewide/test/moved_test.py ('k') | appengine/monorail/sitewide/test/projectsearch_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698