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 """Unit tests for projectadminadvanced module.""" |
| 7 |
| 8 import time |
| 9 import unittest |
| 10 |
| 11 from framework import permissions |
| 12 from project import projectadminadvanced |
| 13 from proto import project_pb2 |
| 14 from services import service_manager |
| 15 from testing import fake |
| 16 from testing import testing_helpers |
| 17 |
| 18 |
| 19 class ProjectAdminAdvancedTest(unittest.TestCase): |
| 20 """Unit tests for the ProjectAdminAdvanced servlet class.""" |
| 21 |
| 22 def setUp(self): |
| 23 services = service_manager.Services( |
| 24 project=fake.ProjectService()) |
| 25 self.servlet = projectadminadvanced.ProjectAdminAdvanced( |
| 26 'req', 'res', services=services) |
| 27 self.project = services.project.TestAddProject('proj') |
| 28 self.mr = testing_helpers.MakeMonorailRequest( |
| 29 project=self.project, perms=permissions.OWNER_ACTIVE_PERMISSIONSET) |
| 30 |
| 31 def testAssertBasePermission(self): |
| 32 # Signed-out users cannot edit the project |
| 33 self.mr.perms = permissions.READ_ONLY_PERMISSIONSET |
| 34 self.assertRaises(permissions.PermissionException, |
| 35 self.servlet.AssertBasePermission, self.mr) |
| 36 |
| 37 # Non-member users cannot edit the project |
| 38 self.mr.perms = permissions.USER_PERMISSIONSET |
| 39 self.assertRaises(permissions.PermissionException, |
| 40 self.servlet.AssertBasePermission, self.mr) |
| 41 |
| 42 # Contributors cannot edit the project |
| 43 self.mr.perms = permissions.CONTRIBUTOR_ACTIVE_PERMISSIONSET |
| 44 self.assertRaises( |
| 45 permissions.PermissionException, |
| 46 self.servlet.AssertBasePermission, self.mr) |
| 47 |
| 48 self.mr.perms = permissions.OWNER_ACTIVE_PERMISSIONSET |
| 49 self.servlet.AssertBasePermission(self.mr) |
| 50 |
| 51 def testGatherPageData(self): |
| 52 page_data = self.servlet.GatherPageData(self.mr) |
| 53 self.assertEqual(self.servlet.ADMIN_TAB_ADVANCED, |
| 54 page_data['admin_tab_mode']) |
| 55 |
| 56 def testGatherPublishingOptions_Live(self): |
| 57 pub_data = self.servlet._GatherPublishingOptions(self.mr) |
| 58 self.assertTrue(pub_data['offer_archive']) |
| 59 self.assertTrue(pub_data['offer_move']) |
| 60 self.assertFalse(pub_data['offer_publish']) |
| 61 self.assertFalse(pub_data['offer_delete']) |
| 62 self.assertEqual('http://', pub_data['moved_to']) |
| 63 |
| 64 def testGatherPublishingOptions_Moved(self): |
| 65 self.project.moved_to = 'other location' |
| 66 pub_data = self.servlet._GatherPublishingOptions(self.mr) |
| 67 self.assertTrue(pub_data['offer_archive']) |
| 68 self.assertTrue(pub_data['offer_move']) |
| 69 self.assertFalse(pub_data['offer_publish']) |
| 70 self.assertFalse(pub_data['offer_delete']) |
| 71 self.assertEqual('other location', pub_data['moved_to']) |
| 72 |
| 73 def testGatherPublishingOptions_Archived(self): |
| 74 self.project.state = project_pb2.ProjectState.ARCHIVED |
| 75 pub_data = self.servlet._GatherPublishingOptions(self.mr) |
| 76 self.assertFalse(pub_data['offer_archive']) |
| 77 self.assertFalse(pub_data['offer_move']) |
| 78 self.assertTrue(pub_data['offer_publish']) |
| 79 self.assertTrue(pub_data['offer_delete']) |
| 80 |
| 81 def testGatherPublishingOptions_Doomed(self): |
| 82 self.project.state = project_pb2.ProjectState.ARCHIVED |
| 83 self.project.state_reason = 'you are a spammer' |
| 84 pub_data = self.servlet._GatherPublishingOptions(self.mr) |
| 85 self.assertFalse(pub_data['offer_archive']) |
| 86 self.assertFalse(pub_data['offer_move']) |
| 87 self.assertFalse(pub_data['offer_publish']) |
| 88 self.assertTrue(pub_data['offer_delete']) |
| 89 |
| 90 def testGatherQuotaData(self): |
| 91 self.mr.perms = permissions.OWNER_ACTIVE_PERMISSIONSET |
| 92 quota_data = self.servlet._GatherQuotaData(self.mr) |
| 93 self.assertFalse(quota_data['offer_quota_editing']) |
| 94 |
| 95 self.mr.perms = permissions.ADMIN_PERMISSIONSET |
| 96 quota_data = self.servlet._GatherQuotaData(self.mr) |
| 97 self.assertTrue(quota_data['offer_quota_editing']) |
| 98 |
| 99 def testBuildComponentQuota(self): |
| 100 ezt_item = self.servlet._BuildComponentQuota( |
| 101 5000, 10000, 'attachments') |
| 102 self.assertEqual(50, ezt_item.used_percent) |
| 103 self.assertEqual('attachments', ezt_item.field_name) |
| 104 |
| 105 def testProcessFormData_NotDeleted(self): |
| 106 self.mr.project_name = 'proj' |
| 107 post_data = fake.PostData() |
| 108 next_url = self.servlet.ProcessFormData(self.mr, post_data) |
| 109 now = int(time.time()) |
| 110 self.assertEqual( |
| 111 'http://127.0.0.1/p/proj/adminAdvanced?saved=1&ts=%s' % now, |
| 112 next_url) |
| 113 |
| 114 def testProcessFormData_AfterDeletion(self): |
| 115 self.mr.project_name = 'proj' |
| 116 self.project.state = project_pb2.ProjectState.ARCHIVED |
| 117 post_data = fake.PostData(deletebtn='1') |
| 118 next_url = self.servlet.ProcessFormData(self.mr, post_data) |
| 119 self.assertEqual('http://127.0.0.1/hosting/', next_url) |
| 120 |
| 121 |
| 122 if __name__ == '__main__': |
| 123 unittest.main() |
OLD | NEW |