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