Implement list of avilable for RAPI resources
[ganeti-local] / test / ganeti.rapi.resources_unittest.py
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 os
26 import unittest
27
28 from ganeti.rapi import resources
29
30
31 class MapperTests(unittest.TestCase):
32
33   def setUp(self):
34     self.con = resources.CONNECTOR
35     self.map = resources.Mapper(self.con)
36     
37   def testMapper(self):
38     """Testing for Mapper."""
39     
40     self.failUnless(self.map.getController('/tags') == 
41                     ('R_tags',
42                      ['/tags'],
43                      {}))
44
45     self.failUnless(self.map.getController('/tag') == None)
46     
47     self.failUnless(self.map.getController('/instances/www.test.com') == 
48                     ('R_instances_name',
49                      ['www.test.com'],
50                      {}))
51     
52     self.failUnless(self.map.getController(
53         '/instances/www.test.com/tags?f=5&f=6&alt=html') == 
54                     ('R_instances_name_tags',
55                      ['www.test.com'],
56                      {'alt':['html'], 'f':['5', '6']}))
57
58
59 class R_RootTests(unittest.TestCase):
60   """Testing for R_root class."""
61   
62   def setUp(self):
63     self.root = resources.R_root(None, None, None)
64     self.root.result = []
65   
66   def testGet(self):
67     self.root._get()
68     self.failUnless(self.root.result == 
69                     [{'name': 'instances', 'uri': '/instances'},
70                      {'name': 'info', 'uri': '/info'},
71                      {'name': 'os', 'uri': '/os'},
72                      {'name': 'status', 'uri': '/status'},
73                      {'name': 'tags', 'uri': '/tags'},
74                      {'name': 'nodes', 'uri': '/nodes'}])
75     
76
77 if __name__ == '__main__':
78   unittest.main()