[asterisk-commits] mmichelson: branch mmichelson/phone-testsuite r3165 - in /asterisk/team/mmich...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 28 16:54:58 CDT 2012


Author: mmichelson
Date: Wed Mar 28 16:54:54 2012
New Revision: 3165

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3165
Log:
Add test events so that we can determine integriy of NOTIFYs being sent.

All of the tests pass. The tests probably need some cleanup to improve code
readability and to be more "pythonic".


Modified:
    asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/multiple_state_change/run-test
    asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/nominal_state_change/run-test
    asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/non_digium_state_change/run-test
    asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/resubscribe/configs/ast1/extensions.conf
    asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/resubscribe/run-test
    asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/resubscribe/sipp/resubscribe.xml

Modified: asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/multiple_state_change/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/multiple_state_change/run-test?view=diff&rev=3165&r1=3164&r2=3165
==============================================================================
--- asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/multiple_state_change/run-test (original)
+++ asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/multiple_state_change/run-test Wed Mar 28 16:54:54 2012
@@ -31,10 +31,12 @@
         TestCase.__init__(self)
         self.create_asterisk()
         self.sipTest = SIPpScenario(TEST_DIR, SIPP_SCENARIO)
-        self.passed = False
+        self.sippPassed = False
+        self.notifyPassed = False
+        self.num_notifies = 0
 
     def sippComplete(self, result):
-        self.passed = True
+        self.sippPassed = True
         reactor.stop()
 
     def originateComplete(self, result):
@@ -50,9 +52,55 @@
         df.addErrback(self.handleOriginateFailure)
         df.addCallback(self.originateComplete)
 
+    def inspectPresence(self, ami, event):
+        # For this test, we expect three of these events.
+        # First one is when the presence is changed to "away"
+        # Second one is when the presence is changed to "available"
+        # Third one is when the subscribption is terminated.
+        # The final two  should have the same values present.
+        self.num_notifies = self.num_notifies + 1
+        if not event.get("state") == "DIGIUM_PRESENCE_SENT":
+            return
+
+        if self.num_notifies > 3:
+            print "Too many NOTIFYs!"
+            self.notifyPassed = False
+            reactor.stop()
+
+        if self.num_notifies is 1:
+            if not event.get("presencestate") == "away":
+                print "Incorrect presencestate value!"
+                self.notifyPassed = False
+                reactor.stop()
+            if not event.get("subtype") == "down the hall":
+                print "Incorrect presence subtype!"
+                self.notifyPassed = False
+                reactor.stop()
+            if not event.get("message") == "Quarterly financial meeting":
+                print "Incorrect presence message!"
+                self.notifyPassed = False
+                reactor.stop()
+        else:
+            if not event.get("presencestate") == "available":
+                print "Incorrect presencestate value!"
+                self.notifyPassed = False
+                reactor.stop()
+            if not event.get("subtype") == "":
+                print "Incorrect presence subtype!"
+                self.notifyPassed = False
+                reactor.stop()
+            if not event.get("message") == "":
+                print "Incorrect presence message!"
+                self.notifyPassed = False
+                reactor.stop()
+
+        if self.num_notifies is 3:
+            self.notifyPassed = True
+
     def ami_connect(self, ami):
         print("AMI CONNECT")
         self.ast[ami.id].cli_exec("sip set debug on")
+        ami.registerEvent("TestEvent", self.inspectPresence)
         self.runSippTest()
 
     def run(self):
@@ -63,7 +111,7 @@
 def main():
     test = MultipleStateChange()
     reactor.run()
-    if not test.passed:
+    if not test.sippPassed or not test.notifyPassed:
         return 1
     return 0
 

Modified: asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/nominal_state_change/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/nominal_state_change/run-test?view=diff&rev=3165&r1=3164&r2=3165
==============================================================================
--- asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/nominal_state_change/run-test (original)
+++ asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/nominal_state_change/run-test Wed Mar 28 16:54:54 2012
@@ -31,10 +31,12 @@
         TestCase.__init__(self)
         self.create_asterisk()
         self.sipTest = SIPpScenario(TEST_DIR, SIPP_SCENARIO)
-        self.passed = False
+        self.sippPassed = False
+        self.notifyPassed = False
+        self.num_notifies = 0
 
     def sippComplete(self, result):
-        self.passed = True
+        self.sippPassed = True
         reactor.stop()
 
     def runSippTest(self):
@@ -44,9 +46,40 @@
         df = self.ami[0].originate(channel = "Local/away at default", application = "Echo")
         df.addErrback(self.handleOriginateFailure)
 
