def test_it_works_with_endpoints(self, app): with pytest.raises(BuildError): assert url_for('some.endpoint') with app.test_request_context(): app.add_url_rule('/some-endpoint', endpoint='some.endpoint') assert url_for('some.endpoint') == '/some-endpoint'
def test_it_falls_through_if_class_endpoint_not_found(self, app): class SiteResource(Resource): def get(self, id): pass with app.test_request_context(): app.add_url_rule('/sites/<int:id>', endpoint='site_resource.get') with pytest.raises(BuildError): url_for('delete', id=1, _cls=SiteResource)
def test_it_works_with_config_keys_returning_endpoints(self, app): app.config.from_mapping({'MY_KEY': 'some.endpoint'}) with pytest.raises(BuildError): assert url_for('MY_KEY') with app.test_request_context(): app.add_url_rule('/some-endpoint', endpoint='some.endpoint') assert url_for('MY_KEY') == '/some-endpoint'
def test_it_works_with_url_for_kwargs(self, app): class SiteResource(Resource): def get(self, id): pass with app.test_request_context(): app.add_url_rule('/sites/<int:id>', endpoint='site_resource.get') assert url_for('get', id=1, _cls=SiteResource) == '/sites/1' app.add_url_rule('/foo/<string:slug>', endpoint='some.endpoint') assert url_for('some.endpoint', slug='hi') == '/foo/hi'
def test_it_works_with_controller_method_names(self, app): class SiteController(Controller): def about_us(self): pass with app.test_request_context(): app.add_url_rule('/about-us', endpoint='site_controller.about_us') assert url_for('about_us', _cls=SiteController) == '/about-us'
def test_it_works_with_config_keys_returning_path(self, app): app.config.from_mapping({'MY_KEY': '/my-key'}) assert url_for('MY_KEY') == '/my-key'
def test_it_works_with_garbage(self): assert url_for(None) is None
def test_it_works_with_already_formed_path(self): assert url_for('/foobar') == '/foobar'