def test_utils_get(): assert utils.get('http://google.com') is not None if urlopen_has_ssl_context: with pytest.raises(errors.FakeUserAgentError): utils.get('https://expired.badssl.com/') assert utils.get( 'https://expired.badssl.com/', verify_ssl=False, ) is not None
def test_get_services(): service_failed = False global service_failed try: html = utils.get(settings.BROWSERS_STATS_PAGE) assert len(html) > 0 html = utils.get(settings.BROWSER_BASE_PAGE.format(browser='Firefox')) assert len(html) > 0 except FakeUserAgentError: service_failed = True
def test_utils_get_cache_server(): body = utils.get(settings.CACHE_SERVER).decode('utf-8') data = json.loads(body) expected = { 'randomize': mock.ANY, 'browsers': { 'chrome': mock.ANY, 'firefox': mock.ANY, 'opera': mock.ANY, 'safari': mock.ANY, 'internetexplorer': mock.ANY, }, } assert expected == data
def test_utils_get_retries(): def __retried_request(*args, **kwargs): # noqa __retried_request.attempt += 1 if __retried_request.attempt < settings.HTTP_RETRIES: return Request('http://0.0.0.0:{port}'.format( port=find_unused_port(), )) return Request(*args, **kwargs) __retried_request.attempt = 0 with mock.patch( 'fake_useragent.utils.Request', side_effect=__retried_request, ): assert utils.get('http://google.com') is not None assert __retried_request.attempt == 2
def test_get_args(): html = utils.get(settings.BROWSER_BASE_PAGE, 'Firefox') assert len(html) > 0
def test_get_no_args(): html = utils.get(settings.BROWSERS_STATS_PAGE) assert len(html) > 0
def test_get_cache(): html = utils.get(settings.CACHE_SERVER) data = json.loads(html.decode('utf-8')) check_dict(data)
def test_get_args(): html = utils.get(settings.BROWSER_BASE_PAGE.format(browser='Firefox')) assert len(html) > 0
def test_utils_get(): assert utils.get('http://google.com') is not None