Пример #1
0
    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'
Пример #2
0
    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)
Пример #3
0
    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'
Пример #4
0
    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'
Пример #5
0
    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'
Пример #6
0
 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'
Пример #7
0
 def test_it_works_with_garbage(self):
     assert url_for(None) is None
Пример #8
0
 def test_it_works_with_already_formed_path(self):
     assert url_for('/foobar') == '/foobar'