[asterisk-commits] wdoekes: testsuite/asterisk/trunk r3201 - in /asterisk/trunk: lib/python/aste...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Apr 19 17:15:08 CDT 2012


Author: wdoekes
Date: Thu Apr 19 17:15:00 2012
New Revision: 3201

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3201
Log:
Add regression test for issue ASTERISK-19384.

Review: https://reviewboard.asterisk.org/r/1765/
Reviewed by: Terry Wilson

Added:
    asterisk/trunk/tests/cdr/cdr_accountcode/
    asterisk/trunk/tests/cdr/cdr_accountcode/configs/
    asterisk/trunk/tests/cdr/cdr_accountcode/configs/ast1/
    asterisk/trunk/tests/cdr/cdr_accountcode/configs/ast1/cdr.conf   (with props)
    asterisk/trunk/tests/cdr/cdr_accountcode/configs/ast1/extensions.conf   (with props)
    asterisk/trunk/tests/cdr/cdr_accountcode/run-test   (with props)
    asterisk/trunk/tests/cdr/cdr_accountcode/test-config.yaml   (with props)
Modified:
    asterisk/trunk/lib/python/asterisk/cdr.py
    asterisk/trunk/tests/cdr/tests.yaml

Modified: asterisk/trunk/lib/python/asterisk/cdr.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/cdr.py?view=diff&rev=3201&r1=3200&r2=3201
==============================================================================
--- asterisk/trunk/lib/python/asterisk/cdr.py (original)
+++ asterisk/trunk/lib/python/asterisk/cdr.py Thu Apr 19 17:15:00 2012
@@ -39,7 +39,7 @@
         self.__dict__.update(locals())
         del self.__dict__['self']
 
-    def match(self, other):
+    def match(self, other, silent=False):
         """Matches if the subset of fields that exist in both records match.
 
         It is important to make sure that if you want to test against an empty
@@ -47,11 +47,12 @@
         initialization or passed as None.
         """
 
-        for k,v in self.iteritems():
+        for k, v in self.iteritems():
             if None not in (v, other.get(k)) and not re.match(
                     "%s$" % (str(v).lower()), str(other.get(k)).lower()):
-                logger.warn("CDR MATCH FAILED, Expected: %s:%s Got: %s:%s" % (k, v,
-                        k, other.get(k)))
+                if not silent:
+                    logger.warn("CDR MATCH FAILED, Expected: %s:%s Got: %s:%s" %
+                            (k, v, k, other.get(k)))
                 return False
         return True
 
@@ -120,9 +121,63 @@
         if len(self) != len(other):
             logger.warn("CDR MATCH FAILED, different number of records")
             return False
-        for i,x in enumerate(self):
-            if not x.match(other[i]):
-                return False
+
+        def match_order(list_a, list_b, cmp_func):
+            """Utility function that attempts to find out whether list_a and
+            list_b have a single ordering match or if there is more than
+            one.
+
+            >>> f = (lambda x, y: x == y)
+            >>> match_order(['A', 'B', 'C'], ['C', 'B', 'X'], f)
+            ()
+            >>> match_order(['A', 'B', 'C'], ['C', 'B', 'A'], f)
+            ((2, 1, 0),)
+            >>> match_order(['A', 'B', 'C', 'B'], ['C', 'B', 'A', 'B'], f)
+            ((2, 1, 0, 3), (2, 3, 0, 1))
+            """
+            assert len(list_a) == len(list_b)
+            size = len(list_a)
+
+            # attempt two orderings: forward and reversed
+            guess_orders = (range(size), list(reversed(range(size)))) # both mutable
+            found_orders = []
+
+            for guess_order in guess_orders:
+                found_order = []
+                for a in range(size):
+                    for b in guess_order:
+                        if cmp_func(list_a[a], list_b[b]):
+                            found_order.append(b)
+                            guess_order.remove(b)
+                            break
+                    else:
+                        # no match at all..
+                        return ()
+                found_orders.append(tuple(found_order))
+
+            if found_orders[0] != found_orders[1]:
+                return tuple(found_orders)
+            return (found_orders[0],)
+
+        # Use the match_order function to see if there either is (a) no match,
+        # or (b) a single match or (c) several matches. In the latter case, the
+        # regexes should probably be chosen more carefully.
+        matches = match_order(self, other, (lambda x, y: x.match(y, silent=True)))
+
+        if len(matches) == 0:
+            # Bah.. no match. Loop over the records in the normal order and
+            # have it complain immediately.
+            for i, x in enumerate(self):
+                if not x.match(other[i]):
+                    return False
+            assert False
+
+        elif len(matches) == 1:
+            pass # joy!
+
+        elif len(matches) > 1:
+            logger.warn("More than one CDR permutation results in success")
+
         return True
 
     def __str__(self):

