예제 #1
0
def test_operator():
    from arangodb import query

    q = query.Operator(query.Alias("foo"), query.Alias("bar"))

    qstr, params = q.query()

    assert qstr == "foo == bar"
    assert params == {}
예제 #2
0
def test_sort():
    from arangodb import query

    a = query.Alias("foo")
    q = query.Sort(a.foo, query.Desc(a.bar))

    qstr, params = q.query()

    assert qstr == "SORT foo.`foo`, foo.`bar` DESC"
    assert params == {}
예제 #3
0
def test_query_filter_and():
    from arangodb import query

    alias = query.Alias("foo")
    alias2 = query.Alias("bar")
    q = query.Query(
        alias,
        query.Collection("bar"),
        query.Return(alias.bar),
        query.Filter(alias == "1", alias2 <= 1)
    )

    qstr, params = q.query()

    assert qstr == 'FOR foo IN @@c_0 FILTER foo == @value_0 AND bar <= @value_1 RETURN foo.`bar`'
    assert params == {
        "@c_0": "bar",
        "value_0": "1",
        "value_1": 1
    }
예제 #4
0
def test_remove_query():
    from arangodb import query

    a = query.Alias("foo")
    c = query.Collection("bar")

    q = query.Query(a, c).action(query.Remove(a, c))

    qstr, params = q.query()

    assert qstr == "FOR foo IN @@c_0 REMOVE foo IN @@c_0"
예제 #5
0
def test_query():
    from arangodb import query

    alias = query.Alias("foo")
    q = query.Query(alias, query.Collection("bar"), query.Return(alias))

    qstr, params = q.query()

    assert qstr == "FOR foo IN @@c_0 RETURN foo"
    assert params == {
        "@c_0": "bar",
    }
예제 #6
0
def test_remove():
    from arangodb import query

    a = query.Alias("foo")
    q = query.Remove(a, query.Collection("bar"))

    qstr, params = q.query()

    assert qstr == "REMOVE foo IN @@c_0"
    assert params == {
        '@c_0': 'bar'
    }
예제 #7
0
def test_in():
    from arangodb import query

    a = query.Alias("foo")
    q = query.In(a, [1, 2, 3])

    qstr, params = q.query()

    assert qstr == "foo IN @value_0"
    assert params == {
        'value_0': [1, 2, 3]
    }
예제 #8
0
def test_sort_query():
    from arangodb import query

    a = query.Alias("foo")
    q = query.Query(a, query.Collection("bar")).action(a).sort(a.foo, query.Desc(a.bar)).limit(10)

    qstr, params = q.query()

    assert qstr == "FOR foo IN @@c_0 SORT foo.`foo`, foo.`bar` DESC LIMIT 10 RETURN foo"
    assert params == {
        "@c_0": "bar"
    }
예제 #9
0
def test_let():
    from arangodb import query

    a = query.Alias("foo")
    q = query.Let(a, "bar")

    qstr, params = q.query()

    assert qstr == "LET foo = @value_0"
    assert params == {
        "value_0": "bar"
    }
예제 #10
0
def test_function():
    from arangodb import query

    alias = query.Alias("foo")

    q = query.PATHS(alias, 1)

    qstr, params = q.query()

    assert qstr == "PATHS(foo, @value_0)"
    assert params == {
        "value_0": 1
    }
예제 #11
0
def test_for_expr():
    from arangodb import query

    q = query.For(query.Alias("foo"), query.Collection("bar"))

    assert list(q) == [
        query.FOR,
        query.SPACE,
        q.alias,
        query.SPACE,
        query.IN,
        query.SPACE,
        q.list_expr,
    ]
예제 #12
0
def test_fast_query():
    from arangodb import query

    alias = query.Alias("foo")
    alias2 = query.Alias("bar")
    q = query.Query(alias, query.Collection("bar"))\
        .filter(alias == "1", alias2 <= 1)\
        .filter(alias != 1, alias > 1, alias < 2, alias >= 2)\
        .action(alias.bar)

    qstr, params = q.query()

    assert qstr == 'FOR foo IN @@c_0 FILTER foo == @value_0 AND bar <= @value_1'\
        ' AND foo != @value_2 AND foo > @value_3 AND foo < @value_4 AND foo >= @value_5 RETURN foo.`bar`'
    assert params == {
        "@c_0": "bar",
        "value_0": "1",
        "value_1": 1,
        'value_2': 1,
        'value_3': 1,
        'value_4': 2,
        'value_5': 2
    }
예제 #13
0
def test_alias_relations_eq():
    from arangodb import query

    a = query.Alias("foo")

    x = a == 1
    assert isinstance(x, query.Operator)

    x = a > 1
    assert isinstance(x, query.Operator)

    x = a >= 1
    assert isinstance(x, query.Operator)

    x = a < 1
    assert isinstance(x, query.Operator)

    x = a <= 1
    assert isinstance(x, query.Operator)