def test_utils_get_browsers(): browsers = utils.get_browsers() assert len(browsers) == 5 expected = [ 'Firefox', 'Opera', 'Chrome', 'Internet Explorer', 'Safari', ] browser_names = [browser[0] for browser in browsers] assert set(expected) == set(browser_names) total = 100 for _, percentage in browsers: total -= float(percentage) assert round(total, 0) <= 2 if urlopen_has_ssl_context: with mock.patch( 'fake_useragent.utils.Request', side_effect=partial( _request, response_url='https://expired.badssl.com/', ), ): with pytest.raises(errors.FakeUserAgentError): utils.get_browsers()
def test_utils_get_browser_versions_no_browser_versions(): browser_names = [browser[0] for browser in utils.get_browsers()] for browser in browser_names: with mock.patch('fake_useragent.utils.urlopen') as mocked: path = os.path.join(assets, 'no_browser_versions.html') with io.open(path, mode='rb') as fp: m = mock.Mock() m.read = fp.read mocked.return_value = m with pytest.raises(errors.FakeUserAgentError) as ctx: utils.get_browser_versions(browser) assert ctx.value.args[0].startswith('No browsers version')
def test_utils_get_browser_versions(): browser_names = [browser[0] for browser in utils.get_browsers()] for browser in browser_names: count = len(utils.get_browser_versions(browser)) assert count == settings.BROWSERS_COUNT_LIMIT if urlopen_has_ssl_context: with mock.patch( 'fake_useragent.utils.Request', side_effect=partial( _request, response_url='https://expired.badssl.com/', ), ): with pytest.raises(errors.FakeUserAgentError): utils.get_browser_versions(browser)
def test_get_browsers(): browsers = utils.get_browsers() browser_list = [] for browser in browsers: # ie becomes popular !? xD if browser[0] == 'Internet Explorer': assert int(float(browser[1])) < 20 browser_list.append(browser[0]) assert len(browser_list) == 5 assert 'Firefox' in browser_list assert 'Opera' in browser_list assert 'Chrome' in browser_list assert 'Internet Explorer' in browser_list assert 'Safari' in browser_list global browser_list
def test_utils_get_browsers(): browsers = utils.get_browsers() assert len(browsers) == 5 expected = [ 'Firefox', 'Opera', 'Chrome', 'Internet Explorer', 'Safari', ] browser_names = [browser[0] for browser in browsers] assert set(expected) == set(browser_names) total = 100 for _, percentage in browsers: total -= float(percentage) assert round(total, 0) <= 2
# with open('./user-agent.json','r') as f: # with open('./user_agent_list.txt','w') as f2: # true_user_agent_json = json.loads(f.read()) # print(type(true_user_agent_json)) # print(true_user_agent_json.keys()) # # dict_keys(['browsers', 'randomize']) # # dict_keys(['chrome', 'opera', 'firefox', 'internetexplorer', 'safari']) # print(true_user_agent_json['browsers'].keys()) # for x in true_user_agent_json['browsers']: # for browser in true_user_agent_json['browsers'][x]: # f2.write('\'') # f2.write(browser) # f2.write('\'') # f2.write(',') # f2.write('\n') # # # # 总共有200; from fake_useragent import utils # ua = UserAgent() # print(ua) # print(ua.ie) # print(help(ua)) ret = utils.load() print(utils.get_browsers()) print(len(utils.get_browser_versions('Chrome'))) print(ret)
def test_utils_get_browser_versions(): browser_names = [browser[0] for browser in utils.get_browsers()] for browser in browser_names: count = len(utils.get_browser_versions(browser)) assert count == settings.BROWSERS_COUNT_LIMIT