blob: 02ecfbd5564872fd7fcc4fcc4c77d7a36186d1ee [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# 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.
Copybara854996b2021-09-07 19:36:02 +00004
5"""Unit test for User Group helpers."""
6from __future__ import print_function
7from __future__ import division
8from __future__ import absolute_import
9
10import unittest
11
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010012from mrproto import user_pb2
13from mrproto import usergroup_pb2
Copybara854996b2021-09-07 19:36:02 +000014from sitewide import group_helpers
15
16
17class 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))