Statistics
| Branch: | Tag: | Revision:

root / test / ganeti.rapi.resources_unittest.py @ d357f531

History | View | Annotate | Download (2.3 kB)

1 4cbd4462 Oleksiy Mishchenko
#!/usr/bin/python
2 4cbd4462 Oleksiy Mishchenko
#
3 4cbd4462 Oleksiy Mishchenko
4 4cbd4462 Oleksiy Mishchenko
# Copyright (C) 2007, 2008 Google Inc.
5 4cbd4462 Oleksiy Mishchenko
#
6 4cbd4462 Oleksiy Mishchenko
# This program is free software; you can redistribute it and/or modify
7 4cbd4462 Oleksiy Mishchenko
# it under the terms of the GNU General Public License as published by
8 4cbd4462 Oleksiy Mishchenko
# the Free Software Foundation; either version 2 of the License, or
9 4cbd4462 Oleksiy Mishchenko
# (at your option) any later version.
10 4cbd4462 Oleksiy Mishchenko
#
11 4cbd4462 Oleksiy Mishchenko
# This program is distributed in the hope that it will be useful, but
12 4cbd4462 Oleksiy Mishchenko
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 4cbd4462 Oleksiy Mishchenko
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 4cbd4462 Oleksiy Mishchenko
# General Public License for more details.
15 4cbd4462 Oleksiy Mishchenko
#
16 4cbd4462 Oleksiy Mishchenko
# You should have received a copy of the GNU General Public License
17 4cbd4462 Oleksiy Mishchenko
# along with this program; if not, write to the Free Software
18 4cbd4462 Oleksiy Mishchenko
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 4cbd4462 Oleksiy Mishchenko
# 02110-1301, USA.
20 4cbd4462 Oleksiy Mishchenko
21 4cbd4462 Oleksiy Mishchenko
22 10b207d4 Oleksiy Mishchenko
"""Script for unittesting the RAPI resources module"""
23 4cbd4462 Oleksiy Mishchenko
24 4cbd4462 Oleksiy Mishchenko
25 4cbd4462 Oleksiy Mishchenko
import unittest
26 4cbd4462 Oleksiy Mishchenko
import tempfile
27 4cbd4462 Oleksiy Mishchenko
28 4cbd4462 Oleksiy Mishchenko
from ganeti import errors
29 a0638838 Oleksiy Mishchenko
from ganeti import http
30 a0638838 Oleksiy Mishchenko
31 5d8d232c Michael Hanselmann
from ganeti.rapi import connector
32 028c6b76 Oleksiy Mishchenko
from ganeti.rapi import rlib2
33 4cbd4462 Oleksiy Mishchenko
34 4cbd4462 Oleksiy Mishchenko
35 4cbd4462 Oleksiy Mishchenko
class MapperTests(unittest.TestCase):
36 4cbd4462 Oleksiy Mishchenko
  """Tests for remote API URI mapper."""
37 4cbd4462 Oleksiy Mishchenko
38 4cbd4462 Oleksiy Mishchenko
  def setUp(self):
39 10b207d4 Oleksiy Mishchenko
    self.map = connector.Mapper()
40 4cbd4462 Oleksiy Mishchenko
41 4cbd4462 Oleksiy Mishchenko
  def _TestUri(self, uri, result):
42 4cbd4462 Oleksiy Mishchenko
    self.assertEquals(self.map.getController(uri), result)
43 4cbd4462 Oleksiy Mishchenko
44 4cbd4462 Oleksiy Mishchenko
  def _TestFailingUri(self, uri):
45 84f2756e Michael Hanselmann
    self.failUnlessRaises(http.HttpNotFound, self.map.getController, uri)
46 4cbd4462 Oleksiy Mishchenko
47 4cbd4462 Oleksiy Mishchenko
  def testMapper(self):
48 10b207d4 Oleksiy Mishchenko
    """Testing Mapper"""
49 4cbd4462 Oleksiy Mishchenko
50 dc824c9f Oleksiy Mishchenko
    self._TestFailingUri("/tags")
51 dc824c9f Oleksiy Mishchenko
    self._TestFailingUri("/instances")
52 4e5a68f8 Oleksiy Mishchenko
    self._TestUri("/version", (rlib2.R_version, [], {}))
53 4cbd4462 Oleksiy Mishchenko
54 dc824c9f Oleksiy Mishchenko
    self._TestUri('/2/instances/www.test.com',
55 4e5a68f8 Oleksiy Mishchenko
                  (rlib2.R_2_instances_name,
56 4cbd4462 Oleksiy Mishchenko
                   ['www.test.com'],
57 4cbd4462 Oleksiy Mishchenko
                   {}))
58 4cbd4462 Oleksiy Mishchenko
59 dc824c9f Oleksiy Mishchenko
    self._TestUri('/2/instances/www.test.com/tags?f=5&f=6&alt=html',
60 dc824c9f Oleksiy Mishchenko
                  (rlib2.R_2_instances_name_tags,
61 4cbd4462 Oleksiy Mishchenko
                   ['www.test.com'],
62 4cbd4462 Oleksiy Mishchenko
                   {'alt': ['html'],
63 4cbd4462 Oleksiy Mishchenko
                    'f': ['5', '6'],
64 4cbd4462 Oleksiy Mishchenko
                   }))
65 4cbd4462 Oleksiy Mishchenko
66 4cbd4462 Oleksiy Mishchenko
    self._TestFailingUri("/tag")
67 4cbd4462 Oleksiy Mishchenko
    self._TestFailingUri("/instances/does/not/exist")
68 4cbd4462 Oleksiy Mishchenko
69 4cbd4462 Oleksiy Mishchenko
70 4cbd4462 Oleksiy Mishchenko
class R_RootTests(unittest.TestCase):
71 4cbd4462 Oleksiy Mishchenko
  """Testing for R_root class."""
72 4cbd4462 Oleksiy Mishchenko
73 4cbd4462 Oleksiy Mishchenko
  def setUp(self):
74 5d8d232c Michael Hanselmann
    self.root = connector.R_root(None, None, None)
75 4cbd4462 Oleksiy Mishchenko
76 4cbd4462 Oleksiy Mishchenko
  def testGet(self):
77 4cbd4462 Oleksiy Mishchenko
    expected = [
78 fc72a3a3 Oleksiy Mishchenko
      {'name': '2', 'uri': '/2'},
79 4cbd4462 Oleksiy Mishchenko
      {'name': 'version', 'uri': '/version'},
80 4cbd4462 Oleksiy Mishchenko
      ]
81 4cbd4462 Oleksiy Mishchenko
    self.assertEquals(self.root.GET(), expected)
82 4cbd4462 Oleksiy Mishchenko
83 4cbd4462 Oleksiy Mishchenko
84 4cbd4462 Oleksiy Mishchenko
if __name__ == '__main__':
85 4cbd4462 Oleksiy Mishchenko
  unittest.main()