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

Side by Side Diff: appengine/monorail/project/test/projectadmin_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 unified diff | Download patch
OLDNEW
(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 projectadmin module."""
7
8 import unittest
9
10 from framework import permissions
11 from project import projectadmin
12 from proto import project_pb2
13 from services import service_manager
14 from testing import fake
15 from testing import testing_helpers
16
17
18 class ProjectAdminTest(unittest.TestCase):
19 """Unit tests for the ProjectAdmin servlet class."""
20
21 def setUp(self):
22 services = service_manager.Services(
23 project=fake.ProjectService(),
24 user=fake.UserService())
25 self.servlet = projectadmin.ProjectAdmin('req', 'res', services=services)
26 self.project = services.project.TestAddProject(
27 'proj', summary='a summary', description='a description')
28 self.request, self.mr = testing_helpers.GetRequestObjects(
29 project=self.project)
30
31 def testAssertBasePermission(self):
32 # Contributors cannot edit the project
33 mr = testing_helpers.MakeMonorailRequest(
34 project=self.project,
35 perms=permissions.CONTRIBUTOR_ACTIVE_PERMISSIONSET)
36 self.assertRaises(permissions.PermissionException,
37 self.servlet.AssertBasePermission, mr)
38
39 # Signed-out users cannot edit the project
40 mr.perms = permissions.READ_ONLY_PERMISSIONSET
41 self.assertRaises(permissions.PermissionException,
42 self.servlet.AssertBasePermission, mr)
43
44 # Non-member users cannot edit the project
45 mr.perms = permissions.USER_PERMISSIONSET
46 self.assertRaises(permissions.PermissionException,
47 self.servlet.AssertBasePermission, mr)
48
49 # Owners can edit the project
50 mr.perms = permissions.OWNER_ACTIVE_PERMISSIONSET
51 self.servlet.AssertBasePermission(mr)
52
53 def testGatherPageData(self):
54 # Project has all default values.
55 page_data = self.servlet.GatherPageData(self.mr)
56 self.assertEqual('a summary', page_data['initial_summary'])
57 self.assertEqual('a description', page_data['initial_description'])
58 self.assertEqual(
59 int(project_pb2.ProjectAccess.ANYONE), page_data['initial_access'].key)
60
61 self.assertFalse(page_data['process_inbound_email'])
62 self.assertFalse(page_data['only_owners_remove_restrictions'])
63 self.assertFalse(page_data['only_owners_see_contributors'])
64
65 # Now try some alternate Project field values.
66 self.project.only_owners_remove_restrictions = True
67 self.project.only_owners_see_contributors = True
68 page_data = self.servlet.GatherPageData(self.mr)
69 self.assertTrue(page_data['only_owners_remove_restrictions'])
70 self.assertTrue(page_data['only_owners_see_contributors'])
71
72 # TODO(jrobbins): many more tests needed.
73
74
75 if __name__ == '__main__':
76 unittest.main()
OLDNEW
« no previous file with comments | « appengine/monorail/project/test/project_views_test.py ('k') | appengine/monorail/project/test/projectadminadvanced_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698