def test_traverse_with_verbose(): """Ensure traverse() finds the proper routes and outputs verbose info.""" output = compat.StringIO() with redirected(stdout=output): print_routes.traverse(_api._router._roots, verbose=True) route, get_info, options_info = output.getvalue().strip().split('\n') assert '-> /test' == route # NOTE(kgriffs) We might receive these in either order, since the # method map is not ordered, so check and swap if necessary. if options_info.startswith('-->GET'): get_info, options_info = options_info, get_info assert options_info.startswith('-->OPTIONS') if cython: assert options_info.endswith('[unknown file]') else: assert 'falcon/responders.py:' in options_info assert get_info.startswith('-->GET') # NOTE(vytas): This builds upon the fact that on_get is defined on line 14 # in this file. Adjust the test if the said responder is relocated, or just # check for any number if this becomes too painful to maintain. assert get_info.endswith('tests/test_cmd_print_api.py:14')
def test_traverse_with_verbose(app): """Ensure traverse() finds the proper routes and outputs verbose info.""" output = io.StringIO() with redirected(stdout=output): print_routes.traverse(app._router._roots, verbose=True) route, get_info, options_info = output.getvalue().strip().split('\n') assert '-> /test' == route # NOTE(kgriffs) We might receive these in either order, since the # method map is not ordered, so check and swap if necessary. if options_info.startswith('-->GET'): get_info, options_info = options_info, get_info assert options_info.startswith('-->OPTIONS') assert '{}:'.format(normpath('falcon/responders.py')) in options_info assert get_info.startswith('-->GET') # NOTE(vytas): This builds upon the fact that on_get is defined on line # 18 or 25 (in the case of DummyResourceAsync) in the present file. # Adjust the test if the said responder is relocated, or just check for # any number if this becomes too painful to maintain. path = normpath('tests/test_cmd_print_api.py') assert (get_info.endswith('{}:14'.format(path)) or get_info.endswith('{}:21'.format(path)))
def test_traverse_with_verbose(): """Ensure traverse() finds the proper routes and outputs verbose info.""" output = io.StringIO() with redirected(stdout=output): print_routes.traverse(_api._router._roots, verbose=True) route, get_info, options_info = output.getvalue().strip().split('\n') assert '-> /test' == route # NOTE(kgriffs) We might receive these in either order, since the # method map is not ordered, so check and swap if necessary. if options_info.startswith('-->GET'): get_info, options_info = options_info, get_info assert options_info.startswith('-->OPTIONS') if cython: assert options_info.endswith('[unknown file]') else: assert 'falcon/responders.py:' in options_info assert get_info.startswith('-->GET') # NOTE(vytas): This builds upon the fact that on_get is defined on line 14 # in this file. Adjust the test if the said responder is relocated, or just # check for any number if this becomes too painful to maintain. assert get_info.endswith('tests/test_cmd_print_api.py:15')
def test_traverse(): """Ensure traverse() finds the proper routes.""" output = compat.StringIO() with redirected(stdout=output): print_routes.traverse(_api._router._roots, verbose=False) route = output.getvalue().strip() assert '-> /test' == route
def test_traverse(): """Ensure traverse() finds the proper routes.""" output = six.moves.StringIO() with redirected(stdout=output): print_routes.traverse(_api._router._roots, verbose=False) route = output.getvalue().strip() assert '-> /test' == route
def test_traverse_with_verbose(): """Ensure traverse finds the proper routes and adds verbose output.""" output = six.moves.StringIO() with redirected(stdout=output): print_routes.traverse(_api._router._roots, verbose=True) route, options = output.getvalue().strip().split('\n') assert '-> /test' == route assert 'OPTIONS' in options assert 'falcon/responders.py:' in options
def test_inspect(self, verbose, internal, monkeypatch): args = ['some-file.py', '{}:{}'.format(_MODULE, '_APP')] if verbose: args.append('-v') if internal: args.append('-i') monkeypatch.setattr('sys.argv', args) output = io.StringIO() with redirected(stdout=output): inspect_app.main() ins = inspect.inspect_app(_APP) self.check(output.getvalue().strip(), ins.to_string(verbose, internal))
def test_route_main(monkeypatch): called = False def mock(): nonlocal called called = True monkeypatch.setattr(inspect_app, 'main', mock) output = io.StringIO() with redirected(stdout=output): inspect_app.route_main() assert 'deprecated' in output.getvalue() assert called
def test_routes_only(self, verbose, internal, monkeypatch): args = ['some-file.py', '{}:{}'.format(_MODULE, '_APP'), '-r'] if verbose: args.append('-v') if internal: args.append('-i') monkeypatch.setattr('sys.argv', args) output = io.StringIO() with redirected(stdout=output): inspect_app.main() routes = inspect.inspect_routes(_APP) sv = inspect.StringVisitor(verbose, internal) expect = '\n'.join([sv.process(r) for r in routes]) self.check(output.getvalue().strip(), expect)
def test_traverse_with_verbose(): """Ensure traverse finds the proper routes and adds verbose output for a method function as well as the OPTIONS partial.""" output = six.moves.StringIO() with redirected(stdout=output): print_routes.traverse(_api._router._roots, verbose=True) route, method, options = output.getvalue().strip().split('\n') assert '-> /test' == route # Check in both methods and options for the GET method # because method map is not ordered assert 'GET' in method + options if 'GET' in method: assert 'OPTIONS' in options assert 'falcon/responders.py:' in options else: assert 'OPTIONS' in method assert 'falcon/responders.py:' in method
def test_traverse_with_verbose(): """Ensure traverse() finds the proper routes and outputs verbose info.""" output = six.moves.StringIO() with redirected(stdout=output): print_routes.traverse(_api._router._roots, verbose=True) route, get_info, options_info = output.getvalue().strip().split('\n') assert '-> /test' == route # NOTE(kgriffs) We might receive these in either order, since the # method map is not ordered, so check and swap if necessary. if options_info.startswith('-->GET'): get_info, options_info = options_info, get_info assert options_info.startswith('-->OPTIONS') assert 'falcon/responders.py:' in options_info assert get_info.startswith('-->GET') assert 'tests/test_cmd_print_api.py:' in get_info