initialise repo
[debian/mudpuppy.git] / modules / test.py
1 '''modules for use in unit testing'''
2
3 from modules.base import Automatia, CannotAutomateException
4 from modules.orchestra import OrchestraAutomatia, OrchestraMetadataAutomatia
5
6 class TestModule(Automatia):
7         '''Test item automation model
8         Successfuly automates a specific item
9         '''
10         can_handle = ('TestModuleItem',)
11
12         def do_magic(self):
13                 return  # Returning nothing is fine. The item will still succeed
14
15 class TestModuleUnimplemented(Automatia):
16         '''Test item automation model
17
18         Raises NotImplementedError when mudpuppy tries to call do_magic
19         '''
20         can_handle = ('TestUnimplementedModuleItem',)
21
22 class TestAlwaysAutomates(Automatia):
23         '''Test item that always automates anything it sees
24         also adds stuff to both the task metadata and the state metadata
25         '''
26         @classmethod
27         def can_automate_item(cls, item_state, task_metadata):
28                 return True
29
30         def do_magic(self):
31                 itemstuff = { 'guess what': ['TestAlwaysAutomates was here', {'fish': 'are cool'}], 'foo': 'bar' }
32                 taskstuff = { 'TestAlwaysAutomates last touched': self.item_state['name'] }
33                 return dict( task_metadata_update=taskstuff, item_metadata_update=itemstuff )
34
35 class TestFakeIP(Automatia):
36         '''Test item automation model to add task metadata
37         Adds a dummy IP address to the task metadata
38         '''
39         can_handle = ('TestFakeIPitem',)
40
41         def do_magic(self):
42                 return dict( task_metadata_update={'ip': '10.0.0.1'} )
43
44 class TestCannotAutomate(Automatia):
45         can_handle = ('TestCannotAutomate item',)
46         def do_magic(self):
47                 nyan = "NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN"
48                 raise CannotAutomateException(nyan)
49
50 class TestOrchestraBad(OrchestraAutomatia):
51         can_handle = ('TestOrchestraBadItem',)
52
53 class TestOrchestra(OrchestraAutomatia):
54         can_handle = ('TestOrchestraItem',)
55         score_name = 'helloworld'
56
57 class TestOrchestraMetadata(OrchestraMetadataAutomatia):
58         can_handle = ('TestOrchestraMetadataItem',)
59
60         # echo score returns score args passed with ORC_ prepended to the key names
61         score_name = 'echo' 
62
63         # get return variables from orchestra and put into into task metadata keys
64         orchestra_response_map = { 'ORC_fish': "fish", "ORC_foo": "taskfoo" }
65         score_args = { 'fish':'heads', 'foo':'bar' }