root / test / ganeti.rapi.testutils_unittest.py @ 415feb2e
History | View | Annotate | Download (2.6 kB)
1 | a85f23fa | Michael Hanselmann | #!/usr/bin/python
|
---|---|---|---|
2 | a85f23fa | Michael Hanselmann | #
|
3 | a85f23fa | Michael Hanselmann | |
4 | a85f23fa | Michael Hanselmann | # Copyright (C) 2012 Google Inc.
|
5 | a85f23fa | Michael Hanselmann | #
|
6 | a85f23fa | Michael Hanselmann | # This program is free software; you can redistribute it and/or modify
|
7 | a85f23fa | Michael Hanselmann | # it under the terms of the GNU General Public License as published by
|
8 | a85f23fa | Michael Hanselmann | # the Free Software Foundation; either version 2 of the License, or
|
9 | a85f23fa | Michael Hanselmann | # (at your option) any later version.
|
10 | a85f23fa | Michael Hanselmann | #
|
11 | a85f23fa | Michael Hanselmann | # This program is distributed in the hope that it will be useful, but
|
12 | a85f23fa | Michael Hanselmann | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | a85f23fa | Michael Hanselmann | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | a85f23fa | Michael Hanselmann | # General Public License for more details.
|
15 | a85f23fa | Michael Hanselmann | #
|
16 | a85f23fa | Michael Hanselmann | # You should have received a copy of the GNU General Public License
|
17 | a85f23fa | Michael Hanselmann | # along with this program; if not, write to the Free Software
|
18 | a85f23fa | Michael Hanselmann | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | a85f23fa | Michael Hanselmann | # 02110-1301, USA.
|
20 | a85f23fa | Michael Hanselmann | |
21 | a85f23fa | Michael Hanselmann | |
22 | a85f23fa | Michael Hanselmann | """Script for testing ganeti.rapi.testutils"""
|
23 | a85f23fa | Michael Hanselmann | |
24 | a85f23fa | Michael Hanselmann | import unittest |
25 | a85f23fa | Michael Hanselmann | |
26 | a85f23fa | Michael Hanselmann | from ganeti import compat |
27 | a85f23fa | Michael Hanselmann | from ganeti import constants |
28 | a85f23fa | Michael Hanselmann | from ganeti import errors |
29 | a85f23fa | Michael Hanselmann | from ganeti import opcodes |
30 | a85f23fa | Michael Hanselmann | from ganeti import rapi |
31 | a85f23fa | Michael Hanselmann | |
32 | a85f23fa | Michael Hanselmann | import ganeti.rapi.testutils |
33 | a85f23fa | Michael Hanselmann | |
34 | a85f23fa | Michael Hanselmann | import testutils |
35 | a85f23fa | Michael Hanselmann | |
36 | a85f23fa | Michael Hanselmann | |
37 | a85f23fa | Michael Hanselmann | class TestHideInternalErrors(unittest.TestCase): |
38 | a85f23fa | Michael Hanselmann | def test(self): |
39 | a85f23fa | Michael Hanselmann | def inner(): |
40 | a85f23fa | Michael Hanselmann | raise errors.GenericError("error") |
41 | a85f23fa | Michael Hanselmann | |
42 | a85f23fa | Michael Hanselmann | fn = rapi.testutils._HideInternalErrors(inner) |
43 | a85f23fa | Michael Hanselmann | |
44 | a85f23fa | Michael Hanselmann | self.assertRaises(rapi.testutils.VerificationError, fn)
|
45 | a85f23fa | Michael Hanselmann | |
46 | a85f23fa | Michael Hanselmann | |
47 | a85f23fa | Michael Hanselmann | class TestVerifyOpInput(unittest.TestCase): |
48 | a85f23fa | Michael Hanselmann | def testUnknownOpId(self): |
49 | a85f23fa | Michael Hanselmann | voi = rapi.testutils.VerifyOpInput |
50 | a85f23fa | Michael Hanselmann | |
51 | a85f23fa | Michael Hanselmann | self.assertRaises(rapi.testutils.VerificationError, voi, "UNK_OP_ID", None) |
52 | a85f23fa | Michael Hanselmann | |
53 | a85f23fa | Michael Hanselmann | def testUnknownParameter(self): |
54 | a85f23fa | Michael Hanselmann | voi = rapi.testutils.VerifyOpInput |
55 | a85f23fa | Michael Hanselmann | |
56 | a85f23fa | Michael Hanselmann | self.assertRaises(rapi.testutils.VerificationError, voi,
|
57 | a85f23fa | Michael Hanselmann | opcodes.OpClusterRename.OP_ID, { |
58 | a85f23fa | Michael Hanselmann | "unk": "unk", |
59 | a85f23fa | Michael Hanselmann | }) |
60 | a85f23fa | Michael Hanselmann | |
61 | a85f23fa | Michael Hanselmann | def testWrongParameterValue(self): |
62 | a85f23fa | Michael Hanselmann | voi = rapi.testutils.VerifyOpInput |
63 | a85f23fa | Michael Hanselmann | self.assertRaises(rapi.testutils.VerificationError, voi,
|
64 | a85f23fa | Michael Hanselmann | opcodes.OpClusterRename.OP_ID, { |
65 | a85f23fa | Michael Hanselmann | "name": object(), |
66 | a85f23fa | Michael Hanselmann | }) |
67 | a85f23fa | Michael Hanselmann | |
68 | a85f23fa | Michael Hanselmann | def testSuccess(self): |
69 | a85f23fa | Michael Hanselmann | voi = rapi.testutils.VerifyOpInput |
70 | a85f23fa | Michael Hanselmann | voi(opcodes.OpClusterRename.OP_ID, { |
71 | a85f23fa | Michael Hanselmann | "name": "new-name.example.com", |
72 | a85f23fa | Michael Hanselmann | }) |
73 | a85f23fa | Michael Hanselmann | |
74 | a85f23fa | Michael Hanselmann | |
75 | a85f23fa | Michael Hanselmann | class TestVerifyOpResult(unittest.TestCase): |
76 | a85f23fa | Michael Hanselmann | def testSuccess(self): |
77 | a85f23fa | Michael Hanselmann | vor = rapi.testutils.VerifyOpResult |
78 | a85f23fa | Michael Hanselmann | |
79 | a85f23fa | Michael Hanselmann | vor(opcodes.OpClusterVerify.OP_ID, { |
80 | a85f23fa | Michael Hanselmann | constants.JOB_IDS_KEY: [ |
81 | a85f23fa | Michael Hanselmann | (False, "error message"), |
82 | a85f23fa | Michael Hanselmann | ], |
83 | a85f23fa | Michael Hanselmann | }) |
84 | a85f23fa | Michael Hanselmann | |
85 | a85f23fa | Michael Hanselmann | def testWrongResult(self): |
86 | a85f23fa | Michael Hanselmann | vor = rapi.testutils.VerifyOpResult |
87 | a85f23fa | Michael Hanselmann | |
88 | a85f23fa | Michael Hanselmann | self.assertRaises(rapi.testutils.VerificationError, vor,
|
89 | a85f23fa | Michael Hanselmann | opcodes.OpClusterVerify.OP_ID, []) |
90 | a85f23fa | Michael Hanselmann | |
91 | a85f23fa | Michael Hanselmann | def testNoResultCheck(self): |
92 | a85f23fa | Michael Hanselmann | vor = rapi.testutils.VerifyOpResult |
93 | a85f23fa | Michael Hanselmann | |
94 | a85f23fa | Michael Hanselmann | assert opcodes.OpTestDummy.OP_RESULT is None |
95 | a85f23fa | Michael Hanselmann | |
96 | a85f23fa | Michael Hanselmann | vor(opcodes.OpTestDummy.OP_ID, None)
|
97 | a85f23fa | Michael Hanselmann | |
98 | a85f23fa | Michael Hanselmann | |
99 | a85f23fa | Michael Hanselmann | if __name__ == "__main__": |
100 | a85f23fa | Michael Hanselmann | testutils.GanetiTestProgram() |