blob: 0257cd08de7db2e48ac0a2ed1565bba656c73a19 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001# Copyright 2016 The Chromium Authors. All rights reserved.
2# Use of this source code is governed 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 projectadmin module."""
7from __future__ import print_function
8from __future__ import division
9from __future__ import absolute_import
10
11import unittest
12
13from framework import permissions
14from project import projectadmin
15from proto import project_pb2
16from services import service_manager
17from testing import fake
18from testing import testing_helpers
19
20
21class ProjectAdminTest(unittest.TestCase):
22 """Unit tests for the ProjectAdmin servlet class."""
23
24 def setUp(self):
25 services = service_manager.Services(
26 project=fake.ProjectService(),
27 user=fake.UserService())
28 self.servlet = projectadmin.ProjectAdmin('req', 'res', services=services)
29 self.project = services.project.TestAddProject(
30 'proj', summary='a summary', description='a description')
31 self.request, self.mr = testing_helpers.GetRequestObjects(
32 project=self.project)
33
34 def testAssertBasePermission(self):
35 # Contributors cannot edit the project
36 mr = testing_helpers.MakeMonorailRequest(
37 project=self.project,
38 perms=permissions.CONTRIBUTOR_ACTIVE_PERMISSIONSET)
39 self.assertRaises(permissions.PermissionException,
40 self.servlet.AssertBasePermission, mr)
41
42 # Signed-out users cannot edit the project
43 mr.perms = permissions.READ_ONLY_PERMISSIONSET
44 self.assertRaises(permissions.PermissionException,
45 self.servlet.AssertBasePermission, mr)
46
47 # Non-member users cannot edit the project
48 mr.perms = permissions.USER_PERMISSIONSET
49 self.assertRaises(permissions.PermissionException,
50 self.servlet.AssertBasePermission, mr)
51
52 # Owners can edit the project
53 mr.perms = permissions.OWNER_ACTIVE_PERMISSIONSET
54 self.servlet.AssertBasePermission(mr)
55
56 def testGatherPageData(self):
57 # Project has all default values.
58 page_data = self.servlet.GatherPageData(self.mr)
59 self.assertEqual('a summary', page_data['initial_summary'])
60 self.assertEqual('a description', page_data['initial_description'])
61 self.assertEqual(
62 int(project_pb2.ProjectAccess.ANYONE), page_data['initial_access'].key)
63
64 self.assertFalse(page_data['process_inbound_email'])
65 self.assertFalse(page_data['only_owners_remove_restrictions'])
66 self.assertFalse(page_data['only_owners_see_contributors'])
67 self.assertFalse(page_data['issue_notify_always_detailed'])
68
69 # Now try some alternate Project field values.
70 self.project.only_owners_remove_restrictions = True
71 self.project.only_owners_see_contributors = True
72 self.project.issue_notify_always_detailed = True
73 page_data = self.servlet.GatherPageData(self.mr)
74 self.assertTrue(page_data['only_owners_remove_restrictions'])
75 self.assertTrue(page_data['only_owners_see_contributors'])
76 self.assertTrue(page_data['issue_notify_always_detailed'])
77
78 # TODO(jrobbins): many more tests needed.