Best Python code snippet using Airtest
test_service_proxy.py
Source:test_service_proxy.py
...4import requests_mock5import arpoc6import arpoc.config7@pytest.fixture8def setup_proxy():9 cfg = arpoc.config.OIDCProxyConfig(None, None)10 cfg.proxy = arpoc.config.ProxyConfig("", "", "testhost.example.com",11 ["test@example.com"],12 ["testhost.example.com/redirect"])13 cfg.services['default'] = arpoc.config.ServiceConfig(14 "url_orig", "pathproxied", "policyset")15 oidc_handler = arpoc.OidcHandler(cfg)16 service_a = arpoc.ServiceProxy("default", oidc_handler,17 cfg.services['default'])18 return (oidc_handler, service_a)19@pytest.fixture20def setup_proxy_bearer():21 cfg = arpoc.config.OIDCProxyConfig(None, None)22 cfg.proxy = arpoc.config.ProxyConfig("", "", "testhost.example.com",...
setproxy.py
Source:setproxy.py
...29 """30 return ''.join([c if c.isalnum() else _ashex(c) for c in pwd])31def _ashex(char):32 return '%' + hex(ord(char))[2:]33def setup_proxy(host, port, username='', password=''):34 """Enable proxy support for accessing an external network35 Args:36 host (str): Name of the proxy host to connect to37 port (int): Port number on which proxy is listening38 username (str): Name to login as (in case of authenticated proxy)39 password (str): plain text password for proxy authentication40 Returns:41 None42 Examples:43 For use with a proxy not requiring authentatication44 >>> setup_proxy('10.0.0.1', 3128)45 and for one requiring authentication46 >>> setup_proxy('192.168.1.2', 3128, 'me', 'mypassword')47 """48 pwd = hexpass(password)49 prefix = ''50 if username:51 prefix += username52 if pwd:53 prefix = prefix + ':' + pwd54 if prefix:55 prefix += '@'56 auth = 'http://%s%s:%s' % (prefix, host, port)57 proxy_handler = urllib2.ProxyHandler({'ftp': auth,58 'http': auth})59 opener = urllib2.build_opener(proxy_handler,60 urllib2.HTTPBasicAuthHandler(),...
metods.py
Source:metods.py
1import os2import re3import requests4def get_interface(filename):5 check_interfae = os.path.exists(filename)6 if check_interfae:7 f = open(filename,'r')8 for line in f:9 if line.find('state UP') != -1:10 interfase = line.split(':')[1][1::]11 f.close()12 return interfase13 else:14 return 'No file'15 16def set_inteface_to_conf(interfase):17 f = open('setup_proxy/danted.conf')18 line = f.read()19 f.close()20 line = line.replace('$',interfase)21 f1 = open('/etc/danted.conf', 'w')22 a = f1.write(line)23 f1.close24def check_proxy():25 f = open('setup_proxy/ip.txt','r')26 ip = f.read()27 f.close()28 is_ip = re.findall(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$",ip) 29 if len(is_ip) == 1:30 return True31 else:32 return False33def info_proxy():34 r = open('setup_proxy/ip.txt','r')35 ip = r.read()36 r.close()37 url = 'http://ipinfo.io/'+ip+'/json'38 response = requests.get(url)39 text = response.text40 f = open('setup_proxy/info_proxy.json','w')41 f.write(text)42 f.close()43if __name__ == '__main__':44 choose = int(input())45 if choose == 1:46 interfase = get_interface('setup_proxy/interfase.txt')47 set_inteface_to_conf(interfase)48 print('OK')49 elif choose == 2:50 print(check_proxy())51 elif choose == 3:52 info_proxy()53 else:54 print('ERROR')...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!