Skip to content

Commit

Permalink
Merge pull request #54 from cloudblue/fix/LITE-25309_fix-or-chain
Browse files Browse the repository at this point in the history
LITE-25309 update lib-rql version to fix ambiguous parsing of comma-s…
  • Loading branch information
zzzevaka authored Oct 13, 2022
2 parents 8c61901 + 8e75cd1 commit 89320a6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
lib-rql>=1.1.4,<2
lib-rql>=1.1.5,<2
Django>=2.2.19
3 changes: 2 additions & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ flake8-comprehensions==3.7.0
flake8-debugger==4.0.0
flake8-eradicate==1.1.0
flake8-import-order==0.18.1
flake8-string-format==0.3.0
flake8-string-format==0.3.0
importlib-metadata>=4.0.0,<5.0.0
43 changes: 30 additions & 13 deletions tests/test_filter_cls/test_apply_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,40 +65,57 @@ def test_searching(searching_tpl):
@pytest.mark.django_db
@pytest.mark.parametrize('operator', ['&', ','])
def test_and(operator):
email, title = '[email protected]', 'book'
comp1 = 'title={0}'.format(title)
comp2 = 'eq(author.email,{0})'.format(email)
query = '{comp1}{op}{comp2}'.format(comp1=comp1, op=operator, comp2=comp2)
email, title, stars = '[email protected]', 'book', 10
comps = [
'title={0}'.format(title),
'eq(author.email,{0})'.format(email),
'gt(github_stars,{0})'.format(stars),
]
query = operator.join(comps)
query_func_style = 'and({0})'.format(','.join(comps))

authors = [
Author.objects.create(email='[email protected]'),
Author.objects.create(email=email),
]
books = [Book.objects.create(author=authors[index], title=title) for index in range(2)]
books = [
Book.objects.create(author=authors[0], title=title, github_stars=11),
Book.objects.create(author=authors[1], title='title', github_stars=11),
Book.objects.create(author=authors[1], title=title, github_stars=11),
]

expected = [books[1]]
expected = [books[2]]
assert apply_filters(query) == expected
assert apply_filters('{q}{op}{q}'.format(q=query, op=operator)) == expected
assert apply_filters('and({comp1},{comp2})'.format(comp1=comp1, comp2=comp2)) == expected
assert apply_filters(query_func_style) == expected


@pytest.mark.django_db
@pytest.mark.parametrize('operator', ['|', ';'])
def test_or(operator):
email, title = '[email protected]', 'book'
comp1 = 'title={0}'.format(title)
comp2 = 'eq(author.email,{0})'.format(email)
query = '({comp1}{op}{comp2})'.format(comp1=comp1, op=operator, comp2=comp2)
email, title, stars = '[email protected]', 'book', '10'
comps = [
'title={0}'.format(title),
'eq(author.email,{0})'.format(email),
'gt(github_stars,{0})'.format(stars),
]
query = '({0})'.format(operator.join(comps))
query_func_style = 'or({0})'.format(','.join(comps))

authors = [
Author.objects.create(email='[email protected]'),
Author.objects.create(email=email),
]
books = [Book.objects.create(author=authors[index], title=title) for index in range(2)]
books = [
Book.objects.create(author=authors[0], title=title, github_stars=2),
Book.objects.create(author=authors[1], title='1', github_stars=5),
Book.objects.create(author=authors[0], title='2', github_stars=11),
]

expected = books

assert apply_filters(query) == expected
assert apply_filters('or({comp1},{comp2})'.format(comp1=comp1, comp2=comp2)) == expected
assert apply_filters(query_func_style) == expected


@pytest.mark.django_db
Expand Down

0 comments on commit 89320a6

Please sign in to comment.