Ejemplo n.º 1
0
    def test_shell_su_succes(self):
        mock_adb = Mock()
        mock_adb.shell_command.return_value = "su_succes         "
        Adb.adb = mock_adb
        result = Adb.shell_su(123, "test_command_su")

        expected_calls = [
            call.set_target_by_name(123),
            call.shell_command('su -c \'test_command_su\'')
        ]
        assert mock_adb.mock_calls == expected_calls
        assert result == 'su_succes'
Ejemplo n.º 2
0
    def test_shell_su_error(self):
        mock_adb = Mock()
        mock_adb.shell_command.return_value = "su_error"
        Adb.adb = mock_adb

        with pytest.raises(Adb.AdbError):
            Adb.shell_su(123, "test_command_su")

        expected_calls = [
            call.set_target_by_name(123),
            call.shell_command('su -c \'test_command_su\'')
        ]
        assert mock_adb.mock_calls == expected_calls
Ejemplo n.º 3
0
    def test_install_not_all_permissions(self):
        mock_adb = Mock()
        mock_adb._ADB__output = 'succes'
        Adb.adb = mock_adb
        device_id = 123
        apk = 'test_apk.apk'

        result = Adb.install(device_id, apk, all_permissions=False)

        assert result == 'succes'
        expected_calls = [
            call.set_target_by_name(device_id),
            call.run_cmd('install -r {}'.format(apk))
        ]
        assert mock_adb.mock_calls == expected_calls
Ejemplo n.º 4
0
    def test_logcat_no_regex(self):
        mock_adb = Mock()
        mock_adb.get_logcat.return_value = 'get_logcat output'
        Adb.adb = mock_adb

        device_id = 123

        result = Adb.logcat(device_id)

        assert result == 'get_logcat output'
        expected_calls = [
            call.set_target_by_name(device_id),
            call.get_logcat(lcfilter='-d')
        ]
        assert mock_adb.mock_calls == expected_calls
Ejemplo n.º 5
0
    def test_logcat_with_regex(self):
        mock_adb = Mock()
        mock_adb.get_logcat.return_value = 'get_logcat output'
        Adb.adb = mock_adb

        test_regex = '[a-zA-Z]+'
        device_id = 123

        result = Adb.logcat(device_id, test_regex)

        assert result == 'get_logcat output'
        expected_calls = [
            call.set_target_by_name(device_id),
            call.get_logcat(lcfilter='-d -e {}'.format(test_regex))
        ]
        assert mock_adb.mock_calls == expected_calls
Ejemplo n.º 6
0
    def test_push(self):
        mock_adb = Mock()
        mock_adb._ADB__output = 'push output'
        Adb.adb = mock_adb

        device_id = 123
        local_path = 'local/path'
        remote_path = 'remote/path'

        result = Adb.push(device_id, local_path, remote_path)

        assert result == 'push output'
        expected_calls = [
            call.set_target_by_name(device_id),
            call.run_cmd('push {} {}'.format(local_path, remote_path))
        ]
        assert mock_adb.mock_calls == expected_calls
Ejemplo n.º 7
0
    def test_pull_error_with_bytes_in(self):
        mock_adb = Mock()
        mock_adb._ADB__output = 'pull output'
        mock_adb._ADB__error = 'bytes in error'
        Adb.adb = mock_adb

        device_id = 123
        local_path = 'local/path'
        remote_path = 'remote/path'

        result = Adb.pull(device_id, remote_path, local_path)

        assert result == 'bytes in error'
        expected_calls = [
            call.set_target_by_name(device_id),
            call.run_cmd('pull {} {}'.format(remote_path, local_path))
        ]
        assert mock_adb.mock_calls == expected_calls
Ejemplo n.º 8
0
    def test_install_multiple_default(self, listdir, getcwd):
        mock_adb = Mock()
        mock_adb._ADB__output = 'succes'
        Adb.adb = mock_adb
        device_id = 123
        apk = 'test_apk.xapk'

        getcwd.return_value = '.'
        listdir.return_value = [apk]

        result = Adb.install(device_id, apk)

        assert result == 'succes'
        expected_calls = [
            call.set_target_by_name(device_id),
            call.run_cmd('install-multiple -r -g {}'.format(apk))
        ]
        assert mock_adb.mock_calls == expected_calls
Ejemplo n.º 9
0
    def test_install_multiple_default(self, zipfile, tmpdir):
        xapk_file = tmpdir.mkdir("xapk").join("test_apk.xapk")
        apk_file = tmpdir.mkdir("xapk/test_apk/").join("test_apk.apk")

        xapk_file.write("This is an xapk file")
        apk_file.write("This is an apk file")
        device_id = 123

        mock_adb = Mock()
        mock_adb._ADB__output = 'succes'
        Adb.adb = mock_adb
        result = Adb.install(device_id, xapk_file)

        assert result == 'succes'
        expected_calls = [
            call.set_target_by_name(device_id),
            call.run_cmd('install-multiple -r -g {}'.format(apk_file))
        ]
        assert mock_adb.mock_calls == expected_calls