Added: asterisk/trunk/tests/cdr/cdr_accountcode/configs/ast1/cdr.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/cdr/cdr_accountcode/configs/ast1/cdr.conf?view=auto&rev=3201
==============================================================================
--- asterisk/trunk/tests/cdr/cdr_accountcode/configs/ast1/cdr.conf (added)
+++ asterisk/trunk/tests/cdr/cdr_accountcode/configs/ast1/cdr.conf Thu Apr 19 17:15:00 2012
@@ -1,0 +1,5 @@
+[general]
+[csv]
+usegmtime=yes    ; log date/time in GMT.  Default is "no"
+loguniqueid=yes  ; log uniqueid.  Default is "no"
+loguserfield=yes ; log user field.  Default is "no"

Propchange: asterisk/trunk/tests/cdr/cdr_accountcode/configs/ast1/cdr.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/cdr/cdr_accountcode/configs/ast1/cdr.conf
------------------------------------------------------------------------------
    svn:keywords = wdoekes 20120420

Propchange: asterisk/trunk/tests/cdr/cdr_accountcode/configs/ast1/cdr.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/cdr/cdr_accountcode/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/cdr/cdr_accountcode/configs/ast1/extensions.conf?view=auto&rev=3201
==============================================================================
--- asterisk/trunk/tests/cdr/cdr_accountcode/configs/ast1/extensions.conf (added)
+++ asterisk/trunk/tests/cdr/cdr_accountcode/configs/ast1/extensions.conf Thu Apr 19 17:15:00 2012
@@ -1,0 +1,13 @@
+[general]
+writeprotect=no
+clearglobalvars=no
+
+[default]
+exten => 1,1,Set(CDR(accountcode)=initial)
+exten => 1,n,Dial(Local/2 at default)
+
+exten => 2,1,Dial(Local/3 at default)
+
+exten => 3,1,Set(CDR(accountcode)=third)
+exten => 3,n,Answer()
+exten => 3,n,Hangup()

Propchange: asterisk/trunk/tests/cdr/cdr_accountcode/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/cdr/cdr_accountcode/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:keywords = wdoekes 20120420

