root / test / ganeti.rapi.resources_unittest.py @ 36e23a40
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 |
|
35 |
class MapperTests(unittest.TestCase): |
36 |
"""Tests for remote API URI mapper."""
|
37 |
|
38 |
def setUp(self): |
39 |
self.map = connector.Mapper()
|
40 |
|
41 |
def _TestUri(self, uri, result): |
42 |
self.assertEquals(self.map.getController(uri), result) |
43 |
|
44 |
def _TestFailingUri(self, uri): |
45 |
self.failUnlessRaises(http.HttpNotFound, self.map.getController, uri) |
46 |
|
47 |
def testMapper(self): |
48 |
"""Testing Mapper"""
|
49 |
|
50 |
self._TestFailingUri("/tags") |
51 |
self._TestFailingUri("/instances") |
52 |
self._TestUri("/version", (rlib2.R_version, [], {})) |
53 |
|
54 |
self._TestUri('/2/instances/www.test.com', |
55 |
(rlib2.R_2_instances_name, |
56 |
['www.test.com'],
|
57 |
{})) |
58 |
|
59 |
self._TestUri('/2/instances/www.test.com/tags?f=5&f=6&alt=html', |
60 |
(rlib2.R_2_instances_name_tags, |
61 |
['www.test.com'],
|
62 |
{'alt': ['html'], |
63 |
'f': ['5', '6'], |
64 |
})) |
65 |
|
66 |
self._TestFailingUri("/tag") |
67 |
self._TestFailingUri("/instances/does/not/exist") |
68 |
|
69 |
|
70 |
class R_RootTests(unittest.TestCase): |
71 |
"""Testing for R_root class."""
|
72 |
|
73 |
def setUp(self): |
74 |
self.root = connector.R_root(None, None, None) |
75 |
|
76 |
def testGet(self): |
77 |
expected = [ |
78 |
{'name': '2', 'uri': '/2'}, |
79 |
{'name': 'version', 'uri': '/version'}, |
80 |
] |
81 |
self.assertEquals(self.root.GET(), expected) |
82 |
|
83 |
|
84 |
if __name__ == '__main__': |
85 |
unittest.main() |