Ejemplo n.º 1
0
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')
Ejemplo n.º 2
0
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)))
Ejemplo n.º 3
0
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')
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
 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))
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
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
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