3 # Copyright 2008 Google Inc. All Rights Reserved.
7 import unittest
, os
, sys
10 from autotest_lib
.cli
import cli_mock
, user
13 class user_list_unittest(cli_mock
.cli_unittest
):
14 def test_parse_user_not_required(self
):
17 (options
, leftover
) = ul
.parse()
18 self
.assertEqual([], ul
.users
)
19 self
.assertEqual([], leftover
)
22 def test_parse_with_users(self
):
24 ufile
= cli_mock
.create_file('user0\nuser3\nuser4\n')
25 sys
.argv
= ['atest', 'user1', '--ulist', ufile
.name
, 'user3']
26 (options
, leftover
) = ul
.parse()
27 self
.assertEqualNoOrder(['user0', 'user1','user3', 'user4'],
29 self
.assertEqual(leftover
, [])
33 def test_parse_with_acl(self
):
35 sys
.argv
= ['atest', '--acl', 'acl0']
36 (options
, leftover
) = ul
.parse()
37 self
.assertEqual('acl0', ul
.acl
)
38 self
.assertEqual(leftover
, [])
41 def test_parse_with_access_level(self
):
43 sys
.argv
= ['atest', '--access_level', '3']
44 (options
, leftover
) = ul
.parse()
45 self
.assertEqual('3', ul
.access_level
)
46 self
.assertEqual(leftover
, [])
49 def test_parse_with_all(self
):
51 ufile
= cli_mock
.create_file('user0\nuser3\nuser4\n')
52 sys
.argv
= ['atest', 'user1', '--ulist', ufile
.name
, 'user3',
53 '-l', '4', '-a', 'acl0']
54 (options
, leftover
) = ul
.parse()
55 self
.assertEqualNoOrder(['user0', 'user1','user3', 'user4'],
57 self
.assertEqual('acl0', ul
.acl
)
58 self
.assertEqual('4', ul
.access_level
)
59 self
.assertEqual(leftover
, [])
63 def test_execute_list_all(self
):
64 self
.run_cmd(argv
=['atest', 'user', 'list'],
65 rpcs
=[('get_users', {},
76 out_words_ok
=['user0', 'user5'],
77 out_words_no
=['1', '3', '41', '42'])
80 def test_execute_list_all_with_user(self
):
81 self
.run_cmd(argv
=['atest', 'user', 'list', 'user0'],
82 rpcs
=[('get_users', {'login__in': ['user0']},
87 out_words_ok
=['user0'],
88 out_words_no
=['2', '3'])
91 def test_execute_list_all_with_acl(self
):
92 self
.run_cmd(argv
=['atest', 'user', 'list', '--acl', 'acl0'],
93 rpcs
=[('get_users', {'aclgroup__name__in': ['acl0']},
98 out_words_ok
=['user0'],
99 out_words_no
=['2', '3'])
102 def test_execute_list_all_with_access_level(self
):
103 self
.run_cmd(argv
=['atest', 'user', 'list', '--access_level', '2'],
104 rpcs
=[('get_users', {'access_level__in': ['2']},
106 [{u
'access_level': 2,
109 out_words_ok
=['user0'],
110 out_words_no
=['2', '3'])
113 def test_execute_list_all_verbose(self
):
114 self
.run_cmd(argv
=['atest', 'user', 'list', '--verbose'],
115 rpcs
=[('get_users', {},
117 [{u
'access_level': 0,
126 out_words_ok
=['user0', 'user5', '41', '42', '0', '5'])
129 def test_execute_list_all_with_user_verbose(self
):
130 ufile
= cli_mock
.create_file('user0 user1\n')
131 self
.run_cmd(argv
=['atest', 'user', 'list', '--ulist', ufile
.name
,
133 rpcs
=[('get_users', {'login__in': ['user0', 'user1']},
135 [{u
'access_level': 2,
141 out_words_ok
=['user0', 'user1', '3', '4', '5'])
145 def test_execute_list_all_with_acl_verbose(self
):
146 self
.run_cmd(argv
=['atest', 'user', 'list', '--acl', 'acl0', '-v'],
147 rpcs
=[('get_users', {'aclgroup__name__in': ['acl0']},
149 [{u
'access_level': 2,
152 out_words_ok
=['user0', '3', '2'])
155 def test_execute_list_all_with_access_level_verbose(self
):
156 self
.run_cmd(argv
=['atest', 'user', 'list',
157 '--access_level', '2', '-v'],
158 rpcs
=[('get_users', {'access_level__in': ['2']},
160 [{u
'access_level': 2,
163 out_words_ok
=['user0', '2', '3'])
166 if __name__
== '__main__':