Propchange: asterisk/trunk/tests/cdr/cdr_accountcode/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/cdr/cdr_accountcode/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/cdr/cdr_accountcode/run-test?view=auto&rev=3201
==============================================================================
--- asterisk/trunk/tests/cdr/cdr_accountcode/run-test (added)
+++ asterisk/trunk/tests/cdr/cdr_accountcode/run-test Thu Apr 19 17:15:00 2012
@@ -1,0 +1,70 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2012, Digium, Inc.
+Walter Doekes <walter+asterisk at wjd.nu>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import sys
+sys.path.append("lib/python")
+from asterisk.CDRTestCase import CDRTestCase
+from asterisk.asterisk import Asterisk
+from asterisk.cdr import AsteriskCSVCDR, AsteriskCSVCDRLine
+from twisted.internet import reactor
+import re
+
+class CDRUserFieldTest(CDRTestCase):
+    def __init__(self):
+
+        CDRTestCase.__init__(self)
+
+        # 3 at default -> (answer)
+        # accountcode: third
+        self.add_expectation("Master", AsteriskCSVCDRLine(source="",
+            accountcode="third",
+            destination="3", dcontext="default", callerid="",
+            channel="Local/3 at default-.*", dchannel="",
+            lastapp="Hangup", lastarg="",
+            disposition="ANSWERED", amaflags="DOCUMENTATION",
+        ))
+        # 2 at default -> 3 at default
+        # accountcode: initial
+        self.add_expectation("Master", AsteriskCSVCDRLine(source="",
+            accountcode="initial",
+            destination="2", dcontext="default", callerid="",
+            channel="Local/2 at default-.*", dchannel="Local/3 at default-.*",
+            lastapp="Dial", lastarg="Local/3 at default",
+            disposition="ANSWERED", amaflags="DOCUMENTATION",
+        ))
+        # 1 at default -> 2 at default
+        # accountcode: initial
+        self.add_expectation("Master", AsteriskCSVCDRLine(source="",
+            accountcode="initial",
+            destination="1", dcontext="default", callerid="",
+            channel="Local/1 at default-.*", dchannel="Local/2 at default-.*",
+            lastapp="Dial", lastarg="Local/2 at default",
+            disposition="ANSWERED", amaflags="DOCUMENTATION",
+        ))
+
+        # caller with Echo app
+        self.add_expectation("Master", AsteriskCSVCDRLine(source="",
+            accountcode="",
+            destination="1", dcontext="default", callerid="",
+            channel="Local/1 at default-.*", dchannel="",
+            lastapp="Echo", lastarg="",
+            disposition="ANSWERED", amaflags="DOCUMENTATION",
+        ))
+
+def main():
+    test = CDRUserFieldTest()
+    test.start_asterisk()
+    reactor.run()
+    test.stop_asterisk()
+    return test.results()
+
+if __name__ == '__main__':
+    sys.exit(main())
+
+# vim: set ts=8 sw=4 sts=4 et ai:

Propchange: asterisk/trunk/tests/cdr/cdr_accountcode/run-test
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/cdr/cdr_accountcode/run-test
------------------------------------------------------------------------------
    svn:executable = *

Propchange: asterisk/trunk/tests/cdr/cdr_accountcode/run-test
------------------------------------------------------------------------------
    svn:keywords = wdoekes 20120420

Propchange: asterisk/trunk/tests/cdr/cdr_accountcode/run-test
------------------------------------------------------------------------------
    svn:mime-type = text/x-python

Added: asterisk/trunk/tests/cdr/cdr_accountcode/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/cdr/cdr_accountcode/test-config.yaml?view=auto&rev=3201
==============================================================================
--- asterisk/trunk/tests/cdr/cdr_accountcode/test-config.yaml (added)
+++ asterisk/trunk/tests/cdr/cdr_accountcode/test-config.yaml Thu Apr 19 17:15:00 2012
@@ -1,0 +1,15 @@
+testinfo:
+    summary: 'Test that Set(CDR(accountcode)=...) works'
+    description: |
+        'Test that the setting the accountcode field in the CDR works
+        and that it is passed to local dials.'
+
+properties:
+    minversion: '1.4'
+    dependencies:
+        - python : 'twisted'
+        - python : 'starpy'
+        - asterisk : 'cdr_csv'
+    tags:
+        - CDR
+        - chan_local

Propchange: asterisk/trunk/tests/cdr/cdr_accountcode/test-config.yaml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/cdr/cdr_accountcode/test-config.yaml
------------------------------------------------------------------------------
    svn:keywords = wdoekes 20120420

Propchange: asterisk/trunk/tests/cdr/cdr_accountcode/test-config.yaml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: asterisk/trunk/tests/cdr/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/cdr/tests.yaml?view=diff&rev=3201&r1=3200&r2=3201
==============================================================================
--- asterisk/trunk/tests/cdr/tests.yaml (original)
+++ asterisk/trunk/tests/cdr/tests.yaml Thu Apr 19 17:15:00 2012
@@ -9,6 +9,7 @@
     - test: 'console_fork_before_dial'
     - test: 'cdr_fork_end_time'
     - test: 'cdr_unanswered_yes'
+    - test: 'cdr_accountcode'
     - test: 'cdr_userfield'
     - test: 'nocdr'
     # Temporarily disabled while failures are debugged




More information about the asterisk-commits mailing list