[asterisk-commits] mmichelson: branch mmichelson/bridge-tests r3297 - in /asterisk/team/mmichels...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jul 5 20:51:37 CDT 2012


Author: mmichelson
Date: Thu Jul  5 20:51:34 2012
New Revision: 3297

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3297
Log:
I now have callback methods working for the AMI module.

For now, you can ignore changes in the cdr_userfield test.
I'm just using that as a testing ground for my module.

I had to make an adjustment to the TestRunner in order
to get things working. Specifically, I needed a way to
tell it to add the path of my test to its list of supported
paths when attempting to import a module. However, the only
way to do this was to also tell it a module to load. That's
not what I wanted, so I altered code that required that a
module be specified in the configuration. It's a touch
awkward but it gets the job done. I'll probably change it
before too much longer.

Next big item on the list though is event count support.


Modified:
    asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/TestRunner.py
    asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/ami.py
    asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/configs/ast1/extensions.conf
    asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/test-config.yaml

Modified: asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/TestRunner.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/TestRunner.py?view=diff&rev=3297&r1=3296&r2=3297
==============================================================================
--- asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/TestRunner.py (original)
+++ asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/TestRunner.py Thu Jul  5 20:51:34 2012
@@ -116,10 +116,11 @@
                 module_spec['load-from-path'])
             sys.path.append(module_spec['load-from-path'])
 
-        module_type = load_and_parse_module(module_spec['typename'])
-        # Modules take in two parameters: the module configuration object,
-        # and the test object that they attach to
-        module_type(module_config, test_object)
+        if 'typename' in module_spec:
+            module_type = load_and_parse_module(module_spec['typename'])
+            # Modules take in two parameters: the module configuration object,
+            # and the test object that they attach to
+            module_type(module_config, test_object)
 
 
 def load_and_parse_module(type_name):
@@ -276,4 +277,4 @@
 
 
 if __name__ == '__main__':
-    sys.exit(main() or 0)
+    sys.exit(main() or 0)

Modified: asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/ami.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/ami.py?view=diff&rev=3297&r1=3296&r2=3297
==============================================================================
--- asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/ami.py (original)
+++ asterisk/team/mmichelson/bridge-tests/lib/python/asterisk/ami.py Thu Jul  5 20:51:34 2012
@@ -101,17 +101,11 @@
         super(AMICallbackInstance, self).__init__(instance_config, test_object)
         self.callback_module = instance_config['callback_module']
         self.callback_method = instance_config['callback_method']
-        self.module = None
 
     def event_callback(self, ami, event):
-        if not self.module:
-            finder = TestModuleFinder()
-            self.module = finder.find_module(self.callback_module)
-            if not self.module:
-                raise Exception
-            self.module.load_module(self.callback_module)
-        #XXX Now what? Just call the method? getattr?
-        return self.callback_method(ami, event)
+        callback_module = __import__(self.callback_module)
+        method = getattr(callback_module, self.callback_method)
+        return method(ami, event)
 
 class AMIEventInstanceFactory:
     @staticmethod
@@ -120,7 +114,7 @@
         if instance_type == "headermatch":
             logger.debug("instance type is 'headermatch'")
             return AMIHeaderMatchInstance(instance_config, test_object)
-        elif instance_type == "callback:":
+        elif instance_type == "callback":
             logger.debug("instance type is 'callback'")
             return AMICallbackInstance(instance_config, test_object)
         else:
@@ -134,7 +128,7 @@
         self.test_object = test_object
         self.ami_instances = []
         for instance in module_config:
-            self.ami_instances.append(AMIEventInstanceFactory.create_instance(instance['instance'],
+            self.ami_instances.append(AMIEventInstanceFactory.create_instance(instance,
                 test_object))
 
 class AMI:

Modified: asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/configs/ast1/extensions.conf?view=diff&rev=3297&r1=3296&r2=3297
==============================================================================
--- asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/configs/ast1/extensions.conf (original)
+++ asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/configs/ast1/extensions.conf Thu Jul  5 20:51:34 2012
@@ -8,5 +8,6 @@
 exten => 1,1,Answer
 exten => 1,n,Set(CDR(accountcode)=cdrtest_local)
 exten => 1,n,Set(CDR(userfield)=bazinga)
-exten => 1,n,UserEvent(eggs)
+exten => 1,n,UserEvent(eggs, Style: scrambled)
+exten => 1,n,UserEvent(bacon, Style: crispy)
 exten => 1,n,Hangup

Modified: asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/test-config.yaml?view=diff&rev=3297&r1=3296&r2=3297
==============================================================================
--- asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/test-config.yaml (original)
+++ asterisk/team/mmichelson/bridge-tests/tests/cdr/cdr_userfield/test-config.yaml Thu Jul  5 20:51:34 2012
@@ -14,6 +14,8 @@
         -
             config-section: 'ami-config'
             typename: 'ami.AMIEvent'
+        -
+            load-from-test: 'True'
 
 test-object-config:
     spawn-after-hangup: True
@@ -41,20 +43,26 @@
 
 ami-config:
     -
-        instance:
-                id: '0'
-                type: 'headermatch'
-                start: 'pass'
-                conditions:
-                        match:
-                                Event: 'UserEvent'
-                                UserEvent: 'eggs'
-                    
-                requirements:
-                        nomatch:
-                                Style: 'overeasy'
-
-
+        id: '0'
+        type: 'headermatch'
+        start: 'pass'
+        conditions:
+            match:
+                Event: 'UserEvent'
+                UserEvent: 'eggs'
+        requirements:
+            match:
+                Style: 'scrambled'
+    -
+        id: '0'
+        type: 'callback'
+        start: 'pass'
+        conditions:
+            match:
+                Event: 'UserEvent'
+                UserEvent: 'bacon'
+        callback_module: 'buns'
+        callback_method: 'print_event'
 
 properties:
     minversion: '1.8.0.0'




More information about the asterisk-commits mailing list