forked from yochow/autotest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_unittest.py
executable file
·167 lines (136 loc) · 6.21 KB
/
user_unittest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/python
#
# Copyright 2008 Google Inc. All Rights Reserved.
"""Test for user."""
import unittest, os, sys
import common
from autotest_lib.cli import cli_mock, user
class user_list_unittest(cli_mock.cli_unittest):
def test_parse_user_not_required(self):
ul = user.user_list()
sys.argv = ['atest']
(options, leftover) = ul.parse()
self.assertEqual([], ul.users)
self.assertEqual([], leftover)
def test_parse_with_users(self):
ul = user.user_list()
ufile = cli_mock.create_file('user0\nuser3\nuser4\n')
sys.argv = ['atest', 'user1', '--ulist', ufile.name, 'user3']
(options, leftover) = ul.parse()
self.assertEqualNoOrder(['user0', 'user1','user3', 'user4'],
ul.users)
self.assertEqual(leftover, [])
ufile.clean()
def test_parse_with_acl(self):
ul = user.user_list()
sys.argv = ['atest', '--acl', 'acl0']
(options, leftover) = ul.parse()
self.assertEqual('acl0', ul.acl)
self.assertEqual(leftover, [])
def test_parse_with_access_level(self):
ul = user.user_list()
sys.argv = ['atest', '--access_level', '3']
(options, leftover) = ul.parse()
self.assertEqual('3', ul.access_level)
self.assertEqual(leftover, [])
def test_parse_with_all(self):
ul = user.user_list()
ufile = cli_mock.create_file('user0\nuser3\nuser4\n')
sys.argv = ['atest', 'user1', '--ulist', ufile.name, 'user3',
'-l', '4', '-a', 'acl0']
(options, leftover) = ul.parse()
self.assertEqualNoOrder(['user0', 'user1','user3', 'user4'],
ul.users)
self.assertEqual('acl0', ul.acl)
self.assertEqual('4', ul.access_level)
self.assertEqual(leftover, [])
ufile.clean()
def test_execute_list_all(self):
self.run_cmd(argv=['atest', 'user', 'list'],
rpcs=[('get_users', {},
True,
[{u'access_level': 0,
u'login': u'user0',
u'id': 41},
{u'access_level': 0,
u'login': u'user5',
u'id': 42},
{u'access_level': 2,
u'login': u'user0',
u'id': 3}])],
out_words_ok=['user0', 'user5'],
out_words_no=['1', '3', '41', '42'])
def test_execute_list_all_with_user(self):
self.run_cmd(argv=['atest', 'user', 'list', 'user0'],
rpcs=[('get_users', {'login__in': ['user0']},
True,
[{u'access_level': 2,
u'login': u'user0',
u'id': 3}])],
out_words_ok=['user0'],
out_words_no=['2', '3'])
def test_execute_list_all_with_acl(self):
self.run_cmd(argv=['atest', 'user', 'list', '--acl', 'acl0'],
rpcs=[('get_users', {'aclgroup__name__in': ['acl0']},
True,
[{u'access_level': 2,
u'login': u'user0',
u'id': 3}])],
out_words_ok=['user0'],
out_words_no=['2', '3'])
def test_execute_list_all_with_access_level(self):
self.run_cmd(argv=['atest', 'user', 'list', '--access_level', '2'],
rpcs=[('get_users', {'access_level__in': ['2']},
True,
[{u'access_level': 2,
u'login': u'user0',
u'id': 3}])],
out_words_ok=['user0'],
out_words_no=['2', '3'])
def test_execute_list_all_verbose(self):
self.run_cmd(argv=['atest', 'user', 'list', '--verbose'],
rpcs=[('get_users', {},
True,
[{u'access_level': 0,
u'login': u'user0',
u'id': 41},
{u'access_level': 0,
u'login': u'user5',
u'id': 42},
{u'access_level': 5,
u'login': u'user0',
u'id': 3}])],
out_words_ok=['user0', 'user5', '41', '42', '0', '5'])
def test_execute_list_all_with_user_verbose(self):
ufile = cli_mock.create_file('user0 user1\n')
self.run_cmd(argv=['atest', 'user', 'list', '--ulist', ufile.name,
'-v'],
rpcs=[('get_users', {'login__in': ['user0', 'user1']},
True,
[{u'access_level': 2,
u'login': u'user0',
u'id': 3},
{u'access_level': 5,
u'login': u'user1',
u'id': 4}])],
out_words_ok=['user0', 'user1', '3', '4', '5'])
ufile.clean()
def test_execute_list_all_with_acl_verbose(self):
self.run_cmd(argv=['atest', 'user', 'list', '--acl', 'acl0', '-v'],
rpcs=[('get_users', {'aclgroup__name__in': ['acl0']},
True,
[{u'access_level': 2,
u'login': u'user0',
u'id': 3}])],
out_words_ok=['user0', '3', '2'])
def test_execute_list_all_with_access_level_verbose(self):
self.run_cmd(argv=['atest', 'user', 'list',
'--access_level', '2', '-v'],
rpcs=[('get_users', {'access_level__in': ['2']},
True,
[{u'access_level': 2,
u'login': u'user0',
u'id': 3}])],
out_words_ok=['user0', '2', '3'])
if __name__ == '__main__':
unittest.main()