Beispiel #1
0
def test_query_entity_criteria():
    tags = 'benwa+nice'
    old_expected = old_tagname_filter(tags)

    post = Post(tags=[Tag(name='benwa'), Tag(name='nice')])
    c1 = EntityCriteria('any', post)
    q = Query(Or(c1))
    output = q.to_filter()

    assert output == old_expected
Beispiel #2
0
def test_entity_query_single_entity():
    tag = Tag(name='benwa')
    c1 = EntityCriteria('eq', tag)
    q = Query(c1)

    expected = q.to_filter()

    q2 = EntityQuery(tag)
    output = q2.to_filter()

    assert output == expected
Beispiel #3
0
def test_criteria_contains_criteria():
    example = [{
        "name": "computers",
        "op": "any",
        "val": {
            "name": "serial",
            "op": "ilike",
            "val": "%Amstrad%"
        }
    }]
    c1 = Criteria('ilike', 'serial', '%Amstrad%')
    c2 = Criteria('any', 'computers', c1)
    q = Query(c2)

    assert q.to_filter() == example
Beispiel #4
0
def test_or():
    c = Criteria('eq', 'username', 'Benwa Benwa Benwa')
    c2 = Criteria('eq', 'username', 'Another Benwa Benwa')
    q = Query(Or([c, c2]))

    assert q.to_filter() == [{
        'or': [{
            'name': 'username',
            'op': 'eq',
            'val': 'Benwa Benwa Benwa'
        }, {
            'name': 'username',
            'op': 'eq',
            'val': 'Another Benwa Benwa'
        }]
    }]
Beispiel #5
0
def test_and():
    example = [{
        "and": [{
            "name": "name",
            "op": "like",
            "val": "%Jim%"
        }, {
            "name": "birth_date",
            "op": "gt",
            "val": "1990-01-01"
        }]
    }]

    c1 = Criteria('like', 'name', '%Jim%')
    c2 = Criteria('gt', 'birth_date', "1990-01-01")
    and_ = And([c1, c2])
    q = Query(and_)

    assert q.to_filter() == example