summaryrefslogtreecommitdiffstats
path: root/testing/mozbase/mozdevice/tests/sut_ip.py
blob: 31428a6248c27d84c3e241f1cfbf45638f280222 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
import mozdevice
import logging
import unittest
from sut import MockAgent


class TestGetIP(unittest.TestCase):
    """ class to test IP methods """

    commands = [('exec ifconfig eth0', 'eth0: ip 192.168.0.1 '
                 'mask 255.255.255.0 flags [up broadcast running multicast]\n'
                 'return code [0]'),
                ('exec ifconfig wlan0', 'wlan0: ip 10.1.39.126\n'
                 'mask 255.255.0.0 flags [up broadcast running multicast]\n'
                 'return code [0]'),
                ('exec ifconfig fake0', '##AGENT-WARNING## [ifconfig] '
                 'command with arg(s) = [fake0] is currently not implemented.')
                ]

    def test_getIP_eth0(self):
        m = MockAgent(self, commands=[self.commands[0]])
        d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=logging.DEBUG)
        self.assertEqual('192.168.0.1', d.getIP(interfaces=['eth0']))

    def test_getIP_wlan0(self):
        m = MockAgent(self, commands=[self.commands[1]])
        d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=logging.DEBUG)
        self.assertEqual('10.1.39.126', d.getIP(interfaces=['wlan0']))

    def test_getIP_error(self):
        m = MockAgent(self, commands=[self.commands[2]])
        d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=logging.DEBUG)
        self.assertRaises(mozdevice.DMError, d.getIP, interfaces=['fake0'])

if __name__ == '__main__':
    unittest.main()