[svn-commits] pabelanger: branch group/cdr_test_log_congestion r2038 - in /asterisk/team/gr...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Aug 30 13:34:48 CDT 2011


Author: pabelanger
Date: Tue Aug 30 13:34:44 2011
New Revision: 2038

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=2038
Log:
Rewrite

Removed:
    asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/configs/ast1/manager.users.conf.inc
    asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/configs/ast2/
Modified:
    asterisk/team/group/cdr_test_log_congestion/lib/python/asterisk/CDRTestCase.py
    asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/configs/ast1/extensions.conf
    asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/configs/ast1/manager.general.conf.inc
    asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/configs/ast1/sip.conf
    asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/run-test

Modified: asterisk/team/group/cdr_test_log_congestion/lib/python/asterisk/CDRTestCase.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/cdr_test_log_congestion/lib/python/asterisk/CDRTestCase.py?view=diff&rev=2038&r1=2037&r2=2038
==============================================================================
--- asterisk/team/group/cdr_test_log_congestion/lib/python/asterisk/CDRTestCase.py (original)
+++ asterisk/team/group/cdr_test_log_congestion/lib/python/asterisk/CDRTestCase.py Tue Aug 30 13:34:44 2011
@@ -8,12 +8,15 @@
 """
 
 import sys
+import logging
 from twisted.internet import reactor
 
 sys.path.append("lib/python")
 from asterisk import Asterisk
 from TestCase import TestCase
 from cdr import AsteriskCSVCDR, AsteriskCSVCDRLine
+
+logger = logging.getLogger(__name__)
 
 class CDRTestCase(TestCase):
     """
@@ -34,22 +37,23 @@
     #col 2 - AsteriskCSVCDRLine that goes with ast
     CDRLineExpectations = []
 
+    def __init__(self):
+        TestCase.__init__(self)
+        self.create_asterisk()
 
-    def add_expectation(self, cdrline, astIndex):
+    def add_expectation(self, cdrline):
         """Add an expectation to the expectation list
 
         Keyword Arguments:
         cdrline -- AsteriskCSVCDRLine for an expected element of the cdr
-        astIndex -- int value for the asterisk instance that cdrline should be bound to
 
         Example Usage:
         self.add_expectation(AsteriskCSVCDRLine(accountcode="",
             source="", destination="s", dcontext="default", callerid="",
             channel="SIP/test-00000000", disposition="CONGESTION",
-            amaflags="DOCUMENTATION"), 0)
+            amaflags="DOCUMENTATION"))
         """
-        self.CDRLineExpectations.append([astIndex, cdrline])
-        pass
+        self.CDRLineExpectations.append([cdrline])
 
 
     def match_cdrs(self):
