4 # Copyright (C) 2007, 2008 Google Inc.
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.
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.
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
22 """Script for unittesting the RAPI resources module"""
28 from ganeti import errors
29 from ganeti import http
31 from ganeti.rapi import connector
32 from ganeti.rapi import rlib2
37 class MapperTests(unittest.TestCase):
38 """Tests for remote API URI mapper."""
41 self.map = connector.Mapper()
43 def _TestUri(self, uri, result):
44 self.assertEquals(self.map.getController(uri), result)
46 def _TestFailingUri(self, uri):
47 self.failUnlessRaises(http.HttpNotFound, self.map.getController, uri)
52 self._TestFailingUri("/tags")
53 self._TestFailingUri("/instances")
54 self._TestUri("/version", (rlib2.R_version, [], {}))
56 self._TestUri('/2/instances/www.test.com',
57 (rlib2.R_2_instances_name,
61 self._TestUri('/2/instances/www.test.com/tags?f=5&f=6&alt=html',
62 (rlib2.R_2_instances_name_tags,
68 self._TestFailingUri("/tag")
69 self._TestFailingUri("/instances/does/not/exist")
72 class R_RootTests(unittest.TestCase):
73 """Testing for R_root class."""
76 self.root = connector.R_root(None, None, None)
80 {'name': '2', 'uri': '/2'},
81 {'name': 'version', 'uri': '/version'},
83 self.assertEquals(self.root.GET(), expected)
86 if __name__ == '__main__':
87 testutils.GanetiTestProgram()