Esempio n. 1
0
def test_url_returns_valid_complex():
    # Should still return correct values when provided unnamed arguments
    _url = url('/', lambda x: x)

    assert _url.view_func(1) == 1
    assert _url.methods == ['GET']
    assert _url.name is None

    # Should return correct values when provided a full list of unnamed arguments.
    _url = url('/', lambda x: x, 'home', ['GET', 'POST'])

    assert _url.view_func(3) == 3
    assert _url.methods == ['GET', 'POST']
    assert _url.name == 'home'

    # Should return correct values when provided a full list of named arguments.
    _url = url(rule='/', view_func=lambda x: x, name='_home', methods=['GET', 'POST', 'PUT'])

    assert _url.view_func(5) == 5
    assert _url.methods == ['GET', 'POST', 'PUT']
    assert _url.name == '_home'

    # Should return correct values when provided a mixture of named and unnamed arguments.
    _url = url('/', lambda x: x, name=None, methods=['GET', 'PUT'])

    assert _url.view_func(7) == 7
    assert _url.methods == ['GET', 'PUT']
    assert _url.name is None
def test_router_fails_correctly(app, blueprint):
    urlpatterns = [
        url('/', view_func=lambda x: x, name='home'), 'not a pattern',
        url('/test', view_func=lambda x: x, name='test')
    ]

    with pytest.raises(exceptions.InvalidURLPattern):
        blueprint.register_urls(urlpatterns)
Esempio n. 3
0
def test_url_returns_invalid_simple():
    with pytest.raises(exceptions.InvalidURLRule):
        _url = url('', lambda x: x)

    with pytest.raises(exceptions.InvalidURLRule):
        _url = url(10, lambda x: x)

    with pytest.raises(exceptions.InvalidURLFunction):
        _url = url('/', 'hypothetical_function_name')

    with pytest.raises(exceptions.InvalidURLFunction):
        do = lambda x: x
        _url = url('/', do(10))
def test_router_registers_correctly(app, blueprint):
    urlpatterns = [
        url('/', view_func=lambda x: x, name='home'),
        url('/test', view_func=lambda x: x, name='test')
    ]

    blueprint.register_urls(urlpatterns)

    # Blueprint should queue two separate routes to be added
    assert len(blueprint.deferred_functions) == 2

    blueprint.deferred_functions[0](app)
    blueprint.deferred_functions[1](app)

    # Functions should register correctly within the app
    assert 'home' in app.view_functions
    assert 'test' in app.view_functions

    # Rules should be added to the app's url map
    assert list(app.url_map.iter_rules())[0].rule == '/test'
    assert list(app.url_map.iter_rules())[1].rule == '/'
Esempio n. 5
0
def test_url_returns_valid_simple():
    _url = url(rule='/', view_func=lambda x: x)

    # Should return a namedtuple
    assert isinstance(_url, tuple)
    assert hasattr(_url, '_fields')

    # Should default to GET as a method
    assert _url.methods == ['GET']

    # Should not provide a name if not given one.
    assert _url.name is None
Esempio n. 6
0
def test_url_returns_invalid_complex():
    with pytest.raises(exceptions.InvalidURLName):
        _url = url('/', lambda x: x, name=1)

    with pytest.raises(exceptions.InvalidURLName):
        _url = url('/', lambda x: x, name='')

    with pytest.raises(exceptions.UnspecifiedURLMethods):
        _url = url('/', lambda x: x, methods=[])

    with pytest.raises(exceptions.UnspecifiedURLMethods):
        _url = url('/', lambda x: x, methods=[''])

    with pytest.raises(exceptions.UnspecifiedURLMethods):
        _url = url('/', lambda x: x, methods='GET')

    with pytest.raises(exceptions.UnspecifiedURLMethods):
        _url = url('/', lambda x: x, methods=1)
Esempio n. 7
0
from flask_microservices import url
from . import views

urlpatterns = [
    url('/admin/', view_func=views.admin_panel, name='home'),

    ## Example URLs:

    ### Minimal:
    # url('/admin/simple/', view_func=views.admin_simple)

    ### Advanced
    # url('/admin/roles/add/', view_func=views.admin_panel_roles_add, name='role_add', methods=['GET', 'POST']),
    # url('/admin/roles/edit/', view_func=views.admin_panel_roles_edit, name='role_edit', methods=['GET', 'POST']),
]
Esempio n. 8
0
from flask_microservices import url
from . import views

urlpatterns = [url('/', view_func=views.home, name='home')]
Esempio n. 9
0
from flask_microservices import url
from . import views

urlpatterns = [
    url('/forum/', view_func=views.forum_home, name='home'),
    url('/forum/board/<board_id>', view_func=views.forum_board),

    # We'll add our own admin page to the admin module.
    url('/admin/forum/', view_func=views.forum_admin, name='admin')
]