Exemplo n.º 1
0
def test_read_from_req(mocker):
    def validate1(req):
        assert len(req.docs) == 5

    def validate2(req):
        assert len(req.docs) == 3

    response_mock = mocker.Mock(wrap=validate1)
    response_mock_2 = mocker.Mock(wrap=validate2)
    response_mock_3 = mocker.Mock(wrap=validate1)

    qs = QueryLang(SliceQL(start=1, end=4, priority=1))

    f = Flow(callback_on='body').add(uses='- !SliceQL | {start: 0, end: 5}')

    # without queryset
    with f:
        f.index(random_docs(10), on_done=response_mock)

    response_mock.assert_called()
    # with queryset
    with f:
        f.index(random_docs(10), queryset=qs, on_done=response_mock_2)

    response_mock_2.assert_called()

    qs.priority = -1
    # with queryset, but priority is no larger than driver's default
    with f:
        f.index(random_docs(10), queryset=qs, on_done=response_mock_3)

    response_mock_3.assert_called()
Exemplo n.º 2
0
def test_read_from_req(mocker):
    def validate1(req):
        assert len(req.docs) == 5

    def validate2(req):
        assert len(req.docs) == 3

    response_mock = mocker.Mock()
    response_mock_2 = mocker.Mock()
    response_mock_3 = mocker.Mock()

    qs = QueryLang(
        {'name': 'SliceQL', 'priority': 1, 'parameters': {'start': 1, 'end': 4}}
    )

    f = Flow().add(uses='- !SliceQL | {start: 0, end: 5}')

    # without queryset
    with f:
        f.index(random_docs(10), on_done=response_mock)

    validate_callback(response_mock, validate1)
    # with queryset
    with f:
        f.index(random_docs(10), queryset=qs, on_done=response_mock_2)

    validate_callback(response_mock_2, validate2)

    qs.priority = -1
    # with queryset, but priority is no larger than driver's default
    with f:
        f.index(random_docs(10), queryset=qs, on_done=response_mock_3)

    validate_callback(response_mock_3, validate1)
Exemplo n.º 3
0
def test_ql_priority():
    qs = QueryLang(SliceQL(start=1, end=4, priority=1))
    assert qs.priority == 1
    qs._querylang.priority = -1
    assert qs._querylang.priority == -1
    assert qs.priority == -1

    qs.priority = -2
    assert qs._querylang.priority == -2
    assert qs.priority == -2
Exemplo n.º 4
0
def test_ql_priority():
    qs = QueryLang({
        'name': 'SliceQL',
        'parameters': {
            'start': 1,
            'end': 4
        },
        'priority': 1
    })
    assert qs.priority == 1
    qs._querylang.priority = -1
    assert qs._querylang.priority == -1
    assert qs.priority == -1

    qs.priority = -2
    assert qs._querylang.priority == -2
    assert qs.priority == -2

    qs2 = QueryLang({'name': 'SliceQL', 'parameters': {'start': 1, 'end': 4}})
    assert qs2.priority == 0
Exemplo n.º 5
0
def test_read_from_req():
    def validate1(req):
        assert len(req.docs) == 5

    def validate2(req):
        assert len(req.docs) == 3

    qs = QueryLang(SliceQL(start=1, end=4, priority=1))

    f = Flow(callback_on='body').add(uses='- !SliceQL | {start: 0, end: 5}')

    # without queryset
    with f:
        f.index(random_docs(10), output_fn=validate1)

    # with queryset
    with f:
        f.index(random_docs(10), queryset=qs, output_fn=validate2)

    qs.priority = -1
    # with queryset, but priority is no larger than driver's default
    with f:
        f.index(random_docs(10), queryset=qs, output_fn=validate1)
Exemplo n.º 6
0
def querylang_instance():
    """:returns: An instance of :class:`QueryLang`."""
    query_lang = QueryLang()
    query_lang.name = 'test'
    query_lang.priority = 5
    return query_lang