Statistics
| Branch: | Tag: | Revision:

root / test / ganeti.rapi.resources_unittest.py @ 441e7cfd

History | View | Annotate | Download (2.5 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 rlib1 
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._TestUri("/tags", (rlib1.R_tags, [], {}))
51
    self._TestUri("/instances", (rlib1.R_instances, [], {}))
52

    
53
    self._TestUri('/instances/www.test.com',
54
                  (rlib1.R_instances_name,
55
                   ['www.test.com'],
56
                   {}))
57

    
58
    self._TestUri('/instances/www.test.com/tags?f=5&f=6&alt=html',
59
                  (rlib1.R_instances_name_tags,
60
                   ['www.test.com'],
61
                   {'alt': ['html'],
62
                    'f': ['5', '6'],
63
                   }))
64

    
65
    self._TestFailingUri("/tag")
66
    self._TestFailingUri("/instances/does/not/exist")
67

    
68

    
69
class R_RootTests(unittest.TestCase):
70
  """Testing for R_root class."""
71

    
72
  def setUp(self):
73
    self.root = connector.R_root(None, None, None, None)
74

    
75
  def testGet(self):
76
    expected = [
77
      {'name': 'info', 'uri': '/info'},
78
      {'name': 'instances', 'uri': '/instances'},
79
      {'name': 'nodes', 'uri': '/nodes'},
80
      {'name': 'os', 'uri': '/os'},
81
      {'name': 'tags', 'uri': '/tags'},
82
      {'name': 'version', 'uri': '/version'},
83
      ]
84
    self.assertEquals(self.root.GET(), expected)
85

    
86

    
87
if __name__ == '__main__':
88
  unittest.main()