diff --git a/requirements/dev.txt b/requirements/dev.txt index 333dbe4..955da77 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,2 +1,2 @@ -lib-rql>=1.1.4,<2 +lib-rql>=1.1.5,<2 Django>=2.2.19 diff --git a/requirements/test.txt b/requirements/test.txt index a83d225..6f47033 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -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 \ No newline at end of file +flake8-string-format==0.3.0 +importlib-metadata>=4.0.0,<5.0.0 \ No newline at end of file diff --git a/tests/test_filter_cls/test_apply_filters.py b/tests/test_filter_cls/test_apply_filters.py index 2c91c59..e4afaf6 100644 --- a/tests/test_filter_cls/test_apply_filters.py +++ b/tests/test_filter_cls/test_apply_filters.py @@ -65,40 +65,57 @@ def test_searching(searching_tpl): @pytest.mark.django_db @pytest.mark.parametrize('operator', ['&', ',']) def test_and(operator): - email, title = 'george@martin.com', '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 = 'george@martin.com', '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@example.com'), 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 = 'george@martin.com', '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 = 'george@martin.com', '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@example.com'), 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