예제 #1
0
    def test_device_repeat_multi(self):
        config = {'states': ['offline'], 'battery_low': 35}

        out = [
            'List of devices attached\nHTC\tdevice',
            '25',
            'List of devices attached\nHTC\tdevice',
            '40',
            'List of devices attached\nHTC\tdevice',
            '25',
            'List of devices attached\nHTC\tdevice',
            '80'
        ]
        mock = Mock(side_effect=out)
        with patch.dict(adb.__salt__, {'cmd.run': mock}):
            ret = adb.beacon(config)
            self.assertEqual(ret, [{'device': 'HTC', 'battery_level': 25, 'tag': 'battery_low'}])

            ret = adb.beacon(config)
            self.assertEqual(ret, [])

            ret = adb.beacon(config)
            self.assertEqual(ret, [{'device': 'HTC', 'battery_level': 25, 'tag': 'battery_low'}])

            ret = adb.beacon(config)
            self.assertEqual(ret, [])
예제 #2
0
    def test_no_devices_no_repeat(self):
        config = {'states': ['offline', 'device'], 'no_devices_event': True}

        out = [
            'List of devices attached',
            'List of devices attached'
        ]

        mock = Mock(side_effect=out)
        with patch.dict(adb.__salt__, {'cmd.run': mock}):

            ret = adb.beacon(config)
            self.assertEqual(ret, [{'tag': 'no_devices'}])

            ret = adb.beacon(config)
            self.assertEqual(ret, [])
예제 #3
0
    def test_device_state(self):
        config = {'states': ['device']}

        mock = Mock(return_value='List of devices attached\nHTC\tdevice',)
        with patch.dict(adb.__salt__, {'cmd.run': mock}):
            ret = adb.beacon(config)
            self.assertEqual(ret, [{'device': 'HTC', 'state': 'device', 'tag': 'device'}])
예제 #4
0
    def test_device_state_change(self):
        config = {'states': ['offline']}

        out = [
            'List of devices attached\nHTC\tdevice',
            'List of devices attached\nHTC\toffline'
        ]

        mock = Mock(side_effect=out)
        with patch.dict(adb.__salt__, {'cmd.run': mock}):

            ret = adb.beacon(config)
            self.assertEqual(ret, [])

            ret = adb.beacon(config)
            self.assertEqual(ret, [{'device': 'HTC', 'state': 'offline', 'tag': 'offline'}])
예제 #5
0
    def test_device_no_repeat_capacity_increase(self):
        config = {'states': ['device'], 'battery_low': 75}

        out = [
            'List of devices attached\nHTC\tdevice',
            '25',
            'List of devices attached\nHTC\tdevice',
            '30'
        ]
        mock = Mock(side_effect=out)
        with patch.dict(adb.__salt__, {'cmd.run': mock}):
            ret = adb.beacon(config)
            self.assertEqual(ret, [{'device': 'HTC', 'state': 'device', 'tag': 'device'},
                                   {'device': 'HTC', 'battery_level': 25, 'tag': 'battery_low'}])

            ret = adb.beacon(config)
            self.assertEqual(ret, [])
예제 #6
0
    def test_with_user(self):
        config = {'states': ['device'], 'user': '******'}

        mock = Mock(return_value='* daemon started successfully *\nList of devices attached\nHTC\tdevice',)
        with patch.dict(adb.__salt__, {'cmd.run': mock}):
            ret = adb.beacon(config)
            mock.assert_called_once_with('adb devices', runas='fred')
            self.assertEqual(ret, [{'device': 'HTC', 'state': 'device', 'tag': 'device'}])
예제 #7
0
    def test_no_devices_with_different_states(self):
        config = {'states': ['offline'], 'no_devices_event': True}

        mock = Mock(return_value='List of devices attached\nHTC\tdevice')
        with patch.dict(adb.__salt__, {'cmd.run': mock}):

            ret = adb.beacon(config)
            self.assertEqual(ret, [])
예제 #8
0
    def test_non_dict_config(self):
        config = []

        log_mock = Mock()
        adb.log = log_mock

        ret = adb.beacon(config)

        self.assertEqual(ret, [])
        log_mock.info.assert_called_once_with('Configuration for adb beacon must be a dict.')
예제 #9
0
    def test_empty_config(self):
        config = {}

        log_mock = Mock()
        adb.log = log_mock

        ret = adb.beacon(config)

        self.assertEqual(ret, [])
        log_mock.info.assert_called_once_with('Configuration for adb beacon must include a states array.')
예제 #10
0
    def test_weird_batteries(self):
        config = {'states': ['device'], 'battery_low': 25}

        out = [
            'List of devices attached\nHTC\tdevice',
            '-9000',
        ]
        mock = Mock(side_effect=out)
        with patch.dict(adb.__salt__, {'cmd.run': mock}):
            ret = adb.beacon(config)
            self.assertEqual(ret, [{'device': 'HTC', 'state': 'device', 'tag': 'device'}])
예제 #11
0
    def test_device_battery_not_found(self):
        config = {'states': ['device'], 'battery_low': 25}

        out = [
            'List of devices attached\nHTC\tdevice',
            '/system/bin/sh: cat: /sys/class/power_supply/*/capacity: No such file or directory',
        ]
        mock = Mock(side_effect=out)
        with patch.dict(adb.__salt__, {'cmd.run': mock}):
            ret = adb.beacon(config)
            self.assertEqual(ret, [{'device': 'HTC', 'state': 'device', 'tag': 'device'}])
