forked from appium/python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote_fs_tests.py
More file actions
58 lines (44 loc) · 2.19 KB
/
remote_fs_tests.py
File metadata and controls
58 lines (44 loc) · 2.19 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import base64
import os
import random
from io import BytesIO
from zipfile import ZipFile
from .helper.test_helper import BaseTestCase
class TestRemoteFs(BaseTestCase):
def test_push_pull_file(self) -> None:
dest_path = '/data/local/tmp/test_push_file.txt'
data = bytes('This is the contents of the file to push to the device.', 'utf-8')
self.driver.push_file(dest_path, base64.b64encode(data).decode('utf-8'))
data_ret = base64.b64decode(self.driver.pull_file(dest_path))
assert data == data_ret
def test_pull_folder(self) -> None:
data = bytes('random string data {}'.format(random.randint(0, 1000)), 'utf-8')
dest_dir = '/data/local/tmp/'
for filename in ['1.txt', '2.txt']:
self.driver.push_file(os.path.join(dest_dir, filename), base64.b64encode(data).decode('utf-8'))
folder = self.driver.pull_folder(dest_dir)
with ZipFile(BytesIO(base64.b64decode(folder))) as fzip:
for filename in ['1.txt', '2.txt']:
assert filename in fzip.namelist()
def test_push_file_with_src_path(self) -> None:
test_files = ['test_image.jpg', 'test_file.txt']
for file_name in test_files:
src_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'file', file_name)
dest_path = os.path.join('/data/local/tmp/', file_name)
with open(src_path, 'rb') as fr:
original_data = fr.read()
self.driver.push_file(dest_path, source_path=src_path)
new_data = base64.b64decode(self.driver.pull_file(dest_path))
assert original_data == new_data