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

Side by Side Diff: appengine/swarming/handlers_endpoints_test.py

Issue 2272193004: Add endpoint for permissions (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@migrate-botlist
Patch Set: Created 4 years, 3 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
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # coding=utf-8 2 # coding=utf-8
3 # Copyright 2015 The LUCI Authors. All rights reserved. 3 # Copyright 2015 The LUCI Authors. All rights reserved.
4 # Use of this source code is governed under the Apache License, Version 2.0 4 # Use of this source code is governed under the Apache License, Version 2.0
5 # that can be found in the LICENSE file. 5 # that can be found in the LICENSE file.
6 6
7 import base64 7 import base64
8 import datetime 8 import datetime
9 import json 9 import json
10 import logging 10 import logging
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 64
65 class ServerApiTest(BaseTest): 65 class ServerApiTest(BaseTest):
66 api_service_cls = handlers_endpoints.SwarmingServerService 66 api_service_cls = handlers_endpoints.SwarmingServerService
67 67
68 def test_details(self): 68 def test_details(self):
69 """Asserts that server_details returns the correct version.""" 69 """Asserts that server_details returns the correct version."""
70 response = self.call_api('details') 70 response = self.call_api('details')
71 self.assertEqual({'server_version': utils.get_app_version()}, response.json) 71 self.assertEqual({'server_version': utils.get_app_version()}, response.json)
72 72
73 def test_public_permissions(self):
74 """Asserts that permissions respond correctly to an unauthed user."""
75 self.set_as_anonymous()
76 response = self.call_api('permissions')
77 expected = {
78 u'can_cancel_task': False,
79 u'can_terminate_bot': False,
80 u'can_delete_bot': False,
81 u'can_get_bot_config_py': False,
82 u'can_get_bootstrap_py': False,
83 u'can_put_bot_config_py': False,
84 u'can_put_bootstrap_py': False,
85 u'can_get_bootstrap_token': False,
86 }
87 self.assertEqual(expected, response.json)
88
89 def test_user_permissions(self):
90 """Asserts that permissions respond correctly to a basic user."""
91 self.set_as_user()
92 response = self.call_api('permissions')
93 expected = {
94 u'can_cancel_task': True,
95 u'can_terminate_bot': False,
96 u'can_delete_bot': False,
97 u'can_get_bot_config_py': True,
98 u'can_get_bootstrap_py': True,
99 u'can_put_bot_config_py': False,
100 u'can_put_bootstrap_py': False,
101 u'can_get_bootstrap_token': False,
102 }
103 self.assertEqual(expected, response.json)
104
105 def test_privileged_user_permissions(self):
106 """Asserts that permissions respond correctly to a privileged user."""
107 self.set_as_privileged_user()
108 response = self.call_api('permissions')
109 expected = {
110 u'can_cancel_task': True,
111 u'can_terminate_bot': True,
112 u'can_delete_bot': False,
113 u'can_get_bot_config_py': True,
114 u'can_get_bootstrap_py': True,
115 u'can_put_bot_config_py': False,
116 u'can_put_bootstrap_py': False,
117 u'can_get_bootstrap_token': False,
118 }
119 self.assertEqual(expected, response.json)
120
121 def test_admin_permissions(self):
122 """Asserts that permissions respond correctly to an admin."""
123 self.set_as_admin()
124 response = self.call_api('permissions')
125 expected = {
126 u'can_cancel_task': True,
127 u'can_terminate_bot': True,
128 u'can_delete_bot': True,
129 u'can_get_bot_config_py': True,
130 u'can_get_bootstrap_py': True,
131 u'can_put_bot_config_py': True,
132 u'can_put_bootstrap_py': True,
133 u'can_get_bootstrap_token': True,
134 }
135 self.assertEqual(expected, response.json)
136
73 def _test_file(self, name): 137 def _test_file(self, name):
74 self.set_as_admin() 138 self.set_as_admin()
75 139
76 now = datetime.datetime(2010, 1, 2, 3, 4, 5) 140 now = datetime.datetime(2010, 1, 2, 3, 4, 5)
77 self.mock_now(now) 141 self.mock_now(now)
78 path = os.path.join(self.APP_DIR, 'swarming_bot', 'config', name + '.py') 142 path = os.path.join(self.APP_DIR, 'swarming_bot', 'config', name + '.py')
79 with open(path, 'rb') as f: 143 with open(path, 'rb') as f:
80 content = f.read().decode('utf-8') 144 content = f.read().decode('utf-8')
81 145
82 expected = { 146 expected = {
(...skipping 1834 matching lines...) Expand 10 before | Expand all | Expand 10 after
1917 self.assertEqual(expected, response.json) 1981 self.assertEqual(expected, response.json)
1918 1982
1919 1983
1920 if __name__ == '__main__': 1984 if __name__ == '__main__':
1921 if '-v' in sys.argv: 1985 if '-v' in sys.argv:
1922 unittest.TestCase.maxDiff = None 1986 unittest.TestCase.maxDiff = None
1923 logging.basicConfig(level=logging.DEBUG) 1987 logging.basicConfig(level=logging.DEBUG)
1924 else: 1988 else:
1925 logging.basicConfig(level=logging.CRITICAL) 1989 logging.basicConfig(level=logging.CRITICAL)
1926 unittest.main() 1990 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698