Exemplo n.º 1
0
def test_endpoint_dispatch_errors():
    class MyQuery(Query):
        foo = Filter.choice(
            field__include=True,
            field__attr='name',
            choices=('a', 'b'),
        )

    q = MyQuery().bind(request=req('get'))

    assert perform_ajax_dispatch(
        root=MyQuery().bind(request=req('get', **{q.get_advanced_query_param(): '!!'})),
        path='/errors',
        value='',
    ) == {'global': ['Invalid syntax for query']}
    assert perform_ajax_dispatch(
        root=MyQuery().bind(request=req('get', **{q.get_advanced_query_param(): 'foo=a'})),
        path='/errors',
        value='',
    ) == {}
    assert perform_ajax_dispatch(
        root=MyQuery().bind(request=req('get', foo='q')),
        path='/errors',
        value='',
    ) == {'fields': {'foo': ['q not in available choices']}}
Exemplo n.º 2
0
def test_endpoint_dispatch():
    EndPointDispatchModel.objects.create(name='foo')
    x = EndPointDispatchModel.objects.create(name='bar')

    class MyQuery(Query):
        foo = Filter.choice_queryset(
            field__include=True,
            field__attr='name',
            choices=EndPointDispatchModel.objects.all().order_by('id'),
        )

    request = req('get')
    query = MyQuery().bind(request=request)

    assert query.form.fields.foo.endpoints.choices.endpoint_path == '/choices'
    expected = {
        'results': [
            {
                'id': x.pk,
                'text': str(x)
            },
        ],
        'pagination': {
            'more': False
        },
        'page': 1,
    }
    assert perform_ajax_dispatch(root=query,
                                 path='/form/fields/foo/endpoints/choices',
                                 value='ar') == expected
    assert perform_ajax_dispatch(root=query, path='/choices',
                                 value='ar') == expected