How to use _get_user_agent method in yandex-tank

Best Python code snippet using yandex-tank

test_webpagereader.py

Source:test_webpagereader.py Github

copy

Full Screen

...34 """35 with patch('openlp.core.lib.webpagereader.sys') as mocked_sys:36 # GIVEN: The system is Linux37 mocked_sys.platform = 'linux2'38 # WHEN: We call _get_user_agent()39 user_agent = _get_user_agent()40 # THEN: The user agent is a Linux (or ChromeOS) user agent41 result = 'Linux' in user_agent or 'CrOS' in user_agent42 self.assertTrue(result, 'The user agent should be a valid Linux user agent')43 def test_get_user_agent_windows(self):44 """45 Test that getting a user agent on Windows returns a user agent suitable for Windows46 """47 with patch('openlp.core.lib.webpagereader.sys') as mocked_sys:48 # GIVEN: The system is Linux49 mocked_sys.platform = 'win32'50 # WHEN: We call _get_user_agent()51 user_agent = _get_user_agent()52 # THEN: The user agent is a Linux (or ChromeOS) user agent53 self.assertIn('Windows', user_agent, 'The user agent should be a valid Windows user agent')54 def test_get_user_agent_macos(self):55 """56 Test that getting a user agent on OS X returns a user agent suitable for OS X57 """58 with patch('openlp.core.lib.webpagereader.sys') as mocked_sys:59 # GIVEN: The system is Linux60 mocked_sys.platform = 'darwin'61 # WHEN: We call _get_user_agent()62 user_agent = _get_user_agent()63 # THEN: The user agent is a Linux (or ChromeOS) user agent64 self.assertIn('Mac OS X', user_agent, 'The user agent should be a valid OS X user agent')65 def test_get_user_agent_default(self):66 """67 Test that getting a user agent on a non-Linux/Windows/OS X platform returns the default user agent68 """69 with patch('openlp.core.lib.webpagereader.sys') as mocked_sys:70 # GIVEN: The system is Linux71 mocked_sys.platform = 'freebsd'72 # WHEN: We call _get_user_agent()73 user_agent = _get_user_agent()74 # THEN: The user agent is a Linux (or ChromeOS) user agent75 self.assertIn('NetBSD', user_agent, 'The user agent should be the default user agent')76 def test_get_web_page_no_url(self):77 """78 Test that sending a URL of None to the get_web_page method returns None79 """80 # GIVEN: A None url81 test_url = None82 # WHEN: We try to get the test URL83 result = get_web_page(test_url)84 # THEN: None should be returned85 self.assertIsNone(result, 'The return value of get_web_page should be None')86 def test_get_web_page(self):87 """...

Full Screen

Full Screen

requests.py

Source:requests.py Github

copy

Full Screen

...68 hostname = urlsplit(url)[1]69 if '@' in hostname:70 hostname = hostname.split('@')[1]71 return certs.get(hostname, True)72def _get_user_agent(config: Config) -> str:73 if config.user_agent:74 return config.user_agent75 else:76 return ' '.join([77 'Sphinx/%s' % sphinx.__version__,78 'requests/%s' % requests.__version__,79 'python/%s' % '.'.join(map(str, sys.version_info[:3])),80 ])81def get(url: str, **kwargs: Any) -> requests.Response:82 """Sends a GET request like requests.get().83 This sets up User-Agent header and TLS verification automatically."""84 headers = kwargs.setdefault('headers', {})85 config = kwargs.pop('config', None)86 if config:87 kwargs.setdefault('verify', _get_tls_cacert(url, config))88 headers.setdefault('User-Agent', _get_user_agent(config))89 else:90 headers.setdefault('User-Agent', useragent_header[0][1])91 with ignore_insecure_warning(**kwargs):92 return requests.get(url, **kwargs)93def head(url: str, **kwargs: Any) -> requests.Response:94 """Sends a HEAD request like requests.head().95 This sets up User-Agent header and TLS verification automatically."""96 headers = kwargs.setdefault('headers', {})97 config = kwargs.pop('config', None)98 if config:99 kwargs.setdefault('verify', _get_tls_cacert(url, config))100 headers.setdefault('User-Agent', _get_user_agent(config))101 else:102 headers.setdefault('User-Agent', useragent_header[0][1])103 with ignore_insecure_warning(**kwargs):...

Full Screen

Full Screen

driver.py

Source:driver.py Github

copy

Full Screen

...18 def __init__(self, base_path, driver) -> None:19 self.base_path = base_path20 self.driver = driver21 @abstractclassmethod22 def _get_user_agent(self):23 pass24class Chrome(Driver):25 def __init__(self, base_path) -> None:26 driver = uc.Chrome(27 executable_path=os.path.join(base_path, "chromedriver.exe"),28 chrome_options=self._get_user_agent(),29 )30 super().__init__(base_path, driver)31 def _get_user_agent(self):32 opts = Options()33 opts.add_argument(34 "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36"35 )36 return opts37class Firefox(Driver):38 def __init__(self, base_path) -> None:39 driver = webdriver.Firefox(40 executable_path=os.path.join(base_path, "geckodriver.exe"),41 firefox_profile=self._get_user_agent(),42 )43 super().__init__(base_path, driver)44 def _get_user_agent(self):45 profile = webdriver.FirefoxProfile()46 profile.set_preference("general.useragent.override", self.user_agent)47 return profile48def get_driver(base_path, browser="chrome"):49 driver = {"chrome": Chrome, "firefox": Firefox}...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run yandex-tank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful