Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | # Copyright 2016 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. |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 4 | |
| 5 | """Unit test for User Group helpers.""" |
| 6 | from __future__ import print_function |
| 7 | from __future__ import division |
| 8 | from __future__ import absolute_import |
| 9 | |
| 10 | import unittest |
| 11 | |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 12 | from mrproto import user_pb2 |
| 13 | from mrproto import usergroup_pb2 |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 14 | from sitewide import group_helpers |
| 15 | |
| 16 | |
| 17 | class GroupHelpersTest(unittest.TestCase): |
| 18 | |
| 19 | def testGroupVisibilityView(self): |
| 20 | gvv_anyone = group_helpers.GroupVisibilityView( |
| 21 | usergroup_pb2.MemberVisibility.ANYONE) |
| 22 | gvv_members = group_helpers.GroupVisibilityView( |
| 23 | usergroup_pb2.MemberVisibility.MEMBERS) |
| 24 | gvv_owners = group_helpers.GroupVisibilityView( |
| 25 | usergroup_pb2.MemberVisibility.OWNERS) |
| 26 | self.assertEqual('Anyone on the Internet', gvv_anyone.name) |
| 27 | self.assertEqual('Group Members', gvv_members.name) |
| 28 | self.assertEqual('Group Owners', gvv_owners.name) |
| 29 | |
| 30 | def testGroupMemberView(self): |
| 31 | user = user_pb2.MakeUser(1, email='test@example.com') |
| 32 | gmv = group_helpers.GroupMemberView(user, 888, 'member') |
| 33 | self.assertEqual(888, gmv.group_id) |
| 34 | self.assertEqual('member', gmv.role) |
| 35 | |
| 36 | def testBuildUserGroupVisibilityOptions(self): |
| 37 | vis_views = group_helpers.BuildUserGroupVisibilityOptions() |
| 38 | self.assertEqual(3, len(vis_views)) |
| 39 | |
| 40 | def testGroupTypeView(self): |
| 41 | gt_cia = group_helpers.GroupTypeView( |
| 42 | usergroup_pb2.GroupType.CHROME_INFRA_AUTH) |
| 43 | gt_mdb = group_helpers.GroupTypeView( |
| 44 | usergroup_pb2.GroupType.MDB) |
| 45 | self.assertEqual('Chrome-infra-auth', gt_cia.name) |
| 46 | self.assertEqual('MDB', gt_mdb.name) |
| 47 | |
| 48 | def testBuildUserGroupTypeOptions(self): |
| 49 | group_types = group_helpers.BuildUserGroupTypeOptions() |
| 50 | self.assertEqual(4, len(group_types)) |