Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | # 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 | |
| 6 | from __future__ import print_function |
| 7 | from __future__ import division |
| 8 | from __future__ import absolute_import |
| 9 | |
| 10 | import unittest |
| 11 | |
| 12 | from api.v3 import permission_converters as pc |
| 13 | from api.v3.api_proto import permission_objects_pb2 |
| 14 | from framework import exceptions |
| 15 | from framework import permissions |
| 16 | |
| 17 | |
| 18 | class 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']) |