Skip to content

Commit

Permalink
LITE-30338: Adding new search patterns that are now supported by lib-…
Browse files Browse the repository at this point in the history
…rql.
  • Loading branch information
akodelia committed Jun 25, 2024
1 parent bc08053 commit f3d9820
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 34 additions & 1 deletion tests/test_filter_cls/test_apply_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ def test_not():
]
assert apply_filters('not(title={0})'.format(title)) == [books[1]]

#


def apply_listing_filters(operator, *values):
return apply_filters(
'{operator}(id,({values}))'.format(
operator=operator,
values=','.join(tuple(values)),
),
)



@pytest.mark.django_db
def test_nested_logic():
Expand Down Expand Up @@ -624,7 +636,6 @@ def test_braces_in_braces():
Book.objects.create(title='another'),
]
assert apply_filters('(((title=book)))&(title=book)') == [books[0]]
assert apply_filters('(title=book|(title=invalid))') == [books[0]]


@pytest.mark.django_db
Expand Down Expand Up @@ -689,3 +700,25 @@ def test_distinct_on_field_field_in_ordering():
def test_distinct_on_field_field_not_in_ordering():
_, qs = BooksFilterClass(book_qs).apply_filters('ordering(int_choice_field)')
assert not qs.query.distinct


@pytest.mark.django_db
@pytest.mark.parametrize(
'query',
(
'(not(ilike(title,*ermat*)))',
'(not(ilike(title,*ermat*))&not(ilike(author__name,*Foo*)))',
'(and(not(ilike(title,*ermat*)),not(ilike(author__name,*Foo*))))',
)
)
def test_complex_nested_queries(query):
publisher = [Publisher.objects.create() for _ in range(2)]

author = Author.objects.create(name='Foo', publisher=publisher[0], is_male=False)
Book.objects.create(amazon_rating=4.0, author=author, title='Fermats last theorem')

other_author = Author.objects.create(name='Bar', publisher=publisher[0], is_male=False)
other_book = Book.objects.create(amazon_rating=4.5, author=other_author, title="Madame Bovary")
other_book2 = Book.objects.create(amazon_rating=4.5, author=other_author, title="Madame Bovary")

assert apply_filters(query) == [other_book, other_book2]

0 comments on commit f3d9820

Please sign in to comment.