blob: e679eb6b65ba1e91c85a22fffc48f2d1806b20d1 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001# Copyright 2020 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.
4"""Tests for converting permission strings to API permissions enums."""
5
6from __future__ import print_function
7from __future__ import division
8from __future__ import absolute_import
9
10import unittest
11
12from api.v3 import permission_converters as pc
13from api.v3.api_proto import permission_objects_pb2
14from framework import exceptions
15from framework import permissions
16
17
18class ConverterFunctionsTest(unittest.TestCase):
19
20 def testConvertHotlistPermissions(self):
21 api_perms = pc.ConvertHotlistPermissions(
22 [permissions.ADMINISTER_HOTLIST, permissions.EDIT_HOTLIST])
23 expected_perms = [
24 permission_objects_pb2.Permission.Value('HOTLIST_ADMINISTER'),
25 permission_objects_pb2.Permission.Value('HOTLIST_EDIT')
26 ]
27 self.assertEqual(api_perms, expected_perms)
28
29 def testConvertHotlistPermissions_InvalidPermission(self):
30 with self.assertRaises(exceptions.InputException):
31 pc.ConvertHotlistPermissions(['EatHotlist'])
32
33 def testConvertFieldDefPermissions(self):
34 api_perms = pc.ConvertFieldDefPermissions(
35 [permissions.EDIT_FIELD_DEF_VALUE, permissions.EDIT_FIELD_DEF])
36 expected_perms = [
37 permission_objects_pb2.Permission.Value('FIELD_DEF_VALUE_EDIT'),
38 permission_objects_pb2.Permission.Value('FIELD_DEF_EDIT')
39 ]
40 self.assertEqual(api_perms, expected_perms)
41
42 def testConvertFieldDefPermissions_InvalidPermission(self):
43 with self.assertRaises(exceptions.InputException):
44 pc.ConvertFieldDefPermissions(['EatFieldDef'])