Skip to content

Commit

Permalink
Merge pull request #20 from bretttolbert/master
Browse files Browse the repository at this point in the history
Added keyword to SipPhoneLibrary to expose list of all registered lines....
  • Loading branch information
Nick Robinson committed Mar 25, 2014
2 parents 21c0112 + 859ff58 commit 4885a1a
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 39 deletions.
42 changes: 28 additions & 14 deletions src/SipPhoneLibrary/SipPhoneLibrary_UnitTest_TestSuite.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
Documentation This test suite also serves as a unit test for the SipPhoneLibrary.
Library String
Library ../SipPhoneLibrary/
Library Collections

*** Variables ***
${EXT1} 1001
${EXT1_IP} 10.17.127.216
${EXT1_PORT} 8081
${EXT2} 1002
${EXT2_IP} 10.17.127.216
${EXT2_PORT} 8082

*** Test Cases ***
Example Test Case 1
Expand All @@ -23,14 +18,33 @@ Example Test Case 1
Log ${mac1}
${mac2}= Get Mac ${EXT2}
Log ${mac2}
Press Headset Key ${EXT1}
${digits}= Split String To Characters ${EXT2}
: FOR ${digit} IN @{digits}
\ Press Digit ${EXT1} ${digit}
Sleep 2
Expect Ringback ${EXT1}
Press Headset Key ${EXT2}
${reg}= Get Registered Lines ${EXT1}
Dictionary Should Contain Value ${reg} ${EXT1}
${reg}= Get Registered Lines ${EXT2}
Dictionary Should Contain Value ${reg} ${EXT2}
Dial Number ${EXT1} ${EXT2}
Wait Until Keyword Succeeds 3 seconds 500 ms Expect Ringback ${EXT1}
Accept Call ${EXT2}
Sleep 1
Expect Connected ${EXT1}
Expect Connected ${EXT2}
Press End Call ${EXT2}
End Call ${EXT2}

*** Keywords ***
Dial Number
[Arguments] ${ext} ${number}
[Documentation] Take the specified phone offhook (by pressing the headset key), dial the specified number.
${digits}= Split String To Characters ${number}
: FOR ${digit} IN @{digits}
\ Press Digit ${ext} ${digit}
Press Headset Key ${ext}

Accept Call
[Arguments] ${ext}
[Documentation] Answer a ringing phone (by pressing the headset key).
Press Headset Key ${ext}

End Call
[Arguments] ${ext}
[Documentation] End a call (by pressing the headset key).
Press Headset Key ${ext}
14 changes: 13 additions & 1 deletion src/SipPhoneLibrary/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def press_digit(self, extension, digit):
digit = "Star"
elif digit == "#":
digit = "Pound"
xml_string = BEGIN_REQUEST + "Key:DialPad" + digit + END_REQUEST
xml_string = BEGIN_REQUEST + "Key:DialPad{0}".format(digit) + END_REQUEST
self._send_request(extension, xml_string)

def press_hold(self, extension):
Expand Down Expand Up @@ -455,6 +455,18 @@ def get_phone_model(self, extension):
phone_model = nodes[0].childNodes[0].data
return phone_model

def get_registered_lines(self, extension):
"""Returns a dictionary of all registered lines and their directory numbers.
For example: {'Line1:'2565550061', 'Line2':'2565550062'} """
reg = {}
root = self._poll_device_info(extension)
nodes = root.getElementsByTagName('PhoneDN')
if len(nodes):
phone_dn = nodes[0].childNodes[0].data.strip()
if phone_dn != '':
reg = dict(i.split(':') for i in phone_dn.split(','))
return reg

## Network Information XML look like this:
#<PolycomIPPhone>
#<NetworkConfiguration>
Expand Down
23 changes: 15 additions & 8 deletions src/SipPhoneLibrary/keywords_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ def setUp(self):
self.lib = keywords.PhoneKeywords()

#setup
self.ext1 = phone1['extension']
self.ext2 = phone2['extension']
self.lib.setup_phone(self.ext1, phone1['ipaddr'], port=phone1['port'], timeout=phone1['timeout'])
self.lib.setup_phone(self.ext2, phone2['ipaddr'], port=phone2['port'], timeout=phone2['timeout'])
self.ext1 = EXT1
self.ext2 = EXT2
self.lib.setup_phone(self.ext1, EXT1_IP, port=EXT1_PORT, timeout=EXT1_TIMEOUT)
self.lib.setup_phone(self.ext2, EXT2_IP, port=EXT2_PORT, timeout=EXT2_TIMEOUT)

def test_press_volume_down(self):
#volume
Expand All @@ -31,16 +31,16 @@ def test_get_dhcp_enabled(self):
def test_get_phone_model(self):
#phone model
model1 = self.lib.get_phone_model(self.ext1)
self.assertTrue(model1 == phone1['model'])
self.assertTrue(model1 == EXT1_MODEL)
model2 = self.lib.get_phone_model(self.ext2)
self.assertTrue(model2 == phone2['model'])
self.assertTrue(model2 == EXT2_MODEL)

def test_get_phone_mac(self):
#phone mac
mac1 = self.lib.get_mac(self.ext1)
assert mac1 == phone1['mac']
assert mac1 == EXT1_MAC
mac2 = self.lib.get_mac(self.ext2)
self.assertTrue(mac2 == phone2['mac'])
self.assertTrue(mac2 == EXT2_MAC)

def test_get_ip_addr(self):
#phone ip addr
Expand All @@ -59,6 +59,13 @@ def test_get_prov_server(self):
prov_server2 = self.lib.get_prov_server(self.ext2)
print 'prov_server2:', prov_server2

def test_registrations(self):
reg = self.lib.get_registered_lines(self.ext1)
self.assertTrue(type(reg) is dict)
self.assertEqual(len(reg), 1)
self.assertTrue('Line1' in reg)
self.assertEqual(reg['Line1'], self.ext1)

def test_call_scenario_1(self):
#verify that line 1 is inactive
line_state = self.lib.get_line_state(self.ext1)
Expand Down
29 changes: 13 additions & 16 deletions src/SipPhoneLibrary/keywords_test_parameters.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
phone1 = {
'extension': '1001',
'ipaddr': '10.17.127.216',
'port': '8081',
'model': 'SoundPoint IP 321',
'mac': '0004f2a76cd5',
'timeout': '5 seconds'
}
phone2 = {
'extension': '1002',
'ipaddr': '10.17.127.216',
'port': '8082',
'model': 'SoundPoint IP 321',
'mac': '0004f2a76e03',
'timeout': '5 seconds'
}
EXT1 = '2565557051'
EXT1_IP = '10.17.127.249'
EXT1_PORT = '8081'
EXT1_MODEL = 'SoundPoint IP 321'
EXT1_MAC = '0004f2a76cd5'
EXT1_TIMEOUT = '5 seconds'

EXT2 = '2565557052'
EXT2_IP = '10.17.127.249'
EXT2_PORT = '8082'
EXT2_MODEL = 'SoundPoint IP 321'
EXT2_MAC = '0004f2a76e03'
EXT2_TIMEOUT = '5 seconds'
2 changes: 2 additions & 0 deletions src/SipPhoneLibrary/run_pybot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
pybot --variablefile keywords_test_parameters.py .

0 comments on commit 4885a1a

Please sign in to comment.