def test_build_q_list():
    param = {'q': 'test'}
    expect = (['test'], True)
    assert build_q_list(param) == expect

    param = {
        'q':
        'title:(Holidays are Hell) authors:(Kim Harrison) OR authors:(Lynsay Sands)'
    }
    expect = ([
        'title:((Holidays are Hell))', 'author_name:((Kim Harrison))', 'OR',
        'author_name:((Lynsay Sands))'
    ], False)
    query_fields = [{
        'field': 'title',
        'value': '(Holidays are Hell)'
    }, {
        'field': 'author_name',
        'value': '(Kim Harrison)'
    }, {
        'op': 'OR'
    }, {
        'field': 'author_name',
        'value': '(Lynsay Sands)'
    }]
    assert list(parse_query_fields(param['q'])) == query_fields
    assert build_q_list(param) == expect
def test_build_q_list():
    param = {'q': 'test'}
    expect = (['test'], True)
    assert build_q_list(param) == expect

    param = {'q': 'title:(Holidays are Hell) authors:(Kim Harrison) OR authors:(Lynsay Sands)'}
    expect = (['title:((Holidays are Hell))', 'author_name:((Kim Harrison))', 'OR', 'author_name:((Lynsay Sands))'], False)
    query_fields = [
        {'field': 'title', 'value': '(Holidays are Hell)'},
        {'field': 'author_name', 'value': '(Kim Harrison)'},
        {'op': 'OR'},
        {'field': 'author_name', 'value': '(Lynsay Sands)'}
    ]
    assert list(parse_query_fields(param['q'])) == query_fields
    assert build_q_list(param) == expect
    def test_build_q_list(self):
        param = {'q': 'test'}
        expect = (['test'], True)
        self.assertEqual(build_q_list(param), expect)

        param = {'q': 'title:(Holidays are Hell) authors:(Kim Harrison) OR authors:(Lynsay Sands)'}
        expect = (['title:((Holidays are Hell))', 'author_name:((Kim Harrison))', 'OR', 'author_name:((Lynsay Sands))'], False)
        query_fields = [
            {'field': 'title', 'value': '(Holidays are Hell)'},
            {'field': 'author_name', 'value': '(Kim Harrison)'},
            {'op': 'OR'},
            {'field': 'author_name', 'value': '(Lynsay Sands)'}
        ]
        self.assertEqual(list(parse_query_fields(param['q'])), query_fields)
        self.assertEqual(build_q_list(param), expect)
def test_query_parser_fields(query, parsed_query):
    assert list(parse_query_fields(query)) == parsed_query