@@ -62,63 +66,29 @@
         does_match = self.match_cdrs()
         """
 
-        print "Attempting to match cdrs, note that this function is expected to produce file and type errors."
-        all_pass = True
-        for astnum, astTest in enumerate(self.ast):
-            #We'll store the cdrlines for an individual instance of Asterisk in here
-            records = []
+        # We'll store the cdrlines for an individual instance of Asterisk in here
+        records = []
 
-            #Build records with just the cdrlines that belong to this instance of Asterisk
-            for count, cdrline in enumerate(self.CDRLineExpectations):
-                if cdrline[0] == astnum:
-                    records.append(cdrline[1])
+        # Build records with just the cdrlines that belong to this instance of Asterisk
+        for count, cdrline in enumerate(self.CDRLineExpectations):
+            records.append(cdrline[0])
 
-            #Now make a cdr from records and load the cdr from the ast instance
-            cdr_expect = AsteriskCSVCDR(records=records)
-            cdr_file = AsteriskCSVCDR(fn="%s/%s/cdr-csv/Master.csv" % (astTest.base, astTest.directories['astlogdir']))
+        # Now make a cdr from records and load the cdr from the ast instance
+        cdr_expect = AsteriskCSVCDR(records=records)
+        cdr_file = AsteriskCSVCDR(fn="%s/%s/cdr-csv/Master.csv" %
+                (self.ast[0].base, self.ast[0].directories['astlogdir']))
 
-            print "length of cdr expected - %d" % len(cdr_expect)
-            print "length of cdr produced - %d" % len(cdr_file)
+        # Now match test the match:
+        if cdr_expect.match(cdr_file):
+            self.passed = True
 
-            #Now match test the match:
-            if cdr_expect.match(cdr_file):
-                print "match on %s" % astTest.base
-            else:
-                print "mismatch on %s" % astTest.base
-                all_pass = False
+    def ami_connect(self, ami):
+        TestCase.ami_connect(self, ami)
+        self.ami[0].originate(
+            channel = 'Local/1 at default',
+            application = 'Echo'
+        )
 
-        return all_pass
-
-
-    def stop_reactor(self):
-        """Overrides TestCase stop_reactor in order to add end(self) function
-        This works as the normal stop_reactor function, but will run end(self) when finished.
-
-        Example Usage:
-        self.stop_reactor()
-        """
-        if (reactor.running):
-            print "Stopping Reactor ... :<"
-            reactor.stop()
-            self.end()
-        self.stop_asterisk()
-        pass
-
-
-    def end(self):
-        """End of test function
-        By default, this test will set the success or failure of a CDRTestCase strictly by
-        whether or not the CDRs match the expectations.
-
-        This function can be overridden in specific CDRTestCases in order to avoid this
-        simplistic pass/fail evaluation
-
-        This function probably shouldn't be deliberately invoked within a specific test.
-        """
-        print "End Test"
-        self.passed = self.match_cdrs()
-
-        if self.passed:
-            print "All CDRs matched as expected."
-        else:
-            print "There were CDR mismatches."
+    def run(self):
+        TestCase.run(self)
+        self.create_ami_factory()

Modified: asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/configs/ast1/extensions.conf?view=diff&rev=2038&r1=2037&r2=2038
==============================================================================
--- asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/configs/ast1/extensions.conf (original)
+++ asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/configs/ast1/extensions.conf Tue Aug 30 13:34:44 2011
@@ -5,6 +5,9 @@
 [globals]
 
 [default]
-exten => 1,1,Answer()
-exten => 1,2,Background(tt-weasels)
-exten => 1,n,GoTo(2)
+exten => 1,1,NoOp()
+    same => n,NoCDR()
+    same => n,Dial(SIP/test/2)
+
+exten => 2,1,NoOp()
+    same => n,Congestion()

Modified: asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/configs/ast1/manager.general.conf.inc
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/configs/ast1/manager.general.conf.inc?view=diff&rev=2038&r1=2037&r2=2038
==============================================================================
--- asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/configs/ast1/manager.general.conf.inc (original)
+++ asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/configs/ast1/manager.general.conf.inc Tue Aug 30 13:34:44 2011
@@ -1,3 +1,1 @@
 enabled = yes
-port = 5038
-bindaddr = 127.0.0.1

Modified: asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/configs/ast1/sip.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/configs/ast1/sip.conf?view=diff&rev=2038&r1=2037&r2=2038
==============================================================================
--- asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/configs/ast1/sip.conf (original)
+++ asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/configs/ast1/sip.conf Tue Aug 30 13:34:44 2011
@@ -1,11 +1,7 @@
 [general]
 context=default
-udpbindaddr=127.0.0.1:5065
-directmedia=no
-disallow=all
-allow=ulaw
+udpbindaddr=127.0.0.1
 
 [test]
 type=peer
-host=127.0.0.2
-port=5070
+host=127.0.0.1

Modified: asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/run-test?view=diff&rev=2038&r1=2037&r2=2038
==============================================================================
--- asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/run-test (original)
+++ asterisk/team/group/cdr_test_log_congestion/tests/cdr/cdr_originate_sip_congestion_log/run-test Tue Aug 30 13:34:44 2011
@@ -14,47 +14,41 @@
 from asterisk.cdr import AsteriskCSVCDR, AsteriskCSVCDRLine
 from twisted.internet import reactor
 
-workingdir = "/tmp/asterisk-testsuite/cdr_originate_sip_congestion_log"
-testdir = "tests/cdr/cdr_originate_sip_congestion_log"
+class CDRCongestionLogTest(CDRTestCase):
 
-class CDRCongestionLogTest(CDRTestCase):
-    def __init__(self, argv):
-        CDRTestCase.__init__(self, argv)
+    def __init__(self):
+        CDRTestCase.__init__(self)
+        self.add_expectation(AsteriskCSVCDRLine(
+            accountcode='',
+            source='',
+            destination='1',
+            dcontext='default',
+            callerid='',
+            channel='Local/1 at default-.*',
+            disposition='FAILED',
+            amaflags='DOCUMENTATION'
+        ))
+        self.add_expectation(AsteriskCSVCDRLine(
+            accountcode='',
+            source='Anonymous',
+            destination='2',
+            dcontext='default',
+            callerid='"Anonymous" <Anonymous>',
+            channel='SIP/test-00000001',
+            disposition='CONGESTION',
+            amaflags='DOCUMENTATION'
+        ))
 
-        #This test doesn't need more than a few seconds to confirm proper running behavior
-        self.reactor_timeout = 20
 
-        self.create_asterisk(2)
+def main():
+    test = CDRCongestionLogTest()
+    test.start_asterisk()
+    reactor.run()
+    test.stop_asterisk()
 
-        #Add Expectation - ast[0] should have a single call record ending in congestion
-        self.add_expectation(AsteriskCSVCDRLine(accountcode="",
-            source="", destination="s", dcontext="default", callerid="",
-            channel="SIP/test-00000000", disposition="CONGESTION",
-            amaflags="DOCUMENTATION"), 0)
-
-        print "Expectations Set"
-
-    def run(self):
-        CDRTestCase.run(self)
-        self.create_ami_factory(1, "user", "mysecret")
-
-    def ami_connect(self, ami):
-        CDRTestCase.ami_connect(self, ami)
-        print "originating SIP call on peer 'test'.  This originate is expected to fail due to congestion."
-        ami.originate(channel = "SIP/test/1", context = "default", exten = "1", priority = "1")
-
-def main(argv=None):
-    if argv is None:
-        argv = sys.argv
-    test = CDRCongestionLogTest(argv)
-    test.start_asterisk()
-    reactor.run() #CDRTestCase will perform Asterisk_close on reactor.stop()
-
-    if (test.passed):
-        print "SUCCESS"
-        return 0
-    print "FAILURE"
-    return 1
+    return test.match_cdrs()
 
 if __name__ == '__main__':
     sys.exit(main())
+
+# vim:sw=4:ts=4:expandtab:textwidth=79




More information about the svn-commits mailing list