blob: 5e05b4c5129d6cc3b4d36bc4ec32cfc2ae9d3dc5 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# Copyright 2020 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"""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'])