Index: appengine/monorail/project/test/projectadminadvanced_test.py |
diff --git a/appengine/monorail/project/test/projectadminadvanced_test.py b/appengine/monorail/project/test/projectadminadvanced_test.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fa38a89c25a76aa9b4658a1ccfe9749292a809e9 |
--- /dev/null |
+++ b/appengine/monorail/project/test/projectadminadvanced_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 |
+ |
+"""Unit tests for projectadminadvanced module.""" |
+ |
+import time |
+import unittest |
+ |
+from framework import permissions |
+from project import projectadminadvanced |
+from proto import project_pb2 |
+from services import service_manager |
+from testing import fake |
+from testing import testing_helpers |
+ |
+ |
+class ProjectAdminAdvancedTest(unittest.TestCase): |
+ """Unit tests for the ProjectAdminAdvanced servlet class.""" |
+ |
+ def setUp(self): |
+ services = service_manager.Services( |
+ project=fake.ProjectService()) |
+ self.servlet = projectadminadvanced.ProjectAdminAdvanced( |
+ 'req', 'res', services=services) |
+ self.project = services.project.TestAddProject('proj') |
+ self.mr = testing_helpers.MakeMonorailRequest( |
+ project=self.project, perms=permissions.OWNER_ACTIVE_PERMISSIONSET) |
+ |
+ def testAssertBasePermission(self): |
+ # Signed-out users cannot edit the project |
+ self.mr.perms = permissions.READ_ONLY_PERMISSIONSET |
+ self.assertRaises(permissions.PermissionException, |
+ self.servlet.AssertBasePermission, self.mr) |
+ |
+ # Non-member users cannot edit the project |
+ self.mr.perms = permissions.USER_PERMISSIONSET |
+ self.assertRaises(permissions.PermissionException, |
+ self.servlet.AssertBasePermission, self.mr) |
+ |
+ # Contributors cannot edit the project |
+ self.mr.perms = permissions.CONTRIBUTOR_ACTIVE_PERMISSIONSET |
+ self.assertRaises( |
+ permissions.PermissionException, |
+ self.servlet.AssertBasePermission, self.mr) |
+ |
+ self.mr.perms = permissions.OWNER_ACTIVE_PERMISSIONSET |
+ self.servlet.AssertBasePermission(self.mr) |
+ |
+ def testGatherPageData(self): |
+ page_data = self.servlet.GatherPageData(self.mr) |
+ self.assertEqual(self.servlet.ADMIN_TAB_ADVANCED, |
+ page_data['admin_tab_mode']) |
+ |
+ def testGatherPublishingOptions_Live(self): |
+ pub_data = self.servlet._GatherPublishingOptions(self.mr) |
+ self.assertTrue(pub_data['offer_archive']) |
+ self.assertTrue(pub_data['offer_move']) |
+ self.assertFalse(pub_data['offer_publish']) |
+ self.assertFalse(pub_data['offer_delete']) |
+ self.assertEqual('http://', pub_data['moved_to']) |
+ |
+ def testGatherPublishingOptions_Moved(self): |
+ self.project.moved_to = 'other location' |
+ pub_data = self.servlet._GatherPublishingOptions(self.mr) |
+ self.assertTrue(pub_data['offer_archive']) |
+ self.assertTrue(pub_data['offer_move']) |
+ self.assertFalse(pub_data['offer_publish']) |
+ self.assertFalse(pub_data['offer_delete']) |
+ self.assertEqual('other location', pub_data['moved_to']) |
+ |
+ def testGatherPublishingOptions_Archived(self): |
+ self.project.state = project_pb2.ProjectState.ARCHIVED |
+ pub_data = self.servlet._GatherPublishingOptions(self.mr) |
+ self.assertFalse(pub_data['offer_archive']) |
+ self.assertFalse(pub_data['offer_move']) |
+ self.assertTrue(pub_data['offer_publish']) |
+ self.assertTrue(pub_data['offer_delete']) |
+ |
+ def testGatherPublishingOptions_Doomed(self): |
+ self.project.state = project_pb2.ProjectState.ARCHIVED |
+ self.project.state_reason = 'you are a spammer' |
+ pub_data = self.servlet._GatherPublishingOptions(self.mr) |
+ self.assertFalse(pub_data['offer_archive']) |
+ self.assertFalse(pub_data['offer_move']) |
+ self.assertFalse(pub_data['offer_publish']) |
+ self.assertTrue(pub_data['offer_delete']) |
+ |
+ def testGatherQuotaData(self): |
+ self.mr.perms = permissions.OWNER_ACTIVE_PERMISSIONSET |
+ quota_data = self.servlet._GatherQuotaData(self.mr) |
+ self.assertFalse(quota_data['offer_quota_editing']) |
+ |
+ self.mr.perms = permissions.ADMIN_PERMISSIONSET |
+ quota_data = self.servlet._GatherQuotaData(self.mr) |
+ self.assertTrue(quota_data['offer_quota_editing']) |
+ |
+ def testBuildComponentQuota(self): |
+ ezt_item = self.servlet._BuildComponentQuota( |
+ 5000, 10000, 'attachments') |
+ self.assertEqual(50, ezt_item.used_percent) |
+ self.assertEqual('attachments', ezt_item.field_name) |
+ |
+ def testProcessFormData_NotDeleted(self): |
+ self.mr.project_name = 'proj' |
+ post_data = fake.PostData() |
+ next_url = self.servlet.ProcessFormData(self.mr, post_data) |
+ now = int(time.time()) |
+ self.assertEqual( |
+ 'http://127.0.0.1/p/proj/adminAdvanced?saved=1&ts=%s' % now, |
+ next_url) |
+ |
+ def testProcessFormData_AfterDeletion(self): |
+ self.mr.project_name = 'proj' |
+ self.project.state = project_pb2.ProjectState.ARCHIVED |
+ post_data = fake.PostData(deletebtn='1') |
+ next_url = self.servlet.ProcessFormData(self.mr, post_data) |
+ self.assertEqual('http://127.0.0.1/hosting/', next_url) |
+ |
+ |
+if __name__ == '__main__': |
+ unittest.main() |