def test_without_endpoint_absolute_scheme(self, app, mocker): app.add_url_rule('/<foo>', 'foobar', view_func=lambda x: x) field = fields.Url(absolute=True, scheme='https') obj = mocker.Mock(foo=42) with app.test_request_context('/foo', base_url='http://localhost'): assert 'https://localhost/42' == field.output('foo', obj)
def test_without_endpoint(self, app, mocker): app.add_url_rule('/<foo>', 'foobar', view_func=lambda x: x) field = fields.Url() obj = mocker.Mock(foo=42) with app.test_request_context('/foo'): assert '/42' == field.output('foo', obj)
def test_without_endpoint_invalid_object(self, app): app.add_url_rule('/<foo>', 'foobar', view_func=lambda x: x) field = fields.Url() with app.test_request_context('/foo'): with pytest.raises(fields.MarshallingError): field.output('foo', None)
def test_absolute(self, app, mocker): app.add_url_rule('/<foo>', 'foobar', view_func=lambda x: x) field = fields.Url('foobar', absolute=True) obj = mocker.Mock(foo=42) with app.test_request_context('/'): assert 'http://localhost/42' == field.output('foo', obj)
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) with app.test_request_context('/', base_url='http://localhost'): assert 'https://localhost/42' == field.output('foo', obj)
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)
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)
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)
def test_defaults(self): field = fields.Url('endpoint') assert not field.required assert field.__schema__ == {'type': 'string'}