root / test / ganeti.cli_unittest.py @ 5d8d232c
History | View | Annotate | Download (2.2 kB)
1 | 2241e2b9 | Iustin Pop | #!/usr/bin/python
|
---|---|---|---|
2 | 2241e2b9 | Iustin Pop | #
|
3 | 2241e2b9 | Iustin Pop | |
4 | 2241e2b9 | Iustin Pop | # Copyright (C) 2008 Google Inc.
|
5 | 2241e2b9 | Iustin Pop | #
|
6 | 2241e2b9 | Iustin Pop | # This program is free software; you can redistribute it and/or modify
|
7 | 2241e2b9 | Iustin Pop | # it under the terms of the GNU General Public License as published by
|
8 | 2241e2b9 | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or
|
9 | 2241e2b9 | Iustin Pop | # (at your option) any later version.
|
10 | 2241e2b9 | Iustin Pop | #
|
11 | 2241e2b9 | Iustin Pop | # This program is distributed in the hope that it will be useful, but
|
12 | 2241e2b9 | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 2241e2b9 | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 2241e2b9 | Iustin Pop | # General Public License for more details.
|
15 | 2241e2b9 | Iustin Pop | #
|
16 | 2241e2b9 | Iustin Pop | # You should have received a copy of the GNU General Public License
|
17 | 2241e2b9 | Iustin Pop | # along with this program; if not, write to the Free Software
|
18 | 2241e2b9 | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 2241e2b9 | Iustin Pop | # 02110-1301, USA.
|
20 | 2241e2b9 | Iustin Pop | |
21 | 2241e2b9 | Iustin Pop | |
22 | 2241e2b9 | Iustin Pop | """Script for unittesting the cli module"""
|
23 | 2241e2b9 | Iustin Pop | |
24 | 2241e2b9 | Iustin Pop | import unittest |
25 | 2241e2b9 | Iustin Pop | |
26 | 2241e2b9 | Iustin Pop | import ganeti |
27 | 2241e2b9 | Iustin Pop | import testutils |
28 | 2241e2b9 | Iustin Pop | from ganeti import constants |
29 | 2241e2b9 | Iustin Pop | from ganeti import cli |
30 | a8469393 | Iustin Pop | from ganeti.errors import OpPrereqError, ParameterError |
31 | 2241e2b9 | Iustin Pop | |
32 | 2241e2b9 | Iustin Pop | class TestParseTimespec(unittest.TestCase): |
33 | 2241e2b9 | Iustin Pop | """Testing case for ParseTimespec"""
|
34 | 2241e2b9 | Iustin Pop | |
35 | 2241e2b9 | Iustin Pop | def testValidTimes(self): |
36 | 2241e2b9 | Iustin Pop | """Test valid timespecs"""
|
37 | 2241e2b9 | Iustin Pop | test_data = [ |
38 | 2241e2b9 | Iustin Pop | ('1s', 1), |
39 | 2241e2b9 | Iustin Pop | ('1', 1), |
40 | 2241e2b9 | Iustin Pop | ('1m', 60), |
41 | 2241e2b9 | Iustin Pop | ('1h', 60 * 60), |
42 | 2241e2b9 | Iustin Pop | ('1d', 60 * 60 * 24), |
43 | 2241e2b9 | Iustin Pop | ('1w', 60 * 60 * 24 * 7), |
44 | 2241e2b9 | Iustin Pop | ('4h', 4 * 60 * 60), |
45 | 2241e2b9 | Iustin Pop | ('61m', 61 * 60), |
46 | 2241e2b9 | Iustin Pop | ] |
47 | 2241e2b9 | Iustin Pop | for value, expected_result in test_data: |
48 | 2241e2b9 | Iustin Pop | self.failUnlessEqual(cli.ParseTimespec(value), expected_result)
|
49 | 2241e2b9 | Iustin Pop | |
50 | 2241e2b9 | Iustin Pop | def testInvalidTime(self): |
51 | 2241e2b9 | Iustin Pop | """Test invalid timespecs"""
|
52 | 2241e2b9 | Iustin Pop | test_data = [ |
53 | 2241e2b9 | Iustin Pop | '1y',
|
54 | 2241e2b9 | Iustin Pop | '',
|
55 | 2241e2b9 | Iustin Pop | 'aaa',
|
56 | 2241e2b9 | Iustin Pop | 's',
|
57 | 2241e2b9 | Iustin Pop | ] |
58 | 2241e2b9 | Iustin Pop | for value in test_data: |
59 | 2241e2b9 | Iustin Pop | self.failUnlessRaises(OpPrereqError, cli.ParseTimespec, value)
|
60 | 2241e2b9 | Iustin Pop | |
61 | 2241e2b9 | Iustin Pop | |
62 | a8469393 | Iustin Pop | class TestSplitKeyVal(unittest.TestCase): |
63 | a8469393 | Iustin Pop | """Testing case for cli._SplitKeyVal"""
|
64 | fcd62d84 | Iustin Pop | DATA = "a=b,c,no_d,-e"
|
65 | fcd62d84 | Iustin Pop | RESULT = {"a": "b", "c": True, "d": False, "e": None} |
66 | a8469393 | Iustin Pop | |
67 | a8469393 | Iustin Pop | def testSplitKeyVal(self): |
68 | a8469393 | Iustin Pop | """Test splitting"""
|
69 | a8469393 | Iustin Pop | self.failUnlessEqual(cli._SplitKeyVal("option", self.DATA), self.RESULT) |
70 | a8469393 | Iustin Pop | |
71 | a8469393 | Iustin Pop | def testDuplicateParam(self): |
72 | a8469393 | Iustin Pop | """Test duplicate parameters"""
|
73 | a8469393 | Iustin Pop | for data in ("a=1,a=2", "a,no_a"): |
74 | a8469393 | Iustin Pop | self.failUnlessRaises(ParameterError, cli._SplitKeyVal,
|
75 | a8469393 | Iustin Pop | "option", data)
|
76 | a8469393 | Iustin Pop | |
77 | a8469393 | Iustin Pop | |
78 | 2241e2b9 | Iustin Pop | if __name__ == '__main__': |
79 | 2241e2b9 | Iustin Pop | unittest.main() |