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