def test_get_app_fails_if_telemetry_user_id_is_not_defined(): initial_telemetry_user_value = os.getenv("TELEMETRY_USER_ID") try: os.environ["TELEMETRY_USER_ID"] = "" with mock.patch('sys.stderr', new=StringIO()) as fake_stderr: get_app() except SystemExit as e: assert fake_stderr.getvalue().startswith('ERROR: Please') assert e.code == 1 else: pytest.fail("get_app did not raise") finally: os.environ["TELEMETRY_USER_ID"] = initial_telemetry_user_value
async def test_route_have_cors_enabled(cli): app = get_app() for r in app.router.resources(): info = r.get_info() if 'path' in info: url = info['path'] elif 'formatter' in info: formatter = info['formatter'] if '{product}' in formatter: formatter = formatter.replace('{product}', 'firefox') if '{version}' in formatter: formatter = formatter.replace('{version}', '52.0') elif 'prefix' in info: if info['prefix'].startswith(SWAGGER_PREFIX): continue else: import pdb pdb.set_trace() else: # A new case to handle import pdb pdb.set_trace() # Handle swagger URL if url.startswith(SWAGGER_PREFIX): continue await check_cors(cli, url)
def cli(loop, test_client): async def error403(request): raise web.HTTPForbidden() async def error404(request): return web.HTTPNotFound() async def error(request): raise ValueError() app = get_app(loop=loop) app.router.add_get('/error', error) app.router.add_get('/error-403', error403) app.router.add_get('/error-404', error404) return loop.run_until_complete(test_client(app))
def cli(loop, test_client): return loop.run_until_complete(test_client(get_app(loop=loop)))