KVM test: usb cdrom support
[autotest-zwu.git] / cli / label_unittest.py
blob817a340e1299492aa22b20ed449dfb087bab84cf
1 #!/usr/bin/python
3 # Copyright 2008 Google Inc. All Rights Reserved.
5 """Tests for label."""
7 import unittest, sys, os
9 import common
10 from autotest_lib.cli import cli_mock, topic_common
13 class label_list_unittest(cli_mock.cli_unittest):
14 values = [{u'id': 180, # Valid label
15 u'platform': False,
16 u'name': u'label0',
17 u'invalid': False,
18 u'kernel_config': u'',
19 u'only_if_needed': False},
20 {u'id': 338, # Valid label
21 u'platform': False,
22 u'name': u'label1',
23 u'invalid': False,
24 u'kernel_config': u'',
25 u'only_if_needed': False},
26 {u'id': 340, # Invalid label
27 u'platform': False,
28 u'name': u'label2',
29 u'invalid': True,
30 u'kernel_config': u'',
31 u'only_if_needed': False},
32 {u'id': 350, # Valid platform
33 u'platform': True,
34 u'name': u'plat0',
35 u'invalid': False,
36 u'kernel_config': u'',
37 u'only_if_needed': False},
38 {u'id': 420, # Invalid platform
39 u'platform': True,
40 u'name': u'plat1',
41 u'invalid': True,
42 u'kernel_config': u'',
43 u'only_if_needed': False}]
46 def test_label_list_labels_only(self):
47 self.run_cmd(argv=['atest', 'label', 'list', '--ignore_site_file'],
48 rpcs=[('get_labels', {}, True, self.values)],
49 out_words_ok=['label0', 'label1', 'label2'],
50 out_words_no=['plat0', 'plat1'])
53 def test_label_list_labels_only_valid(self):
54 self.run_cmd(argv=['atest', 'label', 'list', '-d',
55 '--ignore_site_file'],
56 rpcs=[('get_labels', {}, True, self.values)],
57 out_words_ok=['label0', 'label1'],
58 out_words_no=['label2', 'plat0', 'plat1'])
61 def test_label_list_labels_and_platforms(self):
62 self.run_cmd(argv=['atest', 'label', 'list', '--all',
63 '--ignore_site_file'],
64 rpcs=[('get_labels', {}, True, self.values)],
65 out_words_ok=['label0', 'label1', 'label2',
66 'plat0', 'plat1'])
69 def test_label_list_platforms_only(self):
70 self.run_cmd(argv=['atest', 'label', 'list', '-t',
71 '--ignore_site_file'],
72 rpcs=[('get_labels', {}, True, self.values)],
73 out_words_ok=['plat0', 'plat1'],
74 out_words_no=['label0', 'label1', 'label2'])
77 def test_label_list_platforms_only_valid(self):
78 self.run_cmd(argv=['atest', 'label', 'list',
79 '-t', '--valid-only', '--ignore_site_file'],
80 rpcs=[('get_labels', {}, True, self.values)],
81 out_words_ok=['plat0'],
82 out_words_no=['label0', 'label1', 'label2',
83 'plat1'])
86 class label_create_unittest(cli_mock.cli_unittest):
87 def test_execute_create_two_labels(self):
88 self.run_cmd(argv=['atest', 'label', 'create', 'label0', 'label1',
89 '--ignore_site_file'],
90 rpcs=[('add_label',
91 {'name': 'label0', 'platform': False,
92 'only_if_needed': False},
93 True, 42),
94 ('add_label',
95 {'name': 'label1', 'platform': False,
96 'only_if_needed': False},
97 True, 43)],
98 out_words_ok=['Created', 'label0', 'label1'])
101 def test_execute_create_two_labels_bad(self):
102 self.run_cmd(argv=['atest', 'label', 'create', 'label0', 'label1',
103 '--ignore_site_file'],
104 rpcs=[('add_label',
105 {'name': 'label0', 'platform': False,
106 'only_if_needed': False},
107 True, 3),
108 ('add_label',
109 {'name': 'label1', 'platform': False,
110 'only_if_needed': False},
111 False,
112 '''ValidationError: {'name':
113 'This value must be unique (label0)'}''')],
114 out_words_ok=['Created', 'label0'],
115 out_words_no=['label1'],
116 err_words_ok=['label1', 'ValidationError'])
120 class label_delete_unittest(cli_mock.cli_unittest):
121 def test_execute_delete_labels(self):
122 self.run_cmd(argv=['atest', 'label', 'delete', 'label0', 'label1',
123 '--ignore_site_file'],
124 rpcs=[('delete_label', {'id': 'label0'}, True, None),
125 ('delete_label', {'id': 'label1'}, True, None)],
126 out_words_ok=['Deleted', 'label0', 'label1'])
129 class label_add_unittest(cli_mock.cli_unittest):
130 def test_execute_add_labels_to_hosts(self):
131 self.run_cmd(argv=['atest', 'label', 'add', 'label0',
132 '--machine', 'host0,host1', '--ignore_site_file'],
133 rpcs=[('label_add_hosts', {'id': 'label0',
134 'hosts': ['host1', 'host0']},
135 True, None)],
136 out_words_ok=['Added', 'label0', 'host0', 'host1'])
139 class label_remove_unittest(cli_mock.cli_unittest):
140 def test_execute_remove_labels_from_hosts(self):
141 self.run_cmd(argv=['atest', 'label', 'remove', 'label0',
142 '--machine', 'host0,host1', '--ignore_site_file'],
143 rpcs=[('label_remove_hosts', {'id': 'label0',
144 'hosts': ['host1', 'host0']},
145 True, None)],
146 out_words_ok=['Removed', 'label0', 'host0', 'host1'])
149 if __name__ == '__main__':
150 unittest.main()