def test_it_requires_a_callable(self): with pytest.raises(ValueError): list(func('/fail')) with pytest.raises(ValueError): list(func('/fail', None)) with pytest.raises(ValueError): list(func(None)) with pytest.raises(ValueError): list(func(None, undecorated_view))
def test_it_works_with_decorated_view(self): route = list(func(decorated_view))[0] assert route.view_func == decorated_view assert route.rule == '/decorated-view' assert route.blueprint is None assert route.endpoint == 'tests.bundles.controller.test_routes.decorated_view' assert route.defaults == {} assert route.methods == ['GET'] assert route.only_if is None
def test_override_rule_options_with_decorated_view(self): route = list(func('/b/<id>', decorated_view, blueprint=bp, endpoint='overridden.endpoint', defaults={'id': 1}, methods=['GET', 'POST'], only_if='only_if'))[0] assert route.rule == '/b/<id>' assert route.view_func == decorated_view assert route.blueprint == bp assert route.endpoint == 'overridden.endpoint' assert route.defaults == {'id': 1} assert route.methods == ['GET', 'POST'] assert route.only_if == 'only_if'
def test_it_does_not_mutate_existing_routes(self): route = list(func('/foo', decorated_view))[0] orig_route = getattr(decorated_view, FN_ROUTES_ATTR)[0] assert orig_route.endpoint == route.endpoint assert orig_route.rule == '/decorated-view' assert route.rule == '/foo'
def test_it_reuses_route_url_implicitly_matches(self): route = list(func(implicit_multi_route_view))[0] assert route.endpoint == 'default'
def test_it_reuses_route_if_url_matches_a_decorated_route(self): route = list(func('/first', multi_route_view, methods=['PUT']))[0] assert route.methods == ['PUT'] assert route.endpoint == 'first'
def test_it_makes_new_route_if_decorated_with_multiple_other_routes(self): route = list(func(multi_route_view))[0] assert route.endpoint == 'tests.bundles.controller.test_routes.multi_route_view'
from flask_unchained.bundles.controller.routes import func, include from .views import view_one, view_two routes = lambda: [ func(view_one), func(view_two), include('tests.bundles.controller.fixtures.vendor_bundle.routes'), include('tests.bundles.controller.fixtures.warning_bundle.routes'), ]