rc for skip of literal binds
This commit is contained in:
@ -142,16 +142,16 @@ def test_combining_groups_together():
|
||||
group = (Product.name == "Test") & (Product.rating >= 3.0)
|
||||
group.resolve(model_cls=Product)
|
||||
assert len(group._nested_groups) == 2
|
||||
assert str(group.get_text_clause()) == (
|
||||
"( ( product.name = 'Test' ) AND" " ( product.rating >= 3.0 ) )"
|
||||
)
|
||||
assert str(
|
||||
group.get_text_clause().compile(compile_kwargs={"literal_binds": True})
|
||||
) == ("((product.name = 'Test') AND (product.rating >= 3.0))")
|
||||
|
||||
group = ~((Product.name == "Test") & (Product.rating >= 3.0))
|
||||
group.resolve(model_cls=Product)
|
||||
assert len(group._nested_groups) == 2
|
||||
assert str(group.get_text_clause()) == (
|
||||
" NOT ( ( product.name = 'Test' ) AND" " ( product.rating >= 3.0 ) )"
|
||||
)
|
||||
assert str(
|
||||
group.get_text_clause().compile(compile_kwargs={"literal_binds": True})
|
||||
) == ("NOT ((product.name = 'Test') AND" " (product.rating >= 3.0))")
|
||||
|
||||
group = ((Product.name == "Test") & (Product.rating >= 3.0)) | (
|
||||
Product.category.name << (["Toys", "Books"])
|
||||
@ -159,11 +159,13 @@ def test_combining_groups_together():
|
||||
group.resolve(model_cls=Product)
|
||||
assert len(group._nested_groups) == 2
|
||||
assert len(group._nested_groups[0]._nested_groups) == 2
|
||||
group_str = str(group.get_text_clause())
|
||||
group_str = str(
|
||||
group.get_text_clause().compile(compile_kwargs={"literal_binds": True})
|
||||
)
|
||||
category_prefix = group._nested_groups[1].actions[0].table_prefix
|
||||
assert group_str == (
|
||||
"( ( ( product.name = 'Test' ) AND ( product.rating >= 3.0 ) ) "
|
||||
f"OR ( {category_prefix}_categories.name IN ('Toys', 'Books') ) )"
|
||||
"(((product.name = 'Test') AND (product.rating >= 3.0)) "
|
||||
f"OR ({category_prefix}_categories.name IN ('Toys', 'Books')))"
|
||||
)
|
||||
|
||||
group = (Product.name % "Test") | (
|
||||
@ -173,15 +175,17 @@ def test_combining_groups_together():
|
||||
group.resolve(model_cls=Product)
|
||||
assert len(group._nested_groups) == 2
|
||||
assert len(group._nested_groups[1]._nested_groups) == 2
|
||||
group_str = str(group.get_text_clause())
|
||||
group_str = str(
|
||||
group.get_text_clause().compile(compile_kwargs={"literal_binds": True})
|
||||
)
|
||||
price_list_prefix = (
|
||||
group._nested_groups[1]._nested_groups[0].actions[0].table_prefix
|
||||
)
|
||||
category_prefix = group._nested_groups[1]._nested_groups[1].actions[0].table_prefix
|
||||
assert group_str == (
|
||||
f"( ( product.name LIKE '%Test%' ) "
|
||||
f"OR ( ( {price_list_prefix}_price_lists.name LIKE 'Aa%' ) "
|
||||
f"OR ( {category_prefix}_categories.name IN ('Toys', 'Books') ) ) )"
|
||||
f"((product.name LIKE '%Test%') "
|
||||
f"OR (({price_list_prefix}_price_lists.name LIKE 'Aa%') "
|
||||
f"OR ({category_prefix}_categories.name IN ('Toys', 'Books'))))"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -40,9 +40,10 @@ def test_or_group():
|
||||
assert result.actions[0].target_model == Author
|
||||
assert result.actions[1].target_model == Book
|
||||
assert (
|
||||
str(result.get_text_clause()) == f"( authors.name = 'aa' OR "
|
||||
str(result.get_text_clause().compile(compile_kwargs={"literal_binds": True}))
|
||||
== f"(authors.name = 'aa' OR "
|
||||
f"{result.actions[1].table_prefix}"
|
||||
f"_books.title = 'bb' )"
|
||||
f"_books.title = 'bb')"
|
||||
)
|
||||
|
||||
|
||||
@ -53,9 +54,10 @@ def test_and_group():
|
||||
assert result.actions[0].target_model == Author
|
||||
assert result.actions[1].target_model == Book
|
||||
assert (
|
||||
str(result.get_text_clause()) == f"( authors.name = 'aa' AND "
|
||||
str(result.get_text_clause().compile(compile_kwargs={"literal_binds": True}))
|
||||
== f"(authors.name = 'aa' AND "
|
||||
f"{result.actions[1].table_prefix}"
|
||||
f"_books.title = 'bb' )"
|
||||
f"_books.title = 'bb')"
|
||||
)
|
||||
|
||||
|
||||
@ -68,12 +70,13 @@ def test_nested_and():
|
||||
assert len(result._nested_groups) == 2
|
||||
book_prefix = result._nested_groups[0].actions[1].table_prefix
|
||||
assert (
|
||||
str(result.get_text_clause()) == f"( ( authors.name = 'aa' OR "
|
||||
str(result.get_text_clause().compile(compile_kwargs={"literal_binds": True}))
|
||||
== f"((authors.name = 'aa' OR "
|
||||
f"{book_prefix}"
|
||||
f"_books.title = 'bb' ) AND "
|
||||
f"( authors.name = 'cc' OR "
|
||||
f"_books.title = 'bb') AND "
|
||||
f"(authors.name = 'cc' OR "
|
||||
f"{book_prefix}"
|
||||
f"_books.title = 'dd' ) )"
|
||||
f"_books.title = 'dd'))"
|
||||
)
|
||||
|
||||
|
||||
@ -84,11 +87,12 @@ def test_nested_group_and_action():
|
||||
assert len(result._nested_groups) == 1
|
||||
book_prefix = result._nested_groups[0].actions[1].table_prefix
|
||||
assert (
|
||||
str(result.get_text_clause()) == f"( ( authors.name = 'aa' OR "
|
||||
str(result.get_text_clause().compile(compile_kwargs={"literal_binds": True}))
|
||||
== f"((authors.name = 'aa' OR "
|
||||
f"{book_prefix}"
|
||||
f"_books.title = 'bb' ) AND "
|
||||
f"_books.title = 'bb') AND "
|
||||
f"{book_prefix}"
|
||||
f"_books.title = 'dd' )"
|
||||
f"_books.title = 'dd')"
|
||||
)
|
||||
|
||||
|
||||
@ -108,12 +112,14 @@ def test_deeply_nested_or():
|
||||
assert len(result._nested_groups) == 2
|
||||
assert len(result._nested_groups[0]._nested_groups) == 2
|
||||
book_prefix = result._nested_groups[0]._nested_groups[0].actions[1].table_prefix
|
||||
result_qry = str(result.get_text_clause())
|
||||
result_qry = str(
|
||||
result.get_text_clause().compile(compile_kwargs={"literal_binds": True})
|
||||
)
|
||||
expected_qry = (
|
||||
f"( ( ( authors.name = 'aa' OR {book_prefix}_books.title = 'bb' ) AND "
|
||||
f"( authors.name = 'cc' OR {book_prefix}_books.title = 'dd' ) ) "
|
||||
f"OR ( ( {book_prefix}_books.year < 1900 OR {book_prefix}_books.title = '11' ) AND "
|
||||
f"( {book_prefix}_books.year > 'xx' OR {book_prefix}_books.title = '22' ) ) )"
|
||||
f"(((authors.name = 'aa' OR {book_prefix}_books.title = 'bb') AND "
|
||||
f"(authors.name = 'cc' OR {book_prefix}_books.title = 'dd')) "
|
||||
f"OR (({book_prefix}_books.year < 1900 OR {book_prefix}_books.title = '11') AND"
|
||||
f" ({book_prefix}_books.year > 'xx' OR {book_prefix}_books.title = '22')))"
|
||||
)
|
||||
assert result_qry.replace("\n", "") == expected_qry.replace("\n", "")
|
||||
|
||||
|
||||
@ -56,6 +56,10 @@ def create_test_database():
|
||||
metadata.drop_all(engine)
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
database._backend._dialect.name == "sqlite",
|
||||
reason="wait for fix for sqlite in encode/databases",
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_double_nested_reverse_relation():
|
||||
async with database:
|
||||
|
||||
Reference in New Issue
Block a user