+    def inspectPresence(self, ami, event):
+        # For this test, we expect two of these events.
+        # First one is when the presence is changed.
+        # Second one is when the subscribption is terminated.
+        # Both should have the same values present.
+        self.num_notifies = self.num_notifies + 1
+        if not event.get("state") == "DIGIUM_PRESENCE_SENT":
+            return
+
+        if self.num_notifies > 2:
+            print "Too many NOTIFYs!"
+            self.notifyPassed = False
+            reactor.stop()
+
+        if not event.get("presencestate") == "away":
+            print "Incorrect presencestate value!"
+            self.notifyPassed = False
+            reactor.stop()
+        if not event.get("subtype") == "down the hall":
+            print "Incorrect presence subtype!"
+            self.notifyPassed = False
+            reactor.stop()
+        if not event.get("message") == "Quarterly financial meeting":
+            print "Incorrect presence message!"
+            self.notifyPassed = False
+            reactor.stop()
+
+        if self.num_notifies is 2:
+            self.notifyPassed = True
+
     def ami_connect(self, ami):
         print("AMI CONNECT")
         self.ast[ami.id].cli_exec("sip set debug on")
+        ami.registerEvent("TestEvent", self.inspectPresence)
         self.runSippTest()
 
     def run(self):
@@ -57,7 +90,7 @@
 def main():
     test = NominalStateChange()
     reactor.run()
-    if not test.passed:
+    if not test.sippPassed or not test.notifyPassed:
         return 1
     return 0
 

Modified: asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/non_digium_state_change/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/non_digium_state_change/run-test?view=diff&rev=3165&r1=3164&r2=3165
==============================================================================
--- asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/non_digium_state_change/run-test (original)
+++ asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/non_digium_state_change/run-test Wed Mar 28 16:54:54 2012
@@ -37,10 +37,11 @@
         self.create_asterisk()
         self.sipTest = SIPpScenario(TEST_DIR, SIPP_SUBSCRIBE)
         self.bobTest = SIPpScenario(TEST_DIR, BOB_SCENARIO)
-        self.passed = False
+        self.sippPassed = False
+        self.notifyPassed = True
 
     def testComplete(self, result):
-        self.passed = True
+        self.sippPassed = True
         reactor.stop()
 
     def sippComplete(self, result):
@@ -65,9 +66,18 @@
         df = self.ami[0].originate(channel = "Local/away at default", application = "Echo")
         df.addErrback(self.handleOriginateFailure)
 
+    def inspectPresence(self, ami, event):
+        # For this test, we expect none of these events.
+        # If we get any, we fail.
+        if not event.get("state") == "DIGIUM_PRESENCE_SENT":
+            return
+
+        self.notifyPassed = False
+
     def ami_connect(self, ami):
         print("AMI CONNECT")
         self.ast[ami.id].cli_exec("sip set debug on")
+        self.ami[0].registerEvent("TestEvent", self.inspectPresence)
         self.ami[0].registerEvent("UserEvent", self.originateComplete)
         self.runSippTest()
 
@@ -79,7 +89,7 @@
 def main():
     test = NominalStateChange()
     reactor.run()
-    if not test.passed:
+    if not test.sippPassed or not test.notifyPassed:
         return 1
     return 0
 

Modified: asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/resubscribe/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/resubscribe/configs/ast1/extensions.conf?view=diff&rev=3165&r1=3164&r2=3165
==============================================================================
--- asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/resubscribe/configs/ast1/extensions.conf (original)
+++ asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/resubscribe/configs/ast1/extensions.conf Wed Mar 28 16:54:54 2012
@@ -9,4 +9,5 @@
 
 exten => available,1,Answer
 same => n,Set(PRESENCE_STATE(CustomPresence:bob)=available)
+same => n,UserEvent(Presence)
 same => n,Hangup

Modified: asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/resubscribe/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/resubscribe/run-test?view=diff&rev=3165&r1=3164&r2=3165
==============================================================================
--- asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/resubscribe/run-test (original)
+++ asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/resubscribe/run-test Wed Mar 28 16:54:54 2012
@@ -38,22 +38,25 @@
         self.create_asterisk()
         self.sipTestInitial = SIPpScenario(TEST_DIR, SIPP_SCENARIO_INITIAL)
         self.sipTestResubscribe = SIPpScenario(TEST_DIR, SIPP_SCENARIO_RESUBSCRIBE)
-        self.passed = False
-        self.alreadyEvaluatedTestEvent = False
+        self.sippPassed = False
+        self.notifyPassed = False
+        self.num_notifies = 0
 
     def sippComplete(self, result):
         # Okay, we now know that the subscription is terminated. Now let's
         # originate that second call to change the state to 'available'
