|
1 #/usr/bin/env python |
|
2 import mozdevice |
|
3 import mozlog |
|
4 import unittest |
|
5 from sut import MockAgent |
|
6 |
|
7 |
|
8 class TestGetIP(unittest.TestCase): |
|
9 """ class to test IP methods """ |
|
10 |
|
11 commands = [('exec ifconfig eth0', 'eth0: ip 192.168.0.1 ' |
|
12 'mask 255.255.255.0 flags [up broadcast running multicast]\n' |
|
13 'return code [0]'), |
|
14 ('exec ifconfig wlan0', 'wlan0: ip 10.1.39.126\n' |
|
15 'mask 255.255.0.0 flags [up broadcast running multicast]\n' |
|
16 'return code [0]'), |
|
17 ('exec ifconfig fake0', '##AGENT-WARNING## [ifconfig] ' |
|
18 'command with arg(s) = [fake0] is currently not implemented.') |
|
19 ] |
|
20 |
|
21 def test_getIP_eth0(self): |
|
22 m = MockAgent(self, commands=[self.commands[0]]) |
|
23 d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=mozlog.DEBUG) |
|
24 self.assertEqual('192.168.0.1', d.getIP(interfaces=['eth0'])) |
|
25 |
|
26 def test_getIP_wlan0(self): |
|
27 m = MockAgent(self, commands=[self.commands[1]]) |
|
28 d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=mozlog.DEBUG) |
|
29 self.assertEqual('10.1.39.126', d.getIP(interfaces=['wlan0'])) |
|
30 |
|
31 def test_getIP_error(self): |
|
32 m = MockAgent(self, commands=[self.commands[2]]) |
|
33 d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=mozlog.DEBUG) |
|
34 self.assertRaises(mozdevice.DMError, d.getIP, interfaces=['fake0']) |
|
35 |
|
36 if __name__ == '__main__': |
|
37 unittest.main() |