root / test / ganeti.rapi.resources_unittest.py @ 20571a26
History | View | Annotate | Download (2.3 kB)
1 |
#!/usr/bin/python
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2007, 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 RAPI resources module"""
|
23 |
|
24 |
|
25 |
import unittest |
26 |
import tempfile |
27 |
|
28 |
from ganeti import errors |
29 |
from ganeti import http |
30 |
|
31 |
from ganeti.rapi import connector |
32 |
from ganeti.rapi import rlib2 |
33 |
|
34 |
import testutils |
35 |
|
36 |
|
37 |
class MapperTests(unittest.TestCase): |
38 |
"""Tests for remote API URI mapper."""
|
39 |
|
40 |
def setUp(self): |
41 |
self.map = connector.Mapper()
|
42 |
|
43 |
def _TestUri(self, uri, result): |
44 |
self.assertEquals(self.map.getController(uri), result) |
45 |
|
46 |
def _TestFailingUri(self, uri): |
47 |
self.failUnlessRaises(http.HttpNotFound, self.map.getController, uri) |
48 |
|
49 |
def testMapper(self): |
50 |
"""Testing Mapper"""
|
51 |
|
52 |
self._TestFailingUri("/tags") |
53 |
self._TestFailingUri("/instances") |
54 |
self._TestUri("/version", (rlib2.R_version, [], {})) |
55 |
|
56 |
self._TestUri('/2/instances/www.test.com', |
57 |
(rlib2.R_2_instances_name, |
58 |
['www.test.com'],
|
59 |
{})) |
60 |
|
61 |
self._TestUri('/2/instances/www.test.com/tags?f=5&f=6&alt=html', |
62 |
(rlib2.R_2_instances_name_tags, |
63 |
['www.test.com'],
|
64 |
{'alt': ['html'], |
65 |
'f': ['5', '6'], |
66 |
})) |
67 |
|
68 |
self._TestFailingUri("/tag") |
69 |
self._TestFailingUri("/instances/does/not/exist") |
70 |
|
71 |
|
72 |
class R_RootTests(unittest.TestCase): |
73 |
"""Testing for R_root class."""
|
74 |
|
75 |
def setUp(self): |
76 |
self.root = connector.R_root(None, None, None) |
77 |
|
78 |
def testGet(self): |
79 |
expected = [ |
80 |
{'name': '2', 'uri': '/2'}, |
81 |
{'name': 'version', 'uri': '/version'}, |
82 |
] |
83 |
self.assertEquals(self.root.GET(), expected) |
84 |
|
85 |
|
86 |
if __name__ == '__main__': |
87 |
testutils.GanetiTestProgram() |