+        self.ami[0].registerEvent("UserEvent", self.originateComplete)
         df = self.ami[0].originate(channel = "Local/available at default",
                 application = "Echo")
         df.addErrback(self.handleOriginateFailure)
-        df.addCallback(self.originateComplete)
 
     def sippResubscribeComplete(self, result):
-        self.passed = True
+        self.sippPassed = True
         reactor.stop()
 
-    def originateComplete(self, result):
+    def originateComplete(self, ami, event):
+        if not event.get("userevent") == "Presence":
+            return
         # The state has changed to "available". Now start the other
         # SIPP scenario and make sure it gets notified as we expect
         df = self.sipTestResubscribe.run(self)
@@ -66,9 +69,58 @@
         df = self.ami[0].originate(channel = "Local/away at default", application = "Echo")
         df.addErrback(self.handleOriginateFailure)
 
+    def inspectPresence(self, ami, event):
+        # For this test, we expect four of these events.
+        # First one is when the presence is changed to "away"
+        # Second one is when the first subscription is terminated
+        # Third one is when the subscription is re-established.
+        # Fourth one is when the subscription is re-terminated.
+        # The first two and last two should have the same values present.
+        self.num_notifies = self.num_notifies + 1
+        if not event.get("state") == "DIGIUM_PRESENCE_SENT":
+            return
+
+        print("Got a NOTIFY")
+
+        if self.num_notifies > 4:
+            print "Too many NOTIFYs!"
+            self.notifyPassed = False
+            reactor.stop()
+
+        if self.num_notifies < 3:
+            if not event.get("presencestate") == "away":
+                print "Incorrect presencestate value!"
+                self.notifyPassed = False
+                reactor.stop()
+            if not event.get("subtype") == "down the hall":
+                print "Incorrect presence subtype!"
+                self.notifyPassed = False
+                reactor.stop()
+            if not event.get("message") == "Quarterly financial meeting":
+                print "Incorrect presence message!"
+                self.notifyPassed = False
+                reactor.stop()
+        else:
+            if not event.get("presencestate") == "available":
+                print "Incorrect presencestate value!"
+                self.notifyPassed = False
+                reactor.stop()
+            if not event.get("subtype") == "":
+                print "Incorrect presence subtype!"
+                self.notifyPassed = False
+                reactor.stop()
+            if not event.get("message") == "":
+                print "Incorrect presence message!"
+                self.notifyPassed = False
+                reactor.stop()
+
+        if self.num_notifies is 4:
+            self.notifyPassed = True
+
     def ami_connect(self, ami):
         print("AMI CONNECT")
         self.ast[ami.id].cli_exec("sip set debug on")
+        ami.registerEvent("TestEvent", self.inspectPresence)
         self.runSippTest()
 
     def run(self):
@@ -79,7 +131,7 @@
 def main():
     test = Resubscribe()
     reactor.run()
-    if not test.passed:
+    if not test.sippPassed or not test.notifyPassed:
         return 1
     return 0
 

Modified: asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/resubscribe/sipp/resubscribe.xml
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/resubscribe/sipp/resubscribe.xml?view=diff&rev=3165&r1=3164&r2=3165
==============================================================================
--- asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/resubscribe/sipp/resubscribe.xml (original)
+++ asterisk/team/mmichelson/phone-testsuite/tests/channels/SIP/sip_custom_presence/resubscribe/sipp/resubscribe.xml Wed Mar 28 16:54:54 2012
@@ -62,7 +62,7 @@
       SIP/2.0 200 OK
       [last_Via:]
       [last_From:]
-      [last_To:];tag=[pid]SIPpTag01[call_number]
+      [last_To:]
       [last_Call-ID:]
       [last_CSeq:]
       Contact: <sip:[local_ip]:[local_port];transport=[transport]>
@@ -95,6 +95,24 @@
 
   <recv response="200" crlf="true" />
 
+  <!-- NOTIFY upon subscription termination -->
+  <recv request="NOTIFY" crlf="true" />
+
+  <send>
+    <![CDATA[
+
+      SIP/2.0 200 OK
+      [last_Via:]
+      [last_From:]
+      [last_To:]
+      [last_Call-ID:]
+      [last_CSeq:]
+      Contact: <sip:[local_ip]:[local_port];transport=[transport]>
+      Content-Length: 0
+
+    ]]>
+  </send>
+
   <!-- definition of the response time repartition table (unit is ms)   -->
   <ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>
 




More information about the asterisk-commits mailing list