Exemplo n.º 1
0
def test_uses_view_name_if_present():
    blueprint = FlumpBlueprint('test_flump', __name__)
    blueprint.register_flump_view(ViewNameView, '/endpoint')

    app = Flask(__name__)

    app.register_blueprint(blueprint)

    with app.test_request_context('/'):
        assert url_for('test_flump.totally_unique_name')
Exemplo n.º 2
0
def app(view_and_schema, app):
    UserFlumpView, _, _ = view_and_schema

    class PostOnlyView(UserFlumpView):
        HTTP_METHODS = HttpMethods.POST

    blueprint = FlumpBlueprint('post_only_blueprint', __name__)
    blueprint.register_flump_view(PostOnlyView, '/post_only/')
    app.register_blueprint(blueprint)
    return app
Exemplo n.º 3
0
def test_custom_url_mapping():
    blueprint = FlumpBlueprint('test_flump', __name__)
    blueprint.register_flump_view(ViewWithUrlMapping, '/endpoint')

    app = Flask(__name__)

    app.register_blueprint(blueprint)

    rules = [i.rule for i in app.url_map._rules_by_endpoint['test_flump.blah']]
    assert len(rules) == 2
    assert set(rules) == {'/endpoint'}
Exemplo n.º 4
0
def test_adds_trailing_slash_to_id_specific_route_if_left_off():
    blueprint = FlumpBlueprint('test_flump', __name__)
    blueprint.register_flump_view(ViewForTest, '/endpoint')

    assert blueprint.name == 'test_flump'

    app = Flask(__name__)

    app.register_blueprint(blueprint)

    rules = [i.rule for i in app.url_map._rules_by_endpoint['test_flump.blah']]
    assert len(rules) == 5
    assert set(rules) == {'/endpoint', '/endpoint/<entity_id>'}
Exemplo n.º 5
0
def test_flump_blueprint():
    blueprint = FlumpBlueprint('test_flump', __name__)
    blueprint.register_flump_view(ViewForTest, '/endpoint/')

    assert blueprint.name == 'test_flump'

    app = Flask(__name__)

    app.register_blueprint(blueprint)

    rules = [i.rule for i in app.url_map._rules_by_endpoint['test_flump.blah']]
    assert len(rules) == 5
    assert set(rules) == {'/endpoint', '/endpoint/<entity_id>'}
Exemplo n.º 6
0
def app(view_and_schema):
    view_class, schema, _ = view_and_schema
    blueprint = FlumpBlueprint('flump', __name__)
    blueprint.register_flump_view(view_class, '/user/')

    app = Flask(__name__)
    app.response_class = FlumpTestResponse
    app.config['SERVER_NAME'] = 'localhost'
    app.config['SERVER_PROTOCOL'] = 'http'
    app.config['DEBUG'] = True
    app.config['TESTING'] = True

    app.register_blueprint(blueprint, url_prefix='/tester')

    ctx = app.app_context()
    ctx.push()
    try:
        yield app
    finally:
        ctx.pop()
Exemplo n.º 7
0
def app(view_and_schema):
    view_class, schema, _ = view_and_schema
    blueprint = FlumpBlueprint('flump', __name__)
    blueprint.register_flump_view(view_class, '/user/')

    app = Flask(__name__)
    app.response_class = FlumpTestResponse
    app.config['SERVER_NAME'] = 'localhost'
    app.config['SERVER_PROTOCOL'] = 'http'
    app.config['DEBUG'] = True
    app.config['TESTING'] = True

    app.register_blueprint(blueprint, url_prefix='/tester')

    ctx = app.app_context()
    ctx.push()
    try:
        yield app
    finally:
        ctx.pop()
Exemplo n.º 8
0
def test_flump_view_decorator():
    blueprint = FlumpBlueprint('test_flump', __name__)

    @blueprint.flump_view('/endpoint/')
    class View(ViewForTest):
        pass

    app = Flask(__name__)
    app.register_blueprint(blueprint)

    # Assert that 5 routes have been defined.
    rules = [i.rule for i in app.url_map._rules_by_endpoint['test_flump.blah']]
    assert len(rules) == 5
    assert set(rules) == {'/endpoint', '/endpoint/<entity_id>'}
Exemplo n.º 9
0
from collections import namedtuple

from flask import Flask
from flump import (FlumpBlueprint, FlumpView, HttpMethods, OrmIntegration,
                   Fetcher)
from marshmallow import Schema, fields

# Our non-persistent "database"
INSTANCES = []

# The "model" we will be storing in our "database"
User = namedtuple('User', ('id', 'etag', 'name'))


# Instantiate our FlumpBlueprint ready for hooking up to our Flask app.
blueprint = FlumpBlueprint('flump-example', __name__)


class UserSchema(Schema):
    name = fields.Str(required=True)


# Our ORM Integration, as we are not supporting DELETE or UPDATE in this
# example we do not need to include `delete_entity` or `update_entity` methods.
class FakeOrm(OrmIntegration):
    def create_entity(self, data):
        entity = User(str(len(INSTANCES) + 1), uuid.uuid4(), data['name'])
        INSTANCES.append(entity)
        return entity

    def update_entity(self, entity, data):