예제 #12
0
    def test_invalid_states(self):
        config = {'states': ['Random', 'Failings']}

        log_mock = Mock()
        adb.log = log_mock

        ret = adb.beacon(config)

        self.assertEqual(ret, [])
        log_mock.info.assert_called_once_with('Need a one of the following adb states:'
                                              ' offline, bootloader, device, host, recovery, '
                                              'no permissions, sideload, unauthorized, unknown, missing')
예제 #13
0
파일: test_adb.py 프로젝트: whytewolf/salt
def test_device_battery_not_found():
    config = [{"states": ["device"], "battery_low": 25}]

    out = [
        "List of devices attached\nHTC\tdevice",
        "/system/bin/sh: cat: /sys/class/power_supply/*/capacity: No such file or"
        " directory",
    ]

    mock = Mock(side_effect=out)
    with patch.dict(adb.__salt__, {"cmd.run": mock}):
        ret = adb.validate(config)
        assert ret == (True, "Valid beacon configuration")

        ret = adb.beacon(config)
        assert ret == [{"device": "HTC", "state": "device", "tag": "device"}]
예제 #14
0
    def test_device_battery_charged(self):
        config = [{'states': ['device'], 'battery_low': 30}]

        out = [
            'List of devices attached\nHTC\tdevice',
            '100',
        ]
        mock = Mock(side_effect=out)
        with patch.dict(adb.__salt__, {'cmd.run': mock}):
            ret = adb.validate(config)
            self.assertEqual(ret, (True, 'Valid beacon configuration'))

            ret = adb.beacon(config)
            self.assertEqual(ret, [{'device': 'HTC',
                                    'state': 'device',
                                    'tag': 'device'}])
예제 #15
0
    def test_with_startup(self):
        config = [{'states': ['device']}]

        mock = Mock(
            return_value=
            '* daemon started successfully *\nList of devices attached\nHTC\tdevice',
        )
        with patch.dict(adb.__salt__, {'cmd.run': mock}):
            ret = adb.validate(config)
            self.assertEqual(ret, (True, 'Valid beacon configuration'))

            ret = adb.beacon(config)
            self.assertEqual(ret, [{
                'device': 'HTC',
                'state': 'device',
                'tag': 'device'
            }])
예제 #16
0
    def test_with_startup(self):
        config = [{"states": ["device"]}]

        mock = Mock(
            return_value=
            "* daemon started successfully *\nList of devices attached\nHTC\tdevice",
        )
        with patch.dict(adb.__salt__, {"cmd.run": mock}):
            ret = adb.validate(config)
            self.assertEqual(ret, (True, "Valid beacon configuration"))

            ret = adb.beacon(config)
            self.assertEqual(ret, [{
                "device": "HTC",
                "state": "device",
                "tag": "device"
            }])
예제 #17
0
    def test_device_battery_not_found(self):
        config = [{'states': ['device'], 'battery_low': 25}]

        out = [
            'List of devices attached\nHTC\tdevice',
            '/system/bin/sh: cat: /sys/class/power_supply/*/capacity: No such file or directory',
        ]
        mock = Mock(side_effect=out)
        with patch.dict(adb.__salt__, {'cmd.run': mock}):
            ret = adb.validate(config)
            self.assertEqual(ret, (True, 'Valid beacon configuration'))

            ret = adb.beacon(config)
            self.assertEqual(ret, [{
                'device': 'HTC',
                'state': 'device',
                'tag': 'device'
            }])
예제 #18
0
    def test_with_user(self):
        config = [{'states': ['device'], 'user': '******'}]

        mock = Mock(
            return_value=
            '* daemon started successfully *\nList of devices attached\nHTC\tdevice'
        )
        with patch.dict(adb.__salt__, {'cmd.run': mock}):
            ret = adb.validate(config)
            self.assertEqual(ret, (True, 'Valid beacon configuration'))

            ret = adb.beacon(config)
            mock.assert_called_once_with('adb devices', runas='fred')
            self.assertEqual(ret, [{
                'device': 'HTC',
                'state': 'device',
                'tag': 'device'
            }])
예제 #19
0
    def test_with_user(self):
        config = [{"states": ["device"], "user": "******"}]

        mock = Mock(
            return_value=
            "* daemon started successfully *\nList of devices attached\nHTC\tdevice"
        )
        with patch.dict(adb.__salt__, {"cmd.run": mock}):
            ret = adb.validate(config)
            self.assertEqual(ret, (True, "Valid beacon configuration"))

            ret = adb.beacon(config)
            mock.assert_called_once_with("adb devices", runas="fred")
            self.assertEqual(ret, [{
                "device": "HTC",
                "state": "device",
                "tag": "device"
            }])
예제 #20
0
    def test_weird_batteries(self):
        config = [{"states": ["device"], "battery_low": 25}]

        out = [
            "List of devices attached\nHTC\tdevice",
            "-9000",
        ]
        mock = Mock(side_effect=out)
        with patch.dict(adb.__salt__, {"cmd.run": mock}):
            ret = adb.validate(config)
            self.assertEqual(ret, (True, "Valid beacon configuration"))

            ret = adb.beacon(config)
            self.assertEqual(ret, [{
                "device": "HTC",
                "state": "device",
                "tag": "device"
            }])
예제 #21
0
    def test_multiple_low_batteries(self):
        config = {'states': ['device'], 'battery_low': 30}

        out = [
            'List of devices attached\nHTC\tdevice',
            '25\n14',
        ]
        mock = Mock(side_effect=out)
        with patch.dict(adb.__salt__, {'cmd.run': mock}):
            ret = adb.beacon(config)
            self.assertEqual(ret, [{
                'device': 'HTC',
                'state': 'device',
                'tag': 'device'
            }, {
                'device': 'HTC',
                'battery_level': 25,
                'tag': 'battery_low'
            }])