From f3f85dcb6ef8660a3615b1d7933b399557080458 Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Fri, 4 Jan 2019 23:18:52 +0900 Subject: [PATCH 1/5] Add network connection test --- test/unit/webdriver/device/network_test.py | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/unit/webdriver/device/network_test.py diff --git a/test/unit/webdriver/device/network_test.py b/test/unit/webdriver/device/network_test.py new file mode 100644 index 00000000..c6b85d0b --- /dev/null +++ b/test/unit/webdriver/device/network_test.py @@ -0,0 +1,30 @@ +#!/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. + +from test.unit.helper.test_helper import appium_command, android_w3c_driver + + +import httpretty + +class TestWebDriverNetwork(object): + + @httpretty.activate + def test_network_connection(self): + driver = android_w3c_driver() + httpretty.register_uri( + httpretty.GET, + appium_command('/session/1234567890/network_connection'), + body='{"value": 2}' + ) + assert driver.network_connection == 2 From 626f1ae68e258da59eaf17cbbe6b391e6df2571c Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Sat, 5 Jan 2019 01:01:23 +0900 Subject: [PATCH 2/5] Added set network connection test --- test/unit/webdriver/device/network_test.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/unit/webdriver/device/network_test.py b/test/unit/webdriver/device/network_test.py index c6b85d0b..0deacba2 100644 --- a/test/unit/webdriver/device/network_test.py +++ b/test/unit/webdriver/device/network_test.py @@ -14,9 +14,9 @@ from test.unit.helper.test_helper import appium_command, android_w3c_driver - import httpretty + class TestWebDriverNetwork(object): @httpretty.activate @@ -28,3 +28,13 @@ def test_network_connection(self): body='{"value": 2}' ) assert driver.network_connection == 2 + + @httpretty.activate + def test_set_network_connection(self): + driver = android_w3c_driver() + httpretty.register_uri( + httpretty.POST, + appium_command('/session/1234567890/network_connection'), + body='{"value": 2}' + ) + assert driver.set_network_connection(2) == 2 From eb089ba20e94e1722c2b4b70d72f63c9f2093de2 Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Sat, 5 Jan 2019 01:07:00 +0900 Subject: [PATCH 3/5] Add toggle wifi test --- test/unit/webdriver/device/network_test.py | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/unit/webdriver/device/network_test.py b/test/unit/webdriver/device/network_test.py index 0deacba2..1a996916 100644 --- a/test/unit/webdriver/device/network_test.py +++ b/test/unit/webdriver/device/network_test.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from appium.webdriver.webdriver import WebDriver from test.unit.helper.test_helper import appium_command, android_w3c_driver import httpretty @@ -38,3 +39,26 @@ def test_set_network_connection(self): body='{"value": 2}' ) assert driver.set_network_connection(2) == 2 + + @httpretty.activate + def test_toggle_wifi(self): + driver = android_w3c_driver() + httpretty.register_uri( + httpretty.GET, + appium_command('/session/1234567890/network_connection'), + body='{"value": 0}' + ) + assert driver.network_connection == 0 + + httpretty.register_uri( + httpretty.POST, + appium_command('/session/1234567890/appium/device/toggle_wifi'), + ) + assert isinstance(driver.toggle_wifi(), WebDriver) is True + + httpretty.register_uri( + httpretty.GET, + appium_command('/session/1234567890/network_connection'), + body='{"value": 2}' + ) + assert driver.network_connection == 2 From 95e4550753ea67f429a9aaaf83bdb82b2adcbb5c Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Sat, 5 Jan 2019 14:19:23 +0900 Subject: [PATCH 4/5] Removed unnecessary codes from toggle wifi test --- test/unit/webdriver/device/network_test.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/test/unit/webdriver/device/network_test.py b/test/unit/webdriver/device/network_test.py index 1a996916..bbf25e4a 100644 --- a/test/unit/webdriver/device/network_test.py +++ b/test/unit/webdriver/device/network_test.py @@ -43,22 +43,8 @@ def test_set_network_connection(self): @httpretty.activate def test_toggle_wifi(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.GET, - appium_command('/session/1234567890/network_connection'), - body='{"value": 0}' - ) - assert driver.network_connection == 0 - httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/appium/device/toggle_wifi'), ) assert isinstance(driver.toggle_wifi(), WebDriver) is True - - httpretty.register_uri( - httpretty.GET, - appium_command('/session/1234567890/network_connection'), - body='{"value": 2}' - ) - assert driver.network_connection == 2 From 3d4487ddb03beb97da5d3140d85699bf79547844 Mon Sep 17 00:00:00 2001 From: Atsushi Mori Date: Sat, 5 Jan 2019 22:31:38 +0900 Subject: [PATCH 5/5] Changed assertion for set network connection test --- test/unit/webdriver/device/network_test.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/unit/webdriver/device/network_test.py b/test/unit/webdriver/device/network_test.py index bbf25e4a..0a0fd7c4 100644 --- a/test/unit/webdriver/device/network_test.py +++ b/test/unit/webdriver/device/network_test.py @@ -16,6 +16,7 @@ from test.unit.helper.test_helper import appium_command, android_w3c_driver import httpretty +import json class TestWebDriverNetwork(object): @@ -36,9 +37,12 @@ def test_set_network_connection(self): httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/network_connection'), - body='{"value": 2}' + body='{"value": ""}' ) - assert driver.set_network_connection(2) == 2 + driver.set_network_connection(2) + + d = json.loads(httpretty.last_request().body.decode('utf-8')) + assert d['parameters']['type'] == 2 @httpretty.activate def test_toggle_wifi(self):