1 '''modules for use in unit testing'''
3 from modules.base import Automatia, CannotAutomateException
4 from modules.orchestra import OrchestraAutomatia, OrchestraMetadataAutomatia
6 class TestModule(Automatia):
7 '''Test item automation model
8 Successfuly automates a specific item
10 can_handle = ('TestModuleItem',)
13 return # Returning nothing is fine. The item will still succeed
15 class TestModuleUnimplemented(Automatia):
16 '''Test item automation model
18 Raises NotImplementedError when mudpuppy tries to call do_magic
20 can_handle = ('TestUnimplementedModuleItem',)
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
27 def can_automate_item(cls, item_state, task_metadata):
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 )
35 class TestFakeIP(Automatia):
36 '''Test item automation model to add task metadata
37 Adds a dummy IP address to the task metadata
39 can_handle = ('TestFakeIPitem',)
42 return dict( task_metadata_update={'ip': '10.0.0.1'} )
44 class TestCannotAutomate(Automatia):
45 can_handle = ('TestCannotAutomate item',)
47 nyan = "NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN"
48 raise CannotAutomateException(nyan)
50 class TestOrchestraBad(OrchestraAutomatia):
51 can_handle = ('TestOrchestraBadItem',)
53 class TestOrchestra(OrchestraAutomatia):
54 can_handle = ('TestOrchestraItem',)
55 score_name = 'helloworld'
57 class TestOrchestraMetadata(OrchestraMetadataAutomatia):
58 can_handle = ('TestOrchestraMetadataItem',)
60 # echo score returns score args passed with ORC_ prepended to the key names
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' }