testing/mozbase/mozdevice/tests/sut_ip.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testing/mozbase/mozdevice/tests/sut_ip.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,37 @@
     1.4 +#/usr/bin/env python
     1.5 +import mozdevice
     1.6 +import mozlog
     1.7 +import unittest
     1.8 +from sut import MockAgent
     1.9 +
    1.10 +
    1.11 +class TestGetIP(unittest.TestCase):
    1.12 +    """ class to test IP methods """
    1.13 +
    1.14 +    commands = [('exec ifconfig eth0', 'eth0: ip 192.168.0.1 '
    1.15 +                 'mask 255.255.255.0 flags [up broadcast running multicast]\n'
    1.16 +                 'return code [0]'),
    1.17 +                ('exec ifconfig wlan0', 'wlan0: ip 10.1.39.126\n'
    1.18 +                 'mask 255.255.0.0 flags [up broadcast running multicast]\n'
    1.19 +                 'return code [0]'),
    1.20 +                ('exec ifconfig fake0', '##AGENT-WARNING## [ifconfig] '
    1.21 +                 'command with arg(s) = [fake0] is currently not implemented.')
    1.22 +                ]
    1.23 +
    1.24 +    def test_getIP_eth0(self):
    1.25 +        m = MockAgent(self, commands=[self.commands[0]])
    1.26 +        d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=mozlog.DEBUG)
    1.27 +        self.assertEqual('192.168.0.1', d.getIP(interfaces=['eth0']))
    1.28 +
    1.29 +    def test_getIP_wlan0(self):
    1.30 +        m = MockAgent(self, commands=[self.commands[1]])
    1.31 +        d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=mozlog.DEBUG)
    1.32 +        self.assertEqual('10.1.39.126', d.getIP(interfaces=['wlan0']))
    1.33 +
    1.34 +    def test_getIP_error(self):
    1.35 +        m = MockAgent(self, commands=[self.commands[2]])
    1.36 +        d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=mozlog.DEBUG)
    1.37 +        self.assertRaises(mozdevice.DMError, d.getIP, interfaces=['fake0'])
    1.38 +
    1.39 +if __name__ == '__main__':
    1.40 +    unittest.main()

mercurial