michael@0: #/usr/bin/env python michael@0: import mozdevice michael@0: import mozlog michael@0: import unittest michael@0: from sut import MockAgent michael@0: michael@0: michael@0: class TestGetIP(unittest.TestCase): michael@0: """ class to test IP methods """ michael@0: michael@0: commands = [('exec ifconfig eth0', 'eth0: ip 192.168.0.1 ' michael@0: 'mask 255.255.255.0 flags [up broadcast running multicast]\n' michael@0: 'return code [0]'), michael@0: ('exec ifconfig wlan0', 'wlan0: ip 10.1.39.126\n' michael@0: 'mask 255.255.0.0 flags [up broadcast running multicast]\n' michael@0: 'return code [0]'), michael@0: ('exec ifconfig fake0', '##AGENT-WARNING## [ifconfig] ' michael@0: 'command with arg(s) = [fake0] is currently not implemented.') michael@0: ] michael@0: michael@0: def test_getIP_eth0(self): michael@0: m = MockAgent(self, commands=[self.commands[0]]) michael@0: d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=mozlog.DEBUG) michael@0: self.assertEqual('192.168.0.1', d.getIP(interfaces=['eth0'])) michael@0: michael@0: def test_getIP_wlan0(self): michael@0: m = MockAgent(self, commands=[self.commands[1]]) michael@0: d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=mozlog.DEBUG) michael@0: self.assertEqual('10.1.39.126', d.getIP(interfaces=['wlan0'])) michael@0: michael@0: def test_getIP_error(self): michael@0: m = MockAgent(self, commands=[self.commands[2]]) michael@0: d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=mozlog.DEBUG) michael@0: self.assertRaises(mozdevice.DMError, d.getIP, interfaces=['fake0']) michael@0: michael@0: if __name__ == '__main__': michael@0: unittest.main()