Path: blob/trunk/py/test/selenium/webdriver/common/proxy_tests.py
3995 views
# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.1617import pytest1819from selenium.webdriver.common.options import ArgOptions20from selenium.webdriver.common.proxy import Proxy, ProxyType2122MANUAL_PROXY = {23"httpProxy": "some.url:1234",24"noProxy": "localhost, foo.localhost",25"sslProxy": "ssl.proxy:1234",26"socksProxy": "socks.proxy:65555",27"socksUsername": "test",28"socksPassword": "test",29"socksVersion": 5,30}3132PAC_PROXY = {33"proxyAutoconfigUrl": "http://pac.url:1234",34}3536AUTODETECT_PROXY = {37"autodetect": True,38}394041def test_can_add_manual_proxy_to_options():42proxy = Proxy()43proxy.http_proxy = MANUAL_PROXY["httpProxy"]44proxy.no_proxy = MANUAL_PROXY["noProxy"]45proxy.sslProxy = MANUAL_PROXY["sslProxy"]46proxy.socksProxy = MANUAL_PROXY["socksProxy"]47proxy.socksUsername = MANUAL_PROXY["socksUsername"]48proxy.socksPassword = MANUAL_PROXY["socksPassword"]49proxy.socksVersion = MANUAL_PROXY["socksVersion"]5051options = ArgOptions()52options.proxy = proxy5354proxy_capabilities = MANUAL_PROXY.copy()55proxy_capabilities["proxyType"] = "manual"56assert proxy_capabilities == options.to_capabilities().get("proxy")575859def test_can_add_autodetect_proxy_to_options():60proxy = Proxy()61proxy.auto_detect = AUTODETECT_PROXY["autodetect"]6263options = ArgOptions()64options.proxy = proxy6566proxy_capabilities = AUTODETECT_PROXY.copy()67proxy_capabilities["proxyType"] = "autodetect"68assert proxy_capabilities == options.to_capabilities().get("proxy")697071def test_can_add_pacproxy_to_options():72proxy = Proxy()73proxy.proxy_autoconfig_url = PAC_PROXY["proxyAutoconfigUrl"]7475options = ArgOptions()76options.proxy = proxy7778proxy_capabilities = PAC_PROXY.copy()79proxy_capabilities["proxyType"] = "pac"80assert proxy_capabilities == options.to_capabilities().get("proxy")818283def test_can_not_change_initialized_proxy_type():84proxy = Proxy(raw={"proxyType": "direct"})85with pytest.raises(Exception):86proxy.proxy_type = ProxyType.SYSTEM8788proxy = Proxy(raw={"proxyType": ProxyType.DIRECT})89with pytest.raises(Exception):90proxy.proxy_type = ProxyType.SYSTEM919293def test_can_init_manual_proxy():94proxy = Proxy(raw=MANUAL_PROXY)9596assert ProxyType.MANUAL == proxy.proxy_type97assert MANUAL_PROXY["httpProxy"] == proxy.http_proxy98assert MANUAL_PROXY["noProxy"] == proxy.no_proxy99assert MANUAL_PROXY["sslProxy"] == proxy.sslProxy100assert MANUAL_PROXY["socksProxy"] == proxy.socksProxy101assert MANUAL_PROXY["socksUsername"] == proxy.socksUsername102assert MANUAL_PROXY["socksPassword"] == proxy.socksPassword103assert MANUAL_PROXY["socksVersion"] == proxy.socksVersion104105106def test_can_init_autodetect_proxy():107proxy = Proxy(raw=AUTODETECT_PROXY)108assert ProxyType.AUTODETECT == proxy.proxy_type109assert AUTODETECT_PROXY["autodetect"] == proxy.auto_detect110111112def test_can_init_pacproxy():113proxy = Proxy(raw=PAC_PROXY)114assert ProxyType.PAC == proxy.proxy_type115assert PAC_PROXY["proxyAutoconfigUrl"] == proxy.proxy_autoconfig_url116117118def test_can_init_empty_proxy():119proxy = Proxy()120assert ProxyType.UNSPECIFIED == proxy.proxy_type121assert "" == proxy.http_proxy122assert "" == proxy.no_proxy123assert "" == proxy.sslProxy124assert "" == proxy.socksProxy125assert "" == proxy.socksUsername126assert "" == proxy.socksPassword127assert proxy.auto_detect is False128assert "" == proxy.proxy_autoconfig_url129assert proxy.socks_version is None130131options = ArgOptions()132options.proxy = proxy133134proxy_capabilities = {}135proxy_capabilities["proxyType"] = "unspecified"136assert proxy_capabilities == options.to_capabilities().get("proxy")137138139