<p>Friendly Automation <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/testsuite/+/11284">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">testsuite: Add tests for mailbox polling.<br><br>Added five new tests for mailbox polling:<br>- Polling of a single mailbox<br>- Polling of multiple mailboxes<br>- Polling a single mailbox with multiple subscriptions<br>- Polling when no mailboxes have subscriptions<br>- Polling before and after an endpoint unregisters<br><br>Change-Id: Id3a40527624c094e253d56ee2df5381b03b22169<br>---<br>A tests/apps/voicemail/polling/poll_multiple_mailboxes/configs/ast1/pjsip.conf<br>A tests/apps/voicemail/polling/poll_multiple_mailboxes/configs/ast1/voicemail.conf<br>A tests/apps/voicemail/polling/poll_multiple_mailboxes/run-test<br>A tests/apps/voicemail/polling/poll_multiple_mailboxes/test-config.yaml<br>A tests/apps/voicemail/polling/poll_no_subs/configs/ast1/extensions.conf<br>A tests/apps/voicemail/polling/poll_no_subs/configs/ast1/voicemail.conf<br>A tests/apps/voicemail/polling/poll_no_subs/run-test<br>A tests/apps/voicemail/polling/poll_no_subs/test-config.yaml<br>A tests/apps/voicemail/polling/poll_same_mailbox/configs/ast1/pjsip.conf<br>A tests/apps/voicemail/polling/poll_same_mailbox/configs/ast1/voicemail.conf<br>A tests/apps/voicemail/polling/poll_same_mailbox/run-test<br>A tests/apps/voicemail/polling/poll_same_mailbox/test-config.yaml<br>A tests/apps/voicemail/polling/poll_single_mailbox/configs/ast1/pjsip.conf<br>A tests/apps/voicemail/polling/poll_single_mailbox/configs/ast1/voicemail.conf<br>A tests/apps/voicemail/polling/poll_single_mailbox/run-test<br>A tests/apps/voicemail/polling/poll_single_mailbox/test-config.yaml<br>A tests/apps/voicemail/polling/poll_sub_unsub/configs/ast1/extensions.conf<br>A tests/apps/voicemail/polling/poll_sub_unsub/configs/ast1/pjsip.conf<br>A tests/apps/voicemail/polling/poll_sub_unsub/configs/ast1/voicemail.conf<br>A tests/apps/voicemail/polling/poll_sub_unsub/run-test<br>A tests/apps/voicemail/polling/poll_sub_unsub/sipp/register.xml<br>A tests/apps/voicemail/polling/poll_sub_unsub/sipp/unregister.xml<br>A tests/apps/voicemail/polling/poll_sub_unsub/test-config.yaml<br>A tests/apps/voicemail/polling/tests.yaml<br>M tests/apps/voicemail/tests.yaml<br>25 files changed, 812 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/tests/apps/voicemail/polling/poll_multiple_mailboxes/configs/ast1/pjsip.conf b/tests/apps/voicemail/polling/poll_multiple_mailboxes/configs/ast1/pjsip.conf</span><br><span>new file mode 100644</span><br><span>index 0000000..3bffe84</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_multiple_mailboxes/configs/ast1/pjsip.conf</span><br><span>@@ -0,0 +1,51 @@</span><br><span style="color: hsl(120, 100%, 40%);">+[dummy-transport]</span><br><span style="color: hsl(120, 100%, 40%);">+type=transport</span><br><span style="color: hsl(120, 100%, 40%);">+bind=0.0.0.0</span><br><span style="color: hsl(120, 100%, 40%);">+protocol=udp</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[aor](!)</span><br><span style="color: hsl(120, 100%, 40%);">+type=aor</span><br><span style="color: hsl(120, 100%, 40%);">+max_contacts=1</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[auth](!)</span><br><span style="color: hsl(120, 100%, 40%);">+type=auth</span><br><span style="color: hsl(120, 100%, 40%);">+auth_type=userpass</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[endpoint](!)</span><br><span style="color: hsl(120, 100%, 40%);">+type=endpoint</span><br><span style="color: hsl(120, 100%, 40%);">+allow=!all,ulaw</span><br><span style="color: hsl(120, 100%, 40%);">+transport=dummy-transport</span><br><span style="color: hsl(120, 100%, 40%);">+context=default</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[1234](aor)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[1234](auth)</span><br><span style="color: hsl(120, 100%, 40%);">+username=1234</span><br><span style="color: hsl(120, 100%, 40%);">+password=1234</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[1234](endpoint)</span><br><span style="color: hsl(120, 100%, 40%);">+auth=1234</span><br><span style="color: hsl(120, 100%, 40%);">+aors=1234</span><br><span style="color: hsl(120, 100%, 40%);">+mailboxes=1234@default</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[5678](aor)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[5678](auth)</span><br><span style="color: hsl(120, 100%, 40%);">+username=5678</span><br><span style="color: hsl(120, 100%, 40%);">+password=5678</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[5678](endpoint)</span><br><span style="color: hsl(120, 100%, 40%);">+auth=5678</span><br><span style="color: hsl(120, 100%, 40%);">+aors=5678</span><br><span style="color: hsl(120, 100%, 40%);">+mailboxes=5678@default</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[9999](aor)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[9999](auth)</span><br><span style="color: hsl(120, 100%, 40%);">+username=9999</span><br><span style="color: hsl(120, 100%, 40%);">+password=9999</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[9999](endpoint)</span><br><span style="color: hsl(120, 100%, 40%);">+auth=9999</span><br><span style="color: hsl(120, 100%, 40%);">+aors=9999</span><br><span style="color: hsl(120, 100%, 40%);">+mailboxes=9999@default</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_multiple_mailboxes/configs/ast1/voicemail.conf b/tests/apps/voicemail/polling/poll_multiple_mailboxes/configs/ast1/voicemail.conf</span><br><span>new file mode 100644</span><br><span>index 0000000..489a7a3</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_multiple_mailboxes/configs/ast1/voicemail.conf</span><br><span>@@ -0,0 +1,6 @@</span><br><span style="color: hsl(120, 100%, 40%);">+; Voicemail Configuration</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[general]</span><br><span style="color: hsl(120, 100%, 40%);">+format = ulaw</span><br><span style="color: hsl(120, 100%, 40%);">+pollmailboxes=yes</span><br><span style="color: hsl(120, 100%, 40%);">+pollfreq=2</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_multiple_mailboxes/run-test b/tests/apps/voicemail/polling/poll_multiple_mailboxes/run-test</span><br><span>new file mode 100755</span><br><span>index 0000000..4db0314</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_multiple_mailboxes/run-test</span><br><span>@@ -0,0 +1,98 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#!/usr/bin/env python</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+'''</span><br><span style="color: hsl(120, 100%, 40%);">+Copyright (C) 2019, Sangoma Technologies Corporation</span><br><span style="color: hsl(120, 100%, 40%);">+Ben Ford <bford@digium.com></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+This program is free software, distributed under the terms of</span><br><span style="color: hsl(120, 100%, 40%);">+the GNU General Public License Version 2.</span><br><span style="color: hsl(120, 100%, 40%);">+'''</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+import sys</span><br><span style="color: hsl(120, 100%, 40%);">+import logging</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+from asterisk.asterisk import Asterisk</span><br><span style="color: hsl(120, 100%, 40%);">+from asterisk.test_case import TestCase</span><br><span style="color: hsl(120, 100%, 40%);">+from asterisk.voicemail import VoiceMailMailboxManagement</span><br><span style="color: hsl(120, 100%, 40%);">+from twisted.internet import reactor</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+LOGGER = logging.getLogger(__name__)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+class PollingTest(TestCase):</span><br><span style="color: hsl(120, 100%, 40%);">+ def __init__(self):</span><br><span style="color: hsl(120, 100%, 40%);">+ TestCase.__init__(self)</span><br><span style="color: hsl(120, 100%, 40%);">+ self.passed = False</span><br><span style="color: hsl(120, 100%, 40%);">+ self.flags = 0</span><br><span style="color: hsl(120, 100%, 40%);">+ self.create_asterisk()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def stop_test(self, passed=False):</span><br><span style="color: hsl(120, 100%, 40%);">+ self.passed = passed</span><br><span style="color: hsl(120, 100%, 40%);">+ reactor.stop()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def handle_message_waiting(self, ami, event):</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ mailbox = event.get("mailbox")</span><br><span style="color: hsl(120, 100%, 40%);">+ old = int(event.get("old"))</span><br><span style="color: hsl(120, 100%, 40%);">+ new = int(event.get("new"))</span><br><span style="color: hsl(120, 100%, 40%);">+ waiting = int(event.get("waiting"))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ # Conditions:</span><br><span style="color: hsl(120, 100%, 40%);">+ # - If INBOX count is 1, then we need to remove the voicemail and set flag</span><br><span style="color: hsl(120, 100%, 40%);">+ # - If INBOX count is 0, just set flag</span><br><span style="color: hsl(120, 100%, 40%);">+ # - Once flags reaches 2^6-1 (111111), we've met all conditions</span><br><span style="color: hsl(120, 100%, 40%);">+ if new == 1 and waiting == 1:</span><br><span style="color: hsl(120, 100%, 40%);">+ if old != 0:</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.error("Expected 'Old' to be 0")</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test()</span><br><span style="color: hsl(120, 100%, 40%);">+ if mailbox == "1234@default":</span><br><span style="color: hsl(120, 100%, 40%);">+ self.flags |= 1</span><br><span style="color: hsl(120, 100%, 40%);">+ elif mailbox == "5678@default":</span><br><span style="color: hsl(120, 100%, 40%);">+ self.flags |= 2</span><br><span style="color: hsl(120, 100%, 40%);">+ elif mailbox == "9999@default":</span><br><span style="color: hsl(120, 100%, 40%);">+ self.flags |= 4</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ data = mailbox.split("@")</span><br><span style="color: hsl(120, 100%, 40%);">+ mailbox = data[0]</span><br><span style="color: hsl(120, 100%, 40%);">+ if not self.voicemailManager.remove_mailbox("default", mailbox):</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.error("Failed to remove voicemail for mailbox {0}".format(mailbox))</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ elif new == 0 and waiting == 0 and old == 0:</span><br><span style="color: hsl(120, 100%, 40%);">+ if mailbox == "1234@default":</span><br><span style="color: hsl(120, 100%, 40%);">+ self.flags |= 8</span><br><span style="color: hsl(120, 100%, 40%);">+ elif mailbox == "5678@default":</span><br><span style="color: hsl(120, 100%, 40%);">+ self.flags |= 16</span><br><span style="color: hsl(120, 100%, 40%);">+ elif mailbox == "9999@default":</span><br><span style="color: hsl(120, 100%, 40%);">+ self.flags |= 32</span><br><span style="color: hsl(120, 100%, 40%);">+ </span><br><span style="color: hsl(120, 100%, 40%);">+ # self.flags should be 63 (2^6-1 == 111111 in binary)</span><br><span style="color: hsl(120, 100%, 40%);">+ if self.flags == 63:</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test(True)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def ami_connect(self, ami):</span><br><span style="color: hsl(120, 100%, 40%);">+ ami.registerEvent("MessageWaiting", self.handle_message_waiting)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ mailboxes = ["1234", "5678", "9999"]</span><br><span style="color: hsl(120, 100%, 40%);">+ self.voicemailManager = VoiceMailMailboxManagement(self.ast[0])</span><br><span style="color: hsl(120, 100%, 40%);">+ for mailbox in mailboxes:</span><br><span style="color: hsl(120, 100%, 40%);">+ self.voicemailManager.create_mailbox("default", mailbox, True)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ formats = ["ulaw"]</span><br><span style="color: hsl(120, 100%, 40%);">+ for mailbox in mailboxes:</span><br><span style="color: hsl(120, 100%, 40%);">+ if not self.voicemailManager.create_dummy_voicemail("default", mailbox, VoiceMailMailboxManagement.inbox_folder_name, 1, formats):</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.error("Failed to create voicemail for mailbox {0}".format(mailbox))</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def run(self):</span><br><span style="color: hsl(120, 100%, 40%);">+ TestCase.run(self)</span><br><span style="color: hsl(120, 100%, 40%);">+ self.create_ami_factory()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def main():</span><br><span style="color: hsl(120, 100%, 40%);">+ test = PollingTest()</span><br><span style="color: hsl(120, 100%, 40%);">+ reactor.run()</span><br><span style="color: hsl(120, 100%, 40%);">+ if not test.passed:</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+if __name__ == "__main__":</span><br><span style="color: hsl(120, 100%, 40%);">+ sys.exit(main() or 0)</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_multiple_mailboxes/test-config.yaml b/tests/apps/voicemail/polling/poll_multiple_mailboxes/test-config.yaml</span><br><span>new file mode 100644</span><br><span>index 0000000..cfedd6d</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_multiple_mailboxes/test-config.yaml</span><br><span>@@ -0,0 +1,19 @@</span><br><span style="color: hsl(120, 100%, 40%);">+testinfo:</span><br><span style="color: hsl(120, 100%, 40%);">+ summary: 'Test polling of multiple mailboxes'</span><br><span style="color: hsl(120, 100%, 40%);">+ description: |</span><br><span style="color: hsl(120, 100%, 40%);">+ This test verifies that polling multiple mailboxes works as intended. A fake</span><br><span style="color: hsl(120, 100%, 40%);">+ message is added to various mailboxes that triggers events when the polling</span><br><span style="color: hsl(120, 100%, 40%);">+ frequency timeout is reached, which will cause the test to then remove the</span><br><span style="color: hsl(120, 100%, 40%);">+ messages and end the test.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+properties:</span><br><span style="color: hsl(120, 100%, 40%);">+ buildoption: 'TEST_FRAMEWORK'</span><br><span style="color: hsl(120, 100%, 40%);">+ dependencies:</span><br><span style="color: hsl(120, 100%, 40%);">+ - python : 'twisted'</span><br><span style="color: hsl(120, 100%, 40%);">+ - python : 'starpy'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk: 'app_voicemail'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk: 'chan_pjsip'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk: 'res_pjsip'</span><br><span style="color: hsl(120, 100%, 40%);">+ tags:</span><br><span style="color: hsl(120, 100%, 40%);">+ - voicemail</span><br><span style="color: hsl(120, 100%, 40%);">+ - apps</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_no_subs/configs/ast1/extensions.conf b/tests/apps/voicemail/polling/poll_no_subs/configs/ast1/extensions.conf</span><br><span>new file mode 100644</span><br><span>index 0000000..eed7ea0</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_no_subs/configs/ast1/extensions.conf</span><br><span>@@ -0,0 +1,11 @@</span><br><span style="color: hsl(120, 100%, 40%);">+[default]</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+exten => playback,1,NoOp()</span><br><span style="color: hsl(120, 100%, 40%);">+ same => n,Answer()</span><br><span style="color: hsl(120, 100%, 40%);">+ same => n,Playback(silence/5)</span><br><span style="color: hsl(120, 100%, 40%);">+ same => n,Hangup()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+exten => echo,1,NoOp()</span><br><span style="color: hsl(120, 100%, 40%);">+ same => n,Answer()</span><br><span style="color: hsl(120, 100%, 40%);">+ same => n,Echo()</span><br><span style="color: hsl(120, 100%, 40%);">+ same => n,Hangup()</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_no_subs/configs/ast1/voicemail.conf b/tests/apps/voicemail/polling/poll_no_subs/configs/ast1/voicemail.conf</span><br><span>new file mode 100644</span><br><span>index 0000000..489a7a3</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_no_subs/configs/ast1/voicemail.conf</span><br><span>@@ -0,0 +1,6 @@</span><br><span style="color: hsl(120, 100%, 40%);">+; Voicemail Configuration</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[general]</span><br><span style="color: hsl(120, 100%, 40%);">+format = ulaw</span><br><span style="color: hsl(120, 100%, 40%);">+pollmailboxes=yes</span><br><span style="color: hsl(120, 100%, 40%);">+pollfreq=2</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_no_subs/run-test b/tests/apps/voicemail/polling/poll_no_subs/run-test</span><br><span>new file mode 100755</span><br><span>index 0000000..0d6a1c9</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_no_subs/run-test</span><br><span>@@ -0,0 +1,79 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#!/usr/bin/env python</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+'''</span><br><span style="color: hsl(120, 100%, 40%);">+Copyright (C) 2019, Sangoma Technologies Corporation</span><br><span style="color: hsl(120, 100%, 40%);">+Ben Ford <bford@digium.com></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+This program is free software, distributed under the terms of</span><br><span style="color: hsl(120, 100%, 40%);">+the GNU General Public License Version 2.</span><br><span style="color: hsl(120, 100%, 40%);">+'''</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+import sys</span><br><span style="color: hsl(120, 100%, 40%);">+import logging</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+from asterisk.asterisk import Asterisk</span><br><span style="color: hsl(120, 100%, 40%);">+from asterisk.test_case import TestCase</span><br><span style="color: hsl(120, 100%, 40%);">+from asterisk.voicemail import VoiceMailMailboxManagement</span><br><span style="color: hsl(120, 100%, 40%);">+from twisted.internet import reactor</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+LOGGER = logging.getLogger(__name__)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+class PollingTest(TestCase):</span><br><span style="color: hsl(120, 100%, 40%);">+ def __init__(self):</span><br><span style="color: hsl(120, 100%, 40%);">+ TestCase.__init__(self)</span><br><span style="color: hsl(120, 100%, 40%);">+ self.passed = False</span><br><span style="color: hsl(120, 100%, 40%);">+ self.create_asterisk()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def stop_test(self, passed=False):</span><br><span style="color: hsl(120, 100%, 40%);">+ self.passed = passed</span><br><span style="color: hsl(120, 100%, 40%);">+ # Sometimes the reactor has already stopped, we only care if the test passed</span><br><span style="color: hsl(120, 100%, 40%);">+ try:</span><br><span style="color: hsl(120, 100%, 40%);">+ reactor.stop()</span><br><span style="color: hsl(120, 100%, 40%);">+ except Exception as e:</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.info("Error while stopping reactor: '{0}'".format(e))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def handle_message_waiting(self, ami, event):</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.error("Got a MessageWaiting event we weren't expecting!")</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def handle_hangup(self, ami, event):</span><br><span style="color: hsl(120, 100%, 40%);">+ if "Local/playback@default" in event.get("channel"):</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test(True)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def handle_originate_failure(self, reason):</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.error("Failed to originate call! Reason: {0}".format(reason))</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def ami_connect(self, ami):</span><br><span style="color: hsl(120, 100%, 40%);">+ ami.registerEvent("MessageWaiting", self.handle_message_waiting)</span><br><span style="color: hsl(120, 100%, 40%);">+ ami.registerEvent("Hangup", self.handle_hangup)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ self.voicemailManager = VoiceMailMailboxManagement(self.ast[0])</span><br><span style="color: hsl(120, 100%, 40%);">+ self.voicemailManager.create_mailbox("default", "1234", True)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ formats = ["ulaw"]</span><br><span style="color: hsl(120, 100%, 40%);">+ if not self.voicemailManager.create_dummy_voicemail("default", "1234", VoiceMailMailboxManagement.inbox_folder_name, 1, formats):</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.error("Failed to create voicemail")</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ variable = {}</span><br><span style="color: hsl(120, 100%, 40%);">+ ami.originate(channel="Local/playback@default",</span><br><span style="color: hsl(120, 100%, 40%);">+ context="default",</span><br><span style="color: hsl(120, 100%, 40%);">+ exten="echo",</span><br><span style="color: hsl(120, 100%, 40%);">+ priority="1",</span><br><span style="color: hsl(120, 100%, 40%);">+ variable=variable</span><br><span style="color: hsl(120, 100%, 40%);">+ ).addErrback(self.handle_originate_failure)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def run(self):</span><br><span style="color: hsl(120, 100%, 40%);">+ TestCase.run(self)</span><br><span style="color: hsl(120, 100%, 40%);">+ self.create_ami_factory()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def main():</span><br><span style="color: hsl(120, 100%, 40%);">+ test = PollingTest()</span><br><span style="color: hsl(120, 100%, 40%);">+ reactor.run()</span><br><span style="color: hsl(120, 100%, 40%);">+ if not test.passed:</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+if __name__ == "__main__":</span><br><span style="color: hsl(120, 100%, 40%);">+ sys.exit(main() or 0)</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_no_subs/test-config.yaml b/tests/apps/voicemail/polling/poll_no_subs/test-config.yaml</span><br><span>new file mode 100644</span><br><span>index 0000000..3f8f08d</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_no_subs/test-config.yaml</span><br><span>@@ -0,0 +1,20 @@</span><br><span style="color: hsl(120, 100%, 40%);">+testinfo:</span><br><span style="color: hsl(120, 100%, 40%);">+ summary: 'Test polling of mailboxes with no subscriptions'</span><br><span style="color: hsl(120, 100%, 40%);">+ description: |</span><br><span style="color: hsl(120, 100%, 40%);">+ This test verifies that polling a mailbox with no subscriptions does</span><br><span style="color: hsl(120, 100%, 40%);">+ not trigger a notification that a change was made. The test will end</span><br><span style="color: hsl(120, 100%, 40%);">+ after a short playback, and if an event for mailbox polling is detected</span><br><span style="color: hsl(120, 100%, 40%);">+ during that time, the test will fail.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+properties:</span><br><span style="color: hsl(120, 100%, 40%);">+ buildoption: 'TEST_FRAMEWORK'</span><br><span style="color: hsl(120, 100%, 40%);">+ dependencies:</span><br><span style="color: hsl(120, 100%, 40%);">+ - python : 'twisted'</span><br><span style="color: hsl(120, 100%, 40%);">+ - python : 'starpy'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk: 'app_playback'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk: 'app_voicemail'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk: 'chan_pjsip'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk: 'res_pjsip'</span><br><span style="color: hsl(120, 100%, 40%);">+ tags:</span><br><span style="color: hsl(120, 100%, 40%);">+ - voicemail</span><br><span style="color: hsl(120, 100%, 40%);">+ - apps</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_same_mailbox/configs/ast1/pjsip.conf b/tests/apps/voicemail/polling/poll_same_mailbox/configs/ast1/pjsip.conf</span><br><span>new file mode 100644</span><br><span>index 0000000..4c7b3e1</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_same_mailbox/configs/ast1/pjsip.conf</span><br><span>@@ -0,0 +1,49 @@</span><br><span style="color: hsl(120, 100%, 40%);">+[dummy-transport]</span><br><span style="color: hsl(120, 100%, 40%);">+type=transport</span><br><span style="color: hsl(120, 100%, 40%);">+bind=0.0.0.0</span><br><span style="color: hsl(120, 100%, 40%);">+protocol=udp</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[aor](!)</span><br><span style="color: hsl(120, 100%, 40%);">+type=aor</span><br><span style="color: hsl(120, 100%, 40%);">+max_contacts=1</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[auth](!)</span><br><span style="color: hsl(120, 100%, 40%);">+type=auth</span><br><span style="color: hsl(120, 100%, 40%);">+auth_type=userpass</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[endpoint](!)</span><br><span style="color: hsl(120, 100%, 40%);">+type=endpoint</span><br><span style="color: hsl(120, 100%, 40%);">+allow=!all,ulaw</span><br><span style="color: hsl(120, 100%, 40%);">+transport=dummy-transport</span><br><span style="color: hsl(120, 100%, 40%);">+context=default</span><br><span style="color: hsl(120, 100%, 40%);">+mailboxes=1234@default</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[1234](aor)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[1234](auth)</span><br><span style="color: hsl(120, 100%, 40%);">+username=1234</span><br><span style="color: hsl(120, 100%, 40%);">+password=1234</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[1234](endpoint)</span><br><span style="color: hsl(120, 100%, 40%);">+auth=1234</span><br><span style="color: hsl(120, 100%, 40%);">+aors=1234</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[5678](aor)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[5678](auth)</span><br><span style="color: hsl(120, 100%, 40%);">+username=5678</span><br><span style="color: hsl(120, 100%, 40%);">+password=5678</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[5678](endpoint)</span><br><span style="color: hsl(120, 100%, 40%);">+auth=5678</span><br><span style="color: hsl(120, 100%, 40%);">+aors=5678</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[9999](aor)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[9999](auth)</span><br><span style="color: hsl(120, 100%, 40%);">+username=9999</span><br><span style="color: hsl(120, 100%, 40%);">+password=9999</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[9999](endpoint)</span><br><span style="color: hsl(120, 100%, 40%);">+auth=9999</span><br><span style="color: hsl(120, 100%, 40%);">+aors=9999</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_same_mailbox/configs/ast1/voicemail.conf b/tests/apps/voicemail/polling/poll_same_mailbox/configs/ast1/voicemail.conf</span><br><span>new file mode 100644</span><br><span>index 0000000..489a7a3</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_same_mailbox/configs/ast1/voicemail.conf</span><br><span>@@ -0,0 +1,6 @@</span><br><span style="color: hsl(120, 100%, 40%);">+; Voicemail Configuration</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[general]</span><br><span style="color: hsl(120, 100%, 40%);">+format = ulaw</span><br><span style="color: hsl(120, 100%, 40%);">+pollmailboxes=yes</span><br><span style="color: hsl(120, 100%, 40%);">+pollfreq=2</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_same_mailbox/run-test b/tests/apps/voicemail/polling/poll_same_mailbox/run-test</span><br><span>new file mode 100755</span><br><span>index 0000000..78d0773</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_same_mailbox/run-test</span><br><span>@@ -0,0 +1,87 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#!/usr/bin/env python</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+'''</span><br><span style="color: hsl(120, 100%, 40%);">+Copyright (C) 2019, Sangoma Technologies Corporation</span><br><span style="color: hsl(120, 100%, 40%);">+Ben Ford <bford@digium.com></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+This program is free software, distributed under the terms of</span><br><span style="color: hsl(120, 100%, 40%);">+the GNU General Public License Version 2.</span><br><span style="color: hsl(120, 100%, 40%);">+'''</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+import sys</span><br><span style="color: hsl(120, 100%, 40%);">+import logging</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+from asterisk.asterisk import Asterisk</span><br><span style="color: hsl(120, 100%, 40%);">+from asterisk.test_case import TestCase</span><br><span style="color: hsl(120, 100%, 40%);">+from asterisk.voicemail import VoiceMailMailboxManagement</span><br><span style="color: hsl(120, 100%, 40%);">+from twisted.internet import reactor</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+LOGGER = logging.getLogger(__name__)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+class PollingTest(TestCase):</span><br><span style="color: hsl(120, 100%, 40%);">+ def __init__(self):</span><br><span style="color: hsl(120, 100%, 40%);">+ TestCase.__init__(self)</span><br><span style="color: hsl(120, 100%, 40%);">+ self.passed = False</span><br><span style="color: hsl(120, 100%, 40%);">+ self.counter = 0</span><br><span style="color: hsl(120, 100%, 40%);">+ self.create_asterisk()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def stop_test(self, passed=False):</span><br><span style="color: hsl(120, 100%, 40%);">+ self.passed = passed</span><br><span style="color: hsl(120, 100%, 40%);">+ reactor.stop()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def handle_message_waiting(self, ami, event):</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if event.get("mailbox") != "1234@default":</span><br><span style="color: hsl(120, 100%, 40%);">+ return</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ old = int(event.get("old"))</span><br><span style="color: hsl(120, 100%, 40%);">+ new = int(event.get("new"))</span><br><span style="color: hsl(120, 100%, 40%);">+ waiting = int(event.get("waiting"))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ # Conditions:</span><br><span style="color: hsl(120, 100%, 40%);">+ # - If INBOX count is 1, increment self.counter</span><br><span style="color: hsl(120, 100%, 40%);">+ # - When self.counter reaches 3, we got all 3 events we expected,</span><br><span style="color: hsl(120, 100%, 40%);">+ # so delete the voicemail</span><br><span style="color: hsl(120, 100%, 40%);">+ # - INBOX count should only be 0 after we delete the voicemail, so</span><br><span style="color: hsl(120, 100%, 40%);">+ # increment the counter here to end the test</span><br><span style="color: hsl(120, 100%, 40%);">+ # - Once self.counter reaches 3 after removing the voicemail, we've</span><br><span style="color: hsl(120, 100%, 40%);">+ # received all the events, so stop the test</span><br><span style="color: hsl(120, 100%, 40%);">+ if new == 1 and waiting == 1:</span><br><span style="color: hsl(120, 100%, 40%);">+ if old != 0:</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.error("Expected 'Old' to be 0")</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test()</span><br><span style="color: hsl(120, 100%, 40%);">+ self.counter += 1</span><br><span style="color: hsl(120, 100%, 40%);">+ if self.counter == 3:</span><br><span style="color: hsl(120, 100%, 40%);">+ self.counter = 0</span><br><span style="color: hsl(120, 100%, 40%);">+ if not self.voicemailManager.remove_mailbox("default", "1234"):</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.error("Failed to remove voicemail")</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test()</span><br><span style="color: hsl(120, 100%, 40%);">+ elif new == 0 and waiting == 0 and old == 0:</span><br><span style="color: hsl(120, 100%, 40%);">+ self.counter += 1</span><br><span style="color: hsl(120, 100%, 40%);">+ if self.counter == 3:</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test(True)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def ami_connect(self, ami):</span><br><span style="color: hsl(120, 100%, 40%);">+ ami.registerEvent("MessageWaiting", self.handle_message_waiting)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ self.voicemailManager = VoiceMailMailboxManagement(self.ast[0])</span><br><span style="color: hsl(120, 100%, 40%);">+ self.voicemailManager.create_mailbox("default", "1234", True)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ formats = ["ulaw"]</span><br><span style="color: hsl(120, 100%, 40%);">+ if not self.voicemailManager.create_dummy_voicemail("default", "1234", VoiceMailMailboxManagement.inbox_folder_name, 1, formats):</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.error("Failed to create voicemail")</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def run(self):</span><br><span style="color: hsl(120, 100%, 40%);">+ TestCase.run(self)</span><br><span style="color: hsl(120, 100%, 40%);">+ self.create_ami_factory()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def main():</span><br><span style="color: hsl(120, 100%, 40%);">+ test = PollingTest()</span><br><span style="color: hsl(120, 100%, 40%);">+ reactor.run()</span><br><span style="color: hsl(120, 100%, 40%);">+ if not test.passed:</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+if __name__ == "__main__":</span><br><span style="color: hsl(120, 100%, 40%);">+ sys.exit(main() or 0)</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_same_mailbox/test-config.yaml b/tests/apps/voicemail/polling/poll_same_mailbox/test-config.yaml</span><br><span>new file mode 100644</span><br><span>index 0000000..fedb1db</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_same_mailbox/test-config.yaml</span><br><span>@@ -0,0 +1,18 @@</span><br><span style="color: hsl(120, 100%, 40%);">+testinfo:</span><br><span style="color: hsl(120, 100%, 40%);">+ summary: 'Test polling of a single mailbox with multiple subscriptions'</span><br><span style="color: hsl(120, 100%, 40%);">+ description: |</span><br><span style="color: hsl(120, 100%, 40%);">+ This test verifies that polling a single mailbox with multiple subscriptions</span><br><span style="color: hsl(120, 100%, 40%);">+ works as intended. The test will wait for the given number of notifications</span><br><span style="color: hsl(120, 100%, 40%);">+ to occur, then remove the voicemail and end the test.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+properties:</span><br><span style="color: hsl(120, 100%, 40%);">+ buildoption: 'TEST_FRAMEWORK'</span><br><span style="color: hsl(120, 100%, 40%);">+ dependencies:</span><br><span style="color: hsl(120, 100%, 40%);">+ - python : 'twisted'</span><br><span style="color: hsl(120, 100%, 40%);">+ - python : 'starpy'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk: 'app_voicemail'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk: 'chan_pjsip'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk: 'res_pjsip'</span><br><span style="color: hsl(120, 100%, 40%);">+ tags:</span><br><span style="color: hsl(120, 100%, 40%);">+ - voicemail</span><br><span style="color: hsl(120, 100%, 40%);">+ - apps</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_single_mailbox/configs/ast1/pjsip.conf b/tests/apps/voicemail/polling/poll_single_mailbox/configs/ast1/pjsip.conf</span><br><span>new file mode 100644</span><br><span>index 0000000..dce5f75</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_single_mailbox/configs/ast1/pjsip.conf</span><br><span>@@ -0,0 +1,23 @@</span><br><span style="color: hsl(120, 100%, 40%);">+[dummy-transport]</span><br><span style="color: hsl(120, 100%, 40%);">+type=transport</span><br><span style="color: hsl(120, 100%, 40%);">+bind=0.0.0.0</span><br><span style="color: hsl(120, 100%, 40%);">+protocol=udp</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[1234]</span><br><span style="color: hsl(120, 100%, 40%);">+type=aor</span><br><span style="color: hsl(120, 100%, 40%);">+max_contacts=1</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[1234]</span><br><span style="color: hsl(120, 100%, 40%);">+type=auth</span><br><span style="color: hsl(120, 100%, 40%);">+auth_type=userpass</span><br><span style="color: hsl(120, 100%, 40%);">+username=1234</span><br><span style="color: hsl(120, 100%, 40%);">+password=1234</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[1234]</span><br><span style="color: hsl(120, 100%, 40%);">+type=endpoint</span><br><span style="color: hsl(120, 100%, 40%);">+allow=!all,ulaw</span><br><span style="color: hsl(120, 100%, 40%);">+auth=1234</span><br><span style="color: hsl(120, 100%, 40%);">+aors=1234</span><br><span style="color: hsl(120, 100%, 40%);">+transport=dummy-transport</span><br><span style="color: hsl(120, 100%, 40%);">+context=default</span><br><span style="color: hsl(120, 100%, 40%);">+mailboxes=1234@default</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_single_mailbox/configs/ast1/voicemail.conf b/tests/apps/voicemail/polling/poll_single_mailbox/configs/ast1/voicemail.conf</span><br><span>new file mode 100644</span><br><span>index 0000000..489a7a3</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_single_mailbox/configs/ast1/voicemail.conf</span><br><span>@@ -0,0 +1,6 @@</span><br><span style="color: hsl(120, 100%, 40%);">+; Voicemail Configuration</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[general]</span><br><span style="color: hsl(120, 100%, 40%);">+format = ulaw</span><br><span style="color: hsl(120, 100%, 40%);">+pollmailboxes=yes</span><br><span style="color: hsl(120, 100%, 40%);">+pollfreq=2</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_single_mailbox/run-test b/tests/apps/voicemail/polling/poll_single_mailbox/run-test</span><br><span>new file mode 100755</span><br><span>index 0000000..df85667</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_single_mailbox/run-test</span><br><span>@@ -0,0 +1,81 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#!/usr/bin/env python</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+'''</span><br><span style="color: hsl(120, 100%, 40%);">+Copyright (C) 2019, Sangoma Technologies Corporation</span><br><span style="color: hsl(120, 100%, 40%);">+Ben Ford <bford@digium.com></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+This program is free software, distributed under the terms of</span><br><span style="color: hsl(120, 100%, 40%);">+the GNU General Public License Version 2.</span><br><span style="color: hsl(120, 100%, 40%);">+'''</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+import sys</span><br><span style="color: hsl(120, 100%, 40%);">+import logging</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+from asterisk.asterisk import Asterisk</span><br><span style="color: hsl(120, 100%, 40%);">+from asterisk.test_case import TestCase</span><br><span style="color: hsl(120, 100%, 40%);">+from asterisk.voicemail import VoiceMailMailboxManagement</span><br><span style="color: hsl(120, 100%, 40%);">+from twisted.internet import reactor</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+LOGGER = logging.getLogger(__name__)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+class PollingTest(TestCase):</span><br><span style="color: hsl(120, 100%, 40%);">+ def __init__(self):</span><br><span style="color: hsl(120, 100%, 40%);">+ TestCase.__init__(self)</span><br><span style="color: hsl(120, 100%, 40%);">+ self.passed = False</span><br><span style="color: hsl(120, 100%, 40%);">+ self.test_phase = 1</span><br><span style="color: hsl(120, 100%, 40%);">+ self.create_asterisk()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def stop_test(self, passed=False):</span><br><span style="color: hsl(120, 100%, 40%);">+ self.passed = passed</span><br><span style="color: hsl(120, 100%, 40%);">+ reactor.stop()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def handle_message_waiting(self, ami, event):</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if event.get("mailbox") != "1234@default":</span><br><span style="color: hsl(120, 100%, 40%);">+ return</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ old = int(event.get("old"))</span><br><span style="color: hsl(120, 100%, 40%);">+ new = int(event.get("new"))</span><br><span style="color: hsl(120, 100%, 40%);">+ waiting = int(event.get("waiting"))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ # Phase 1: We are looking for an INBOX count of 1</span><br><span style="color: hsl(120, 100%, 40%);">+ if self.test_phase == 1:</span><br><span style="color: hsl(120, 100%, 40%);">+ if new != 1 or waiting != 1:</span><br><span style="color: hsl(120, 100%, 40%);">+ return</span><br><span style="color: hsl(120, 100%, 40%);">+ if old != 0:</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test()</span><br><span style="color: hsl(120, 100%, 40%);">+ self.test_phase = 2</span><br><span style="color: hsl(120, 100%, 40%);">+ if not self.voicemailManager.remove_mailbox("default", "1234"):</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.error("Failed to remove voicemail")</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test()</span><br><span style="color: hsl(120, 100%, 40%);">+ # Phase 2: We don't expect there to be any messages</span><br><span style="color: hsl(120, 100%, 40%);">+ elif self.test_phase == 2:</span><br><span style="color: hsl(120, 100%, 40%);">+ if new != 0 or old != 0 or waiting != 0:</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.error("Expected empty mailbox")</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test()</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test(True)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def ami_connect(self, ami):</span><br><span style="color: hsl(120, 100%, 40%);">+ ami.registerEvent("MessageWaiting", self.handle_message_waiting)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ self.voicemailManager = VoiceMailMailboxManagement(self.ast[0])</span><br><span style="color: hsl(120, 100%, 40%);">+ self.voicemailManager.create_mailbox("default", "1234", True)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ formats = ["ulaw"]</span><br><span style="color: hsl(120, 100%, 40%);">+ if not self.voicemailManager.create_dummy_voicemail("default", "1234", VoiceMailMailboxManagement.inbox_folder_name, 1, formats):</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.error("Failed to create voicemail")</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def run(self):</span><br><span style="color: hsl(120, 100%, 40%);">+ TestCase.run(self)</span><br><span style="color: hsl(120, 100%, 40%);">+ self.create_ami_factory()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def main():</span><br><span style="color: hsl(120, 100%, 40%);">+ test = PollingTest()</span><br><span style="color: hsl(120, 100%, 40%);">+ reactor.run()</span><br><span style="color: hsl(120, 100%, 40%);">+ if not test.passed:</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+if __name__ == "__main__":</span><br><span style="color: hsl(120, 100%, 40%);">+ sys.exit(main() or 0)</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_single_mailbox/test-config.yaml b/tests/apps/voicemail/polling/poll_single_mailbox/test-config.yaml</span><br><span>new file mode 100644</span><br><span>index 0000000..cd60cb0</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_single_mailbox/test-config.yaml</span><br><span>@@ -0,0 +1,19 @@</span><br><span style="color: hsl(120, 100%, 40%);">+testinfo:</span><br><span style="color: hsl(120, 100%, 40%);">+ summary: 'Test polling of a single mailbox'</span><br><span style="color: hsl(120, 100%, 40%);">+ description: |</span><br><span style="color: hsl(120, 100%, 40%);">+ This test verifies that polling a single mailbox works as intended. A fake</span><br><span style="color: hsl(120, 100%, 40%);">+ message is added to the mailbox that triggers an event when the polling</span><br><span style="color: hsl(120, 100%, 40%);">+ frequency timeout is reached, which will cause the test to then remove the</span><br><span style="color: hsl(120, 100%, 40%);">+ message to end the test.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+properties:</span><br><span style="color: hsl(120, 100%, 40%);">+ buildoption: 'TEST_FRAMEWORK'</span><br><span style="color: hsl(120, 100%, 40%);">+ dependencies:</span><br><span style="color: hsl(120, 100%, 40%);">+ - python : 'twisted'</span><br><span style="color: hsl(120, 100%, 40%);">+ - python : 'starpy'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk: 'app_voicemail'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk: 'chan_pjsip'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk: 'res_pjsip'</span><br><span style="color: hsl(120, 100%, 40%);">+ tags:</span><br><span style="color: hsl(120, 100%, 40%);">+ - voicemail</span><br><span style="color: hsl(120, 100%, 40%);">+ - apps</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_sub_unsub/configs/ast1/extensions.conf b/tests/apps/voicemail/polling/poll_sub_unsub/configs/ast1/extensions.conf</span><br><span>new file mode 100644</span><br><span>index 0000000..eed7ea0</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_sub_unsub/configs/ast1/extensions.conf</span><br><span>@@ -0,0 +1,11 @@</span><br><span style="color: hsl(120, 100%, 40%);">+[default]</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+exten => playback,1,NoOp()</span><br><span style="color: hsl(120, 100%, 40%);">+ same => n,Answer()</span><br><span style="color: hsl(120, 100%, 40%);">+ same => n,Playback(silence/5)</span><br><span style="color: hsl(120, 100%, 40%);">+ same => n,Hangup()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+exten => echo,1,NoOp()</span><br><span style="color: hsl(120, 100%, 40%);">+ same => n,Answer()</span><br><span style="color: hsl(120, 100%, 40%);">+ same => n,Echo()</span><br><span style="color: hsl(120, 100%, 40%);">+ same => n,Hangup()</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_sub_unsub/configs/ast1/pjsip.conf b/tests/apps/voicemail/polling/poll_sub_unsub/configs/ast1/pjsip.conf</span><br><span>new file mode 100644</span><br><span>index 0000000..091bdab</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_sub_unsub/configs/ast1/pjsip.conf</span><br><span>@@ -0,0 +1,16 @@</span><br><span style="color: hsl(120, 100%, 40%);">+[dummy-transport]</span><br><span style="color: hsl(120, 100%, 40%);">+type=transport</span><br><span style="color: hsl(120, 100%, 40%);">+bind=0.0.0.0</span><br><span style="color: hsl(120, 100%, 40%);">+protocol=udp</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[1234]</span><br><span style="color: hsl(120, 100%, 40%);">+type=aor</span><br><span style="color: hsl(120, 100%, 40%);">+max_contacts=1</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[1234]</span><br><span style="color: hsl(120, 100%, 40%);">+type=endpoint</span><br><span style="color: hsl(120, 100%, 40%);">+allow=!all,ulaw</span><br><span style="color: hsl(120, 100%, 40%);">+aors=1234</span><br><span style="color: hsl(120, 100%, 40%);">+transport=dummy-transport</span><br><span style="color: hsl(120, 100%, 40%);">+context=default</span><br><span style="color: hsl(120, 100%, 40%);">+mailboxes=1234@default</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_sub_unsub/configs/ast1/voicemail.conf b/tests/apps/voicemail/polling/poll_sub_unsub/configs/ast1/voicemail.conf</span><br><span>new file mode 100644</span><br><span>index 0000000..489a7a3</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_sub_unsub/configs/ast1/voicemail.conf</span><br><span>@@ -0,0 +1,6 @@</span><br><span style="color: hsl(120, 100%, 40%);">+; Voicemail Configuration</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[general]</span><br><span style="color: hsl(120, 100%, 40%);">+format = ulaw</span><br><span style="color: hsl(120, 100%, 40%);">+pollmailboxes=yes</span><br><span style="color: hsl(120, 100%, 40%);">+pollfreq=2</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_sub_unsub/run-test b/tests/apps/voicemail/polling/poll_sub_unsub/run-test</span><br><span>new file mode 100755</span><br><span>index 0000000..c77827e</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_sub_unsub/run-test</span><br><span>@@ -0,0 +1,123 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#!/usr/bin/env python</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+'''</span><br><span style="color: hsl(120, 100%, 40%);">+Copyright (C) 2019, Sangoma Technologies Corporation</span><br><span style="color: hsl(120, 100%, 40%);">+Ben Ford <bford@digium.com></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+This program is free software, distributed under the terms of</span><br><span style="color: hsl(120, 100%, 40%);">+the GNU General Public License Version 2.</span><br><span style="color: hsl(120, 100%, 40%);">+'''</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+import sys</span><br><span style="color: hsl(120, 100%, 40%);">+import logging</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+from asterisk.asterisk import Asterisk</span><br><span style="color: hsl(120, 100%, 40%);">+from asterisk.test_case import TestCase</span><br><span style="color: hsl(120, 100%, 40%);">+from asterisk.voicemail import VoiceMailMailboxManagement</span><br><span style="color: hsl(120, 100%, 40%);">+from asterisk.sipp import SIPpScenario</span><br><span style="color: hsl(120, 100%, 40%);">+from twisted.internet import reactor</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+LOGGER = logging.getLogger(__name__)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+class PollingTest(TestCase):</span><br><span style="color: hsl(120, 100%, 40%);">+ def __init__(self):</span><br><span style="color: hsl(120, 100%, 40%);">+ TestCase.__init__(self)</span><br><span style="color: hsl(120, 100%, 40%);">+ self.passed = False</span><br><span style="color: hsl(120, 100%, 40%);">+ self.test_phase = 1</span><br><span style="color: hsl(120, 100%, 40%);">+ self._registered_done = False</span><br><span style="color: hsl(120, 100%, 40%);">+ self._unregistered_done = False</span><br><span style="color: hsl(120, 100%, 40%);">+ self.sipp_register = {'scenario': 'register.xml',</span><br><span style="color: hsl(120, 100%, 40%);">+ '-i': '127.0.0.2', '-p': '5061',</span><br><span style="color: hsl(120, 100%, 40%);">+ '-s': '1234'}</span><br><span style="color: hsl(120, 100%, 40%);">+ self.sipp_unregister = {'scenario': 'unregister.xml',</span><br><span style="color: hsl(120, 100%, 40%);">+ '-i': '127.0.0.2', '-p': '5061',</span><br><span style="color: hsl(120, 100%, 40%);">+ '-s': '1234'}</span><br><span style="color: hsl(120, 100%, 40%);">+ self.create_asterisk()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def stop_test(self, passed=False):</span><br><span style="color: hsl(120, 100%, 40%);">+ self.passed = passed</span><br><span style="color: hsl(120, 100%, 40%);">+ # Sometimes the reactor has already stopped, we only care if the test passed</span><br><span style="color: hsl(120, 100%, 40%);">+ try:</span><br><span style="color: hsl(120, 100%, 40%);">+ reactor.stop()</span><br><span style="color: hsl(120, 100%, 40%);">+ except Exception as e:</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.info("Error while stopping reactor: '{0}'".format(e))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def handle_message_waiting(self, ami, event):</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if event.get("mailbox") != "1234@default":</span><br><span style="color: hsl(120, 100%, 40%);">+ return</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ old = int(event.get("old"))</span><br><span style="color: hsl(120, 100%, 40%);">+ new = int(event.get("new"))</span><br><span style="color: hsl(120, 100%, 40%);">+ waiting = int(event.get("waiting"))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ # Phase 1: We should get a MessageWaiting notification after registering</span><br><span style="color: hsl(120, 100%, 40%);">+ if self.test_phase == 1:</span><br><span style="color: hsl(120, 100%, 40%);">+ if new != 1 or waiting != 1 or old != 0:</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.error("Mailbox count was different than expected")</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test()</span><br><span style="color: hsl(120, 100%, 40%);">+ sipp = SIPpScenario(self.test_name, self.sipp_unregister)</span><br><span style="color: hsl(120, 100%, 40%);">+ sipp.run(self)</span><br><span style="color: hsl(120, 100%, 40%);">+ self.test_phase = 2</span><br><span style="color: hsl(120, 100%, 40%);">+ # Phase 2: There should not be a notification after unregistering</span><br><span style="color: hsl(120, 100%, 40%);">+ elif self.test_phase == 2:</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.error("Got a MessageWaiting event in a test phase we shouldn't have")</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def handle_originate_failure(self, reason):</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.error("Failed to originate call! Reason: {0}".format(reason))</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def handle_hangup(self, ami, event):</span><br><span style="color: hsl(120, 100%, 40%);">+ if "Local/playback@default" in event.get("channel"):</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test(True)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def handle_contact_status(self, ami, event):</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if event.get("aor") != "1234":</span><br><span style="color: hsl(120, 100%, 40%);">+ return</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ status = event.get("contactstatus")</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if status == "Created":</span><br><span style="color: hsl(120, 100%, 40%);">+ self.voicemailManager = VoiceMailMailboxManagement(self.ast[0])</span><br><span style="color: hsl(120, 100%, 40%);">+ self.voicemailManager.create_mailbox("default", "1234", True)</span><br><span style="color: hsl(120, 100%, 40%);">+ formats = ["ulaw"]</span><br><span style="color: hsl(120, 100%, 40%);">+ if not self.voicemailManager.create_dummy_voicemail("default", "1234", VoiceMailMailboxManagement.inbox_folder_name, 1, formats):</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.error("Failed to create voicemail")</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_test()</span><br><span style="color: hsl(120, 100%, 40%);">+ elif status == "Removed":</span><br><span style="color: hsl(120, 100%, 40%);">+ # Remove the voicemail from the mailbox</span><br><span style="color: hsl(120, 100%, 40%);">+ self.voicemailManager.remove_mailbox("default", "1234")</span><br><span style="color: hsl(120, 100%, 40%);">+ </span><br><span style="color: hsl(120, 100%, 40%);">+ # Originate a channel that will end the test on hangup</span><br><span style="color: hsl(120, 100%, 40%);">+ variable = {}</span><br><span style="color: hsl(120, 100%, 40%);">+ ami.originate(channel="Local/playback@default",</span><br><span style="color: hsl(120, 100%, 40%);">+ context="default",</span><br><span style="color: hsl(120, 100%, 40%);">+ exten="echo",</span><br><span style="color: hsl(120, 100%, 40%);">+ priority="1",</span><br><span style="color: hsl(120, 100%, 40%);">+ variable=variable</span><br><span style="color: hsl(120, 100%, 40%);">+ ).addErrback(self.handle_originate_failure)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def ami_connect(self, ami):</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ami.registerEvent("ContactStatus", self.handle_contact_status)</span><br><span style="color: hsl(120, 100%, 40%);">+ ami.registerEvent("MessageWaiting", self.handle_message_waiting)</span><br><span style="color: hsl(120, 100%, 40%);">+ ami.registerEvent("Hangup", self.handle_hangup)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ sipp = SIPpScenario(self.test_name, self.sipp_register)</span><br><span style="color: hsl(120, 100%, 40%);">+ sipp.run(self)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def run(self):</span><br><span style="color: hsl(120, 100%, 40%);">+ TestCase.run(self)</span><br><span style="color: hsl(120, 100%, 40%);">+ self.create_ami_factory()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def main():</span><br><span style="color: hsl(120, 100%, 40%);">+ test = PollingTest()</span><br><span style="color: hsl(120, 100%, 40%);">+ reactor.run()</span><br><span style="color: hsl(120, 100%, 40%);">+ if not test.passed:</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+if __name__ == "__main__":</span><br><span style="color: hsl(120, 100%, 40%);">+ sys.exit(main() or 0)</span><br><span>diff --git a/tests/apps/voicemail/polling/poll_sub_unsub/sipp/register.xml b/tests/apps/voicemail/polling/poll_sub_unsub/sipp/register.xml</span><br><span>new file mode 100644</span><br><span>index 0000000..5918b96</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_sub_unsub/sipp/register.xml</span><br><span>@@ -0,0 +1,24 @@</span><br><span style="color: hsl(120, 100%, 40%);">+<?xml version="1.0" encoding="ISO-8859-1" ?></span><br><span style="color: hsl(120, 100%, 40%);">+<!DOCTYPE scenario SYSTEM "sipp.dtd"></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+<scenario name="Basic Sipstone UAC"></span><br><span style="color: hsl(120, 100%, 40%);">+ <send retrans="500"></span><br><span style="color: hsl(120, 100%, 40%);">+ <![CDATA[</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ REGISTER sip:[remote_ip]:[remote_port] SIP/2.0</span><br><span style="color: hsl(120, 100%, 40%);">+ Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]</span><br><span style="color: hsl(120, 100%, 40%);">+ From: "[service]" <sip:[service]@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]</span><br><span style="color: hsl(120, 100%, 40%);">+ To: "[service]" <sip:[service]@[remote_ip]:[remote_port]></span><br><span style="color: hsl(120, 100%, 40%);">+ Call-ID: [call_id]</span><br><span style="color: hsl(120, 100%, 40%);">+ CSeq: 1 REGISTER</span><br><span style="color: hsl(120, 100%, 40%);">+ Max-Forwards: 70</span><br><span style="color: hsl(120, 100%, 40%);">+ Contact: <sip:[service]@[local_ip]:[local_port]>;transport=[transport]</span><br><span style="color: hsl(120, 100%, 40%);">+ Subject: Performance Test</span><br><span style="color: hsl(120, 100%, 40%);">+ Content-Length: 0</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ]]></span><br><span style="color: hsl(120, 100%, 40%);">+ </send></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ <recv response="200" rtd="true" timeout="5000"/></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</scenario></span><br><span>diff --git a/tests/apps/voicemail/polling/poll_sub_unsub/sipp/unregister.xml b/tests/apps/voicemail/polling/poll_sub_unsub/sipp/unregister.xml</span><br><span>new file mode 100644</span><br><span>index 0000000..cc340ad</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_sub_unsub/sipp/unregister.xml</span><br><span>@@ -0,0 +1,25 @@</span><br><span style="color: hsl(120, 100%, 40%);">+<?xml version="1.0" encoding="ISO-8859-1" ?></span><br><span style="color: hsl(120, 100%, 40%);">+<!DOCTYPE scenario SYSTEM "sipp.dtd"></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+<scenario name="Basic Sipstone UAC"></span><br><span style="color: hsl(120, 100%, 40%);">+ <send retrans="500"></span><br><span style="color: hsl(120, 100%, 40%);">+ <![CDATA[</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ REGISTER sip:[remote_ip]:[remote_port] SIP/2.0</span><br><span style="color: hsl(120, 100%, 40%);">+ Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]</span><br><span style="color: hsl(120, 100%, 40%);">+ From: "[service]" <sip:[service]@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]</span><br><span style="color: hsl(120, 100%, 40%);">+ To: "[service]" <sip:[service]@[remote_ip]:[remote_port]></span><br><span style="color: hsl(120, 100%, 40%);">+ Call-ID: [call_id]</span><br><span style="color: hsl(120, 100%, 40%);">+ CSeq: 1 REGISTER</span><br><span style="color: hsl(120, 100%, 40%);">+ Max-Forwards: 70</span><br><span style="color: hsl(120, 100%, 40%);">+ Expires: 0</span><br><span style="color: hsl(120, 100%, 40%);">+ Contact: <sip:[service]@[local_ip]:[local_port]>;transport=[transport]</span><br><span style="color: hsl(120, 100%, 40%);">+ Subject: Performance Test</span><br><span style="color: hsl(120, 100%, 40%);">+ Content-Length: 0</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ]]></span><br><span style="color: hsl(120, 100%, 40%);">+ </send></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ <recv response="200" rtd="true"/></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</scenario></span><br><span>diff --git a/tests/apps/voicemail/polling/poll_sub_unsub/test-config.yaml b/tests/apps/voicemail/polling/poll_sub_unsub/test-config.yaml</span><br><span>new file mode 100644</span><br><span>index 0000000..c2c8982</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/poll_sub_unsub/test-config.yaml</span><br><span>@@ -0,0 +1,20 @@</span><br><span style="color: hsl(120, 100%, 40%);">+testinfo:</span><br><span style="color: hsl(120, 100%, 40%);">+ summary: 'Test polling after subscribing then unsubscribing'</span><br><span style="color: hsl(120, 100%, 40%);">+ description: |</span><br><span style="color: hsl(120, 100%, 40%);">+ This test verifies that a notification is received after subscribing to</span><br><span style="color: hsl(120, 100%, 40%);">+ a mailbox, and that no notification is received after unsubscribing from</span><br><span style="color: hsl(120, 100%, 40%);">+ the mailbox.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+properties:</span><br><span style="color: hsl(120, 100%, 40%);">+ buildoption: 'TEST_FRAMEWORK'</span><br><span style="color: hsl(120, 100%, 40%);">+ dependencies:</span><br><span style="color: hsl(120, 100%, 40%);">+ - python : 'twisted'</span><br><span style="color: hsl(120, 100%, 40%);">+ - python : 'starpy'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk: 'app_echo'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk: 'app_playback'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk: 'app_voicemail'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk: 'chan_pjsip'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk: 'res_pjsip'</span><br><span style="color: hsl(120, 100%, 40%);">+ tags:</span><br><span style="color: hsl(120, 100%, 40%);">+ - voicemail</span><br><span style="color: hsl(120, 100%, 40%);">+ - apps</span><br><span>diff --git a/tests/apps/voicemail/polling/tests.yaml b/tests/apps/voicemail/polling/tests.yaml</span><br><span>new file mode 100644</span><br><span>index 0000000..171a45f</span><br><span>--- /dev/null</span><br><span>+++ b/tests/apps/voicemail/polling/tests.yaml</span><br><span>@@ -0,0 +1,7 @@</span><br><span style="color: hsl(120, 100%, 40%);">+# Enter tests here in the order they should be considered for execution:</span><br><span style="color: hsl(120, 100%, 40%);">+tests:</span><br><span style="color: hsl(120, 100%, 40%);">+ - test: 'poll_multiple_mailboxes'</span><br><span style="color: hsl(120, 100%, 40%);">+ - test: 'poll_no_subs'</span><br><span style="color: hsl(120, 100%, 40%);">+ - test: 'poll_same_mailbox'</span><br><span style="color: hsl(120, 100%, 40%);">+ - test: 'poll_single_mailbox'</span><br><span style="color: hsl(120, 100%, 40%);">+ - test: 'poll_sub_unsub'</span><br><span>diff --git a/tests/apps/voicemail/tests.yaml b/tests/apps/voicemail/tests.yaml</span><br><span>index 0ec6c61..735dbb7 100644</span><br><span>--- a/tests/apps/voicemail/tests.yaml</span><br><span>+++ b/tests/apps/voicemail/tests.yaml</span><br><span>@@ -30,3 +30,4 @@</span><br><span> - test: 'leave_voicemail_nominal'</span><br><span> - test: 'leave_voicemail_priority'</span><br><span> - test: 'play_message'</span><br><span style="color: hsl(120, 100%, 40%);">+ - dir: 'polling'</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/testsuite/+/11284">change 11284</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/testsuite/+/11284"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: testsuite </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: Id3a40527624c094e253d56ee2df5381b03b22169 </div>
<div style="display:none"> Gerrit-Change-Number: 11284 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>