Exemple #1
0
    def test_with_blueprint(self, app, mocker):
        bp = Blueprint('foo', __name__, url_prefix='/foo')
        bp.add_url_rule('/<foo>', 'foobar', view_func=lambda x: x)
        app.register_blueprint(bp)
        field = fields.Url()
        obj = mocker.Mock(foo=42)

        with app.test_request_context('/foo/foo'):
            assert '/foo/42' == field.output('foo', obj)
Exemple #2
0
    def test_with_blueprint_absolute_scheme(self, app, mocker):
        bp = Blueprint('foo', __name__, url_prefix='/foo')
        bp.add_url_rule('/<foo>', 'foobar', view_func=lambda x: x)
        app.register_blueprint(bp)
        field = fields.Url(absolute=True, scheme='https')
        obj = mocker.Mock(foo=42)

        with app.test_request_context('/foo/foo', base_url='http://localhost'):
            assert 'https://localhost/foo/42' == field.output('foo', obj)
Exemple #3
0
    def test_with_blueprint_invalid_object(self, app):
        bp = Blueprint('foo', __name__, url_prefix='/foo')
        bp.add_url_rule('/<foo>', 'foobar', view_func=lambda x: x)
        app.register_blueprint(bp)
        field = fields.Url()

        with app.test_request_context('/foo/foo'):
            with pytest.raises(fields.MarshallingError):
                field.output('foo', None)