-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from NetherlandsForensicInstitute/20-pull-file…
…s-where-there-is-a-space-in-the-folder-name 20 correctly handle spaces in paths, add test, fix release notes
- Loading branch information
Showing
5 changed files
with
163 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,55 @@ | ||
``` | ||
v1.0.0 - Change name to adb-pywrapper and add action to release to PyPi | ||
``` | ||
``` | ||
v0.8 - Removed lru_cache function that caused get_prop output to be cached which is not advisable since these properties can change | ||
``` | ||
``` | ||
v0.7 - Improved the documentation of all the functions and the README.md | ||
``` | ||
``` | ||
v0.6 - Introduced get_device_status functionality to get the device status using a static function | ||
``` | ||
``` | ||
v0.5 - Introduced snapshot_list, load, save and delete for emulator snapshot interaction | ||
``` | ||
``` | ||
v0.4 - Introduced get-state function to get the current status of a connected device. Example: device, offline, fastboot | ||
``` | ||
``` | ||
v0.3 - Introduced emu avd function for emulator communication trough adb | ||
``` | ||
``` | ||
v0.2 - Introduced get_prop function from OSS project | ||
``` | ||
``` | ||
v0.1 - Initial release based on ADB functions introduced in the Appium project | ||
``` | ||
1.0.2 | ||
----- | ||
|
||
- 20: correctly pull files when name contains a space | ||
|
||
1.0.1 | ||
----- | ||
|
||
- implemented optionally specified wait time for wait_for_device functionality | ||
|
||
1.0.0 | ||
----- | ||
|
||
- Change name to adb-pywrapper and add action to release to PyPi | ||
|
||
0.8 | ||
--- | ||
|
||
- Removed lru_cache function that caused get_prop output to be cached which is not advisable since these properties can | ||
change | ||
|
||
0.7 | ||
--- | ||
|
||
- Improved the documentation of all the functions and the README.md | ||
|
||
0.6 | ||
--- | ||
|
||
- Introduced get_device_status functionality to get the device status using a static function | ||
|
||
0.5 | ||
--- | ||
|
||
- Introduced snapshot_list, load, save and delete for emulator snapshot interaction | ||
|
||
0.4 | ||
--- | ||
|
||
- Introduced get-state function to get the current status of a connected device. Example: device, offline, fastboot | ||
|
||
0.3 | ||
--- | ||
|
||
- Introduced emu avd function for emulator communication trough adb | ||
|
||
0.2 | ||
--- | ||
|
||
- Introduced get_prop function from OSS project | ||
|
||
0.1 | ||
--- | ||
|
||
- Initial release based on ADB functions introduced in the Appium project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import os.path | ||
import shutil | ||
import unittest | ||
from os.path import basename | ||
from pathlib import Path | ||
from subprocess import CompletedProcess | ||
from unittest.mock import patch, Mock | ||
|
||
from parameterized import parameterized | ||
|
||
from adb_pywrapper.adb_device import AdbDevice | ||
from adb_pywrapper.adb_result import AdbResult | ||
|
||
|
||
class MockAdbResult(AdbResult): | ||
def __init__(self, stdout: str = '', stderr: str = '', success: bool = True): | ||
self.completed_adb_process = Mock(CompletedProcess) | ||
self.stdout = stdout | ||
self.stderr = stderr | ||
self.success = success | ||
|
||
|
||
class TestAdbDevice(unittest.TestCase): | ||
|
||
@parameterized.expand([ | ||
('/sdcard/test.txt', './foo', 'pull /sdcard/test.txt ./foo'), | ||
('/sdcard/test file.txt', './foo', 'pull \'/sdcard/test file.txt\' ./foo'), | ||
('/sdcard/test.txt', './foo bar', 'pull /sdcard/test.txt \'./foo bar\''), | ||
('/sdcard/test file.txt', './foo bar', 'pull \'/sdcard/test file.txt\' \'./foo bar\'') | ||
]) | ||
@patch('adb_pywrapper.adb_device.AdbDevice._adb_command') | ||
def test_pull(self, file_to_pull, destination, expected_command, mock_adb_command): | ||
try: | ||
device = AdbDevice() | ||
result = device.pull(file_to_pull, destination) | ||
|
||
mock_adb_command.assert_called_once_with(expected_command, None) | ||
self.assertTrue(os.path.exists(destination)) # destination folder should have bene created | ||
self.assertFalse( | ||
result.success) # this is set to True if the file has been copied to the destination. We didn't copy anything | ||
expected_result_path = Path(destination) / basename(file_to_pull) | ||
self.assertEqual(f'./{str(expected_result_path)}', result.path) | ||
finally: | ||
shutil.rmtree(destination) | ||
|
||
@patch('adb_pywrapper.adb_device.AdbDevice._adb_command') | ||
def test_ls(self, mock_adb_command): | ||
device = AdbDevice() | ||
# happy flow | ||
mock_adb_command.return_value = MockAdbResult('foo.txt\nbar.txt', '') | ||
result = device.ls('/sdcard') | ||
mock_adb_command.assert_called_once_with('shell ls /sdcard', None) | ||
self.assertEqual(['foo.txt', 'bar.txt'], result) | ||
# escape special characters | ||
device.ls('/sdcard/test folder') | ||
mock_adb_command.assert_called_with('shell ls \'/sdcard/test folder\'', None) | ||
|
||
@patch('adb_pywrapper.adb_device.AdbDevice._adb_command') | ||
def test_install(self, mock_adb_command): | ||
device = AdbDevice() | ||
result = device.install('/path/to/apk') | ||
mock_adb_command.assert_called_once_with('install /path/to/apk', None) | ||
result = device.install('/path/to/other apk') | ||
mock_adb_command.assert_called_with('install \'/path/to/other apk\'', None) | ||
result = device.install('/path/to/yet another apk', True) | ||
mock_adb_command.assert_called_with('install -r \'/path/to/yet another apk\'', None) | ||
|
||
@patch('adb_pywrapper.adb_device.AdbDevice._adb_command') | ||
def test_install_multiple(self, mock_adb_command): | ||
device = AdbDevice() | ||
result = device.install_multiple(['foo.apk', 'bar.apk']) | ||
mock_adb_command.assert_called_once_with('install-multiple foo.apk bar.apk', None) | ||
result = device.install_multiple(['foo bar.apk', 'bar foo.apk']) | ||
mock_adb_command.assert_called_with("install-multiple 'foo bar.apk' 'bar foo.apk'", None) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters