Ejemplo n.º 1
0
    async def test_without_endpoint_absolute(self, app, mocker):
        app.add_url_rule('/<foo>', 'foobar', view_func=lambda x: x)
        field = fields.Url(absolute=True)
        obj = mocker.Mock(foo=42)

        async with app.test_request_context('/foo'):
            assert 'http://localhost/42' == field.output('foo', obj)
Ejemplo n.º 2
0
    async def test_without_endpoint_invalid_object(self, app):
        app.add_url_rule('/<foo>', 'foobar', view_func=lambda x: x)
        field = fields.Url()

        async with app.test_request_context():
            with pytest.raises(fields.MarshallingError):
                field.output('foo', None)
Ejemplo n.º 3
0
    async def test_simple(self, app, mocker):
        app.add_url_rule('/<foo>', 'foobar', view_func=lambda x: x)
        field = fields.Url('foobar')
        obj = mocker.Mock(foo=42)

        async with app.test_request_context():
            assert '/42' == field.output('foo', obj)
Ejemplo n.º 4
0
    async def test_absolute_scheme(self, app, mocker):
        """Url.scheme should override current_request.scheme"""
        app.add_url_rule('/<foo>', 'foobar', view_func=lambda x: x)
        field = fields.Url('foobar', absolute=True, scheme='https')
        obj = mocker.Mock(foo=42)

        async with app.test_request_context():
            assert 'https://localhost/42' == field.output('foo', obj)
Ejemplo n.º 5
0
    async def test_with_blueprint_absolute(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)
        obj = mocker.Mock(foo=42)

        async with app.test_request_context('/foo/foo'):
            assert 'http://localhost/foo/42' == field.output('foo', obj)
Ejemplo n.º 6
0
    async 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()

        async with app.test_request_context('/foo/foo'):
            with pytest.raises(fields.MarshallingError):
                field.output('foo', None)
Ejemplo n.º 7
0
    def test_invalid_object(self, app):
        app.add_url_rule('/<foo>', 'foobar', view_func=lambda x: x)
        field = fields.Url('foobar')

        with pytest.raises(fields.MarshallingError):
            field.output('foo', None)
Ejemplo n.º 8
0
 def test_defaults(self):
     field = fields.Url('endpoint')
     assert not field.required
     assert field.__schema__ == {'type': 'string'}