From 47ec8c989a2b6180d2ab9b7a7020fab27146974f Mon Sep 17 00:00:00 2001 From: Alexandre Savard <alexandre.savard@savoirfairelinux.com> Date: Tue, 10 Apr 2012 10:49:16 -0400 Subject: [PATCH] #9619: update python interface and script account registration --- tools/pysflphone/sflphonectrlsimple.py | 6 +- .../test_sflphone_dbus_interface.py | 93 +++++++++++++++ tools/sippxml/uac_register_no_cvs.xml | 110 ++++++++++++++++++ 3 files changed, 206 insertions(+), 3 deletions(-) create mode 100644 tools/pysflphone/test_sflphone_dbus_interface.py create mode 100644 tools/sippxml/uac_register_no_cvs.xml diff --git a/tools/pysflphone/sflphonectrlsimple.py b/tools/pysflphone/sflphonectrlsimple.py index 12709ed900..1838ba5371 100755 --- a/tools/pysflphone/sflphonectrlsimple.py +++ b/tools/pysflphone/sflphonectrlsimple.py @@ -348,7 +348,7 @@ class SflPhoneCtrlSimple(Thread): if self.account is None: raise SflPhoneError("No provided or current account !") account = self.account - return self.getAccountDetails(account)['Status'] == "REGISTERED" + return self.getAccountDetails(account)['Registration.Status'] == "REGISTERED" def isAccountEnable(self, account=None): @@ -369,11 +369,11 @@ class SflPhoneCtrlSimple(Thread): if enable == True: details = self.getAccountDetails(account) - details['Account.enable'] = "TRUE" + details['Account.enable'] = "true" self.configurationmanager.setAccountDetails(account, details) else: details = self.getAccountDetails(account) - details['Account.enable'] = "FALSE" + details['Account.enable'] = "false" self.configurationmanager.setAccountDetails(account, details) def checkAccountExists(self, account=None): diff --git a/tools/pysflphone/test_sflphone_dbus_interface.py b/tools/pysflphone/test_sflphone_dbus_interface.py new file mode 100644 index 0000000000..c45156decf --- /dev/null +++ b/tools/pysflphone/test_sflphone_dbus_interface.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python +# +# Copyright (C) 2009 by the Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +import time +import logging +from sflphonectrlsimple import SflPhoneCtrlSimple + +from nose.tools import nottest + +### +### function starting with 'test' are executed. +### + +# Open sflphone and connect to sflphoned through dbus +sflphone = SflPhoneCtrlSimple(True) + +accountList = ["IP2IP", "Account:1332798167"] + +class TestSFLPhoneAccountConfig: + + def __init__(self): + self.logger = logging.getLogger("TestSFLPhoneAccountConfig") + filehdlr = logging.FileHandler("/tmp/sflphonedbustest.log") + formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s") + filehdlr.setFormatter(formatter) + self.logger.addHandler(filehdlr) + self.logger.setLevel(logging.INFO) + + @nottest + def test_get_account_list(self): + self.logger.info("Test get account list") + accList = sflphone.getAllAccounts() + listIntersection = set(accList) & set(accountList) + assert len(listIntersection) == len(accountList) + + @nottest + def test_account_registration(self): + self.logger.info("Test account registration") + accList = [x for x in sflphone.getAllAccounts() if x != "IP2IP"] + for acc in accList: + self.logger.info("Registering account " + acc) + + if sflphone.isAccountEnable(acc): + sflphone.setAccountEnable(acc, False) + time.sleep(2) + + # Account should not be registered + assert sflphone.isAccountRegistered(acc) + + sflphone.setAccountEnable(acc, True) + time.sleep(2) + + assert sflphone.isAccountRegistered(acc) + + @nottest + def test_add_remove_account(self): + self.logger.info("Test add/remove account") + accountDetails = {} + newAccList = [] + + # consider only true accounts + accList = [x for x in sflphone.getAllAccounts() if x != "IP2IP"] + + # Store the account details localy + for acc in accList: + accountDetails[acc] = sflphone.getAccountDetails(acc) + + # Remove all accounts from sflphone + for acc in accountDetails: + sflphone.removeAccount(acc) + + # Recreate all accounts + for acc in accountDetails: + newAccList.append(sflphone.addAccount(accountDetails[acc])) + + # New accounts should be automatically registered + for acc in newAccList: + assert sflphone.isAccountRegistered(acc) diff --git a/tools/sippxml/uac_register_no_cvs.xml b/tools/sippxml/uac_register_no_cvs.xml new file mode 100644 index 0000000000..f22ae377a8 --- /dev/null +++ b/tools/sippxml/uac_register_no_cvs.xml @@ -0,0 +1,110 @@ +<?xml version="1.0" encoding="ISO-8859-2" ?> + +<!-- Use with CSV file struct like: 3000;192.168.1.106;[authentication username=3000 password=3000]; + (user part of uri, server address, auth tag in each line) +--> + +<scenario name="register_client"> + <send retrans="500"> + <![CDATA[ + + REGISTER sip:127.0.0.1 SIP/2.0 + Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch] + From: <sip:300@127.0.0.1>;tag=[call_number] + To: <sip:300@127.0.0.1> + Call-ID: [call_id] + CSeq: [cseq] REGISTER + Contact: sip:300@[local_ip]:[local_port] + Max-Forwards: 10 + Expires: 120 + User-Agent: SIPp/Win32 + Content-Length: 0 + + ]]> + </send> + + <!-- asterisk --> + <recv response="200"> + <!-- + <action> + <ereg regexp=".*" search_in="hdr" header="Contact:" check_it="true" assign_to="1" /> + </action> + --> + </recv> + + <!-- + <recv request="INVITE" crlf="true"> + </recv> + + <send> + <![CDATA[ + + SIP/2.0 180 Ringing + [last_Via:] + [last_From:] + [last_To:];tag=[pid]SIPpTag01[call_number] + [last_Call-ID:] + [last_CSeq:] + Contact: <sip:[local_ip]:[local_port];transport=[transport]> + Content-Length: 0 + + ]]> + </send> + + <send retrans="500"> + <![CDATA[ + + SIP/2.0 200 OK + [last_Via:] + [last_From:] + [last_To:];tag=[pid]SIPpTag01[call_number] + [last_Call-ID:] + [last_CSeq:] + Contact: <sip:[local_ip]:[local_port];transport=[transport]> + Content-Type: application/sdp + Content-Length: [len] + + v=0 + o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip] + s=- + c=IN IP[media_ip_type] [media_ip] + t=0 0 + m=audio [media_port] RTP/AVP 0 + a=rtpmap:0 PCMU/8000 + + ]]> + </send> + + <recv request="ACK" + optional="true" + rtd="true" + crlf="true"> + </recv> + + <recv request="BYE"> + </recv> + + <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> + + <timewait milliseconds="4000"/> + + + <ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/> + + <CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/> + --> + +</scenario> -- GitLab