SSHApi functionality migrated to LinuxNode
[nepi.git] / test / execution / resource.py
1 #!/usr/bin/env python
2 from neco.execution.resource import ResourceManager, ResourceFactory, clsinit
3 from neco.execution.attribute import Attribute
4
5 import unittest
6
7 @clsinit
8 class MyResource(ResourceManager):
9     _rtype = "MyResource"
10
11     @classmethod
12     def _register_attributes(cls):
13         cool_attr = Attribute("my_attr", "is a really nice attribute!")
14         cls._register_attribute(cool_attr)
15
16     def __init__(self, ec, guid):
17         super(MyResource, self).__init__(ec, guid)
18
19 @clsinit
20 class AnotherResource(ResourceManager):
21     _rtype = "AnotherResource"
22
23     def __init__(self, ec, guid):
24         super(AnotherResource, self).__init__(ec, guid)
25      
26 class EC(object):
27     pass
28
29 class ResourceFactoryTestCase(unittest.TestCase):
30     def test_add_resource_factory(self):
31         ResourceFactory.register_type(MyResource)
32         ResourceFactory.register_type(AnotherResource)
33
34         self.assertEquals(MyResource.rtype(), "MyResource")
35         self.assertEquals(len(MyResource._attributes), 1)
36
37         self.assertEquals(ResourceManager.rtype(), "Resource")
38         self.assertEquals(len(ResourceManager._attributes), 0)
39
40         self.assertEquals(AnotherResource.rtype(), "AnotherResource")
41         self.assertEquals(len(AnotherResource._attributes), 0)
42
43         self.assertEquals(len(ResourceFactory.resource_types()), 2)
44
45 # TODO:!!!
46 class ResourceManagerTestCase(unittest.TestCase):
47     def test_start_with_condition(self):
48         pass
49     
50     def test_stop_with_condition(self):
51         pass
52
53     def test_set_with_condition(self):
54         pass
55
56
57 if __name__ == '__main__':
58     unittest.main()
59