def test_it_works_with_only_a_controller_cls(self):
     routes = list(controller(SiteController))
     assert len(routes) == 2
     assert routes[0].endpoint == 'site_controller.index'
     assert routes[0].rule == '/'
     assert routes[1].endpoint == 'site_controller.about'
     assert routes[1].rule == '/about'
 def test_it_works_with_a_prefix_and_controller_cls(self):
     routes = list(controller('/prefix', SiteController))
     assert len(routes) == 2
     assert routes[0].endpoint == 'site_controller.index'
     assert routes[0].rule == '/prefix/'
     assert routes[1].endpoint == 'site_controller.about'
     assert routes[1].rule == '/prefix/about'
    def test_it_works(self):
        routes = list(controller(MultiRouteController))
        assert routes[0].full_rule == '/hello/<string:param>/'
        assert routes[0].endpoint == 'multi_route_controller.hello'
        assert not routes[0].defaults

        assert routes[1].rule == '/hello/'
        assert routes[1].endpoint == 'multi_route_controller.hello'
        assert routes[1].defaults == dict(param='DEFAULT')
Beispiel #4
0
 def test_it_does_not_mutate_existing_routes(self):
     routes = list(controller('/prefix', SiteController))
     orig_routes = [route
                    for routes in getattr(SiteController,
                                          CONTROLLER_ROUTES_ATTR).values()
                    for route in routes]
     assert orig_routes[0].endpoint == routes[0].endpoint
     assert orig_routes[0].rule == '/'
     assert routes[0].rule == '/prefix'
    def test_it_requires_a_controller_cls(self):
        with pytest.raises(ValueError):
            list(controller('/fail'))

        with pytest.raises(ValueError):
            list(controller('/fail', None))

        with pytest.raises(ValueError):
            list(controller(None))

        with pytest.raises(ValueError):
            list(controller(None, SiteController))

        with pytest.raises(TypeError):
            list(controller(UserResource))

        with pytest.raises(TypeError):
            list(controller('/users', UserResource))