def test_ancestor_is(): gql = gql_module.GQL( "SELECT * FROM SomeKind WHERE ANCESTOR IS 'AnyKind'") assert gql.filters() == { (-1, "is"): [("nop", [gql_module.Literal("AnyKind")])] }
def test_order_by_no_arg(): with pytest.raises(exceptions.BadQueryError): gql_module.GQL("SELECT * FROM SomeKind ORDER BY")
def test_constructor_bad_query(): with pytest.raises(exceptions.BadQueryError): gql_module.GQL("BAD, BAD QUERY")
def test_false(): gql = gql_module.GQL("SELECT * FROM SomeKind WHERE prop1=FALSE") assert gql.filters() == { ("prop1", "="): [("nop", [gql_module.Literal(False)])] }
def test_quoted_identifier(): gql = gql_module.GQL('SELECT * FROM SomeKind WHERE "prop1"=3.14') assert gql.filters() == { ("prop1", "="): [("nop", [gql_module.Literal(3.14)])] }
def test_is_no_ancestor(): with pytest.raises(exceptions.BadQueryError): gql_module.GQL("SELECT * FROM SomeKind WHERE prop1 IS 'OtherKind'")
def test_null(): gql = gql_module.GQL("SELECT * FROM SomeKind WHERE prop1=NULL") assert gql.filters() == { ("prop1", "="): [("nop", [gql_module.Literal(None)])] }
def test_orderings(): gql = gql_module.GQL(GQL_QUERY) assert gql.orderings() == [("prop4", 1), ("prop1", 2)]
def test_is_keys_only(): gql = gql_module.GQL(GQL_QUERY) assert gql.is_keys_only() is False gql = gql_module.GQL("SELECT __key__ from SomeKind") assert gql.is_keys_only() is True
def test_constructor_reserved_where_identifier(): with pytest.raises(exceptions.BadQueryError): gql_module.GQL("SELECT * FROM SomeKind WHERE WHERE")
def test_constructor_empty_where_condition_value(): with pytest.raises(exceptions.BadQueryError): gql_module.GQL("SELECT * FROM SomeKind WHERE prop1=")
def test_constructor_bad_where_condition(): with pytest.raises(exceptions.BadQueryError): gql_module.GQL("SELECT * FROM SomeKind WHERE WE_ARE")
def test_constructor_extra_query(): with pytest.raises(exceptions.BadQueryError): gql_module.GQL("SELECT * FROM SomeKind; END")
def test_constructor_incomplete_query(): with pytest.raises(exceptions.BadQueryError): gql_module.GQL("SELECT")
def test_ancestor_multiple_ancestors(): with pytest.raises(exceptions.BadQueryError): gql_module.GQL( ("SELECT * FROM SomeKind WHERE ANCESTOR IS 'AnyKind' AND " "ANCESTOR IS 'OtherKind'"))
def test_projection(): gql = gql_module.GQL(GQL_QUERY) assert gql.projection() == ("prop1", "prop2")
def test_ancestor_no_is(): with pytest.raises(exceptions.BadQueryError): gql_module.GQL("SELECT * FROM SomeKind WHERE ANCESTOR='OtherKind'")
def test_is_distinct(): gql = gql_module.GQL(GQL_QUERY) assert gql.is_distinct() is False gql = gql_module.GQL("SELECT DISTINCT prop1 from SomeKind") assert gql.is_distinct() is True
def test_func(): gql = gql_module.GQL("SELECT * FROM SomeKind WHERE prop1=key(:1)") assert gql.filters() == {("prop1", "="): [("key", [1])]}
def test_kind(): gql = gql_module.GQL(GQL_QUERY) assert gql.kind() == "SomeKind" assert gql._entity == "SomeKind"
def test_true(): gql = gql_module.GQL("SELECT * FROM SomeKind WHERE prop1=TRUE") assert gql.filters() == { ("prop1", "="): [("nop", [gql_module.Literal(True)])] }
def test_cast(): gql = gql_module.GQL("SELECT * FROM SomeKind WHERE prop1=user('js')") assert gql.filters() == { ("prop1", "="): [("user", [gql_module.Literal("js")])] }
def test_float(): gql = gql_module.GQL("SELECT * FROM SomeKind WHERE prop1=3.14") assert gql.filters() == { ("prop1", "="): [("nop", [gql_module.Literal(3.14)])] }
def test_cast_list_no_in(): with pytest.raises(exceptions.BadQueryError): gql_module.GQL("SELECT * FROM SomeKind WHERE prop1=(1, 2, 3)")
def test_order_by_ascending(): gql = gql_module.GQL("SELECT * FROM SomeKind ORDER BY prop1 ASC") assert gql.orderings() == [("prop1", 1)]
def test_reference(): gql = gql_module.GQL("SELECT * FROM SomeKind WHERE prop1=:ref") assert gql.filters() == {("prop1", "="): [("nop", ["ref"])]}
def test_constructor(): gql = gql_module.GQL(GQL_QUERY) assert gql.kind() == "SomeKind"
def test_in_list(): Literal = gql_module.Literal gql = gql_module.GQL("SELECT * FROM SomeKind WHERE prop1 IN (1, 2, 3)") assert gql.filters() == { ("prop1", "IN"): [("list", [Literal(1), Literal(2), Literal(3)])] }