Ejemplo n.º 1
0
def test_get_browser_versions():
    for browser in browser_list:
        assert (
            len(utils.get_browser_versions(browser))
            ==
            settings.BROWSERS_COUNT_LIMIT
        )
Ejemplo n.º 2
0
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')
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
def test_get_browser_versions():
    if not service_failed:
        for browser in browser_list:
            assert len(utils.get_browser_versions(browser)) == settings.BROWSERS_COUNT_LIMIT  # noqa
Ejemplo n.º 6
0
# 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)
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
def test_get_browser_versions():
    for browser in browser_list:
        assert (len(utils.get_browser_versions(browser)) ==
                settings.BROWSERS_COUNT_LIMIT)