Skip to content

Commit cd59d45

Browse files
authored
Add remote_fs unittest (appium#410)
* Add test_push_file unittest * Add test_pull_file unittest * Add remote_fs error cases unittest
1 parent 2cfcf09 commit cd59d45

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env python
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import base64
16+
17+
import httpretty
18+
import pytest
19+
from selenium.common.exceptions import InvalidArgumentException
20+
21+
from appium.common.helper import appium_bytes
22+
from appium.webdriver.webdriver import WebDriver
23+
from test.unit.helper.test_helper import (
24+
android_w3c_driver,
25+
appium_command,
26+
get_httpretty_request_body
27+
)
28+
29+
30+
class TestWebDriverRemoteFs(object):
31+
32+
@httpretty.activate
33+
def test_push_file(self):
34+
driver = android_w3c_driver()
35+
httpretty.register_uri(
36+
httpretty.POST,
37+
appium_command('/session/1234567890/appium/device/push_file'),
38+
)
39+
dest_path = '/path/to/file.txt'
40+
data = base64.b64encode(appium_bytes('HelloWorld', 'utf-8')).decode('utf-8')
41+
42+
assert isinstance(driver.push_file(dest_path, data), WebDriver)
43+
44+
d = get_httpretty_request_body(httpretty.last_request())
45+
assert d['path'] == dest_path
46+
assert d['data'] == str(data)
47+
48+
@httpretty.activate
49+
def test_push_file_invalid_arg_exception_without_src_path_and_base64data(self):
50+
driver = android_w3c_driver()
51+
httpretty.register_uri(
52+
httpretty.POST,
53+
appium_command('/session/1234567890/appium/device/push_file'),
54+
)
55+
dest_path = '/path/to/file.txt'
56+
57+
with pytest.raises(InvalidArgumentException):
58+
driver.push_file(dest_path)
59+
60+
@httpretty.activate
61+
def test_push_file_invalid_arg_exception_with_src_file_not_found(self):
62+
driver = android_w3c_driver()
63+
httpretty.register_uri(
64+
httpretty.POST,
65+
appium_command('/session/1234567890/appium/device/push_file'),
66+
)
67+
dest_path = '/dest_path/to/file.txt'
68+
src_path = '/src_path/to/file.txt'
69+
70+
with pytest.raises(InvalidArgumentException):
71+
driver.push_file(dest_path, source_path=src_path)
72+
73+
@httpretty.activate
74+
def test_pull_file(self):
75+
driver = android_w3c_driver()
76+
httpretty.register_uri(
77+
httpretty.POST,
78+
appium_command('/session/1234567890/appium/device/pull_file'),
79+
body='{"value": "SGVsbG9Xb3JsZA=="}'
80+
)
81+
dest_path = '/path/to/file.txt'
82+
83+
assert driver.pull_file(dest_path) == str(base64.b64encode(appium_bytes('HelloWorld', 'utf-8')).decode('utf-8'))
84+
85+
d = get_httpretty_request_body(httpretty.last_request())
86+
assert d['path'] == dest_path
87+
88+
@httpretty.activate
89+
def test_pull_folder(self):
90+
driver = android_w3c_driver()
91+
httpretty.register_uri(
92+
httpretty.POST,
93+
appium_command('/session/1234567890/appium/device/pull_folder'),
94+
body='{"value": "base64EncodedZippedFolderData"}'
95+
)
96+
dest_path = '/path/to/file.txt'
97+
98+
assert driver.pull_folder(dest_path) == 'base64EncodedZippedFolderData'
99+
100+
d = get_httpretty_request_body(httpretty.last_request())
101+
assert d['path'] == dest_path

0 commit comments

Comments
 (0)