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