-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#150: Rewrite get_filter_from_query_string tests
- Loading branch information
1 parent
74215cd
commit d6f6ab8
Showing
2 changed files
with
55 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import pytest | ||
|
||
from datagateway_api.common.database.filters import ( | ||
DatabaseDistinctFieldFilter, | ||
DatabaseIncludeFilter, | ||
DatabaseLimitFilter, | ||
DatabaseOrderFilter, | ||
DatabaseSkipFilter, | ||
) | ||
from datagateway_api.common.exceptions import FilterError | ||
from datagateway_api.common.helpers import get_filters_from_query_string | ||
|
||
|
||
class TestGetFiltersFromQueryString: | ||
def test_valid_no_filters(self, flask_test_app_db): | ||
with flask_test_app_db: | ||
flask_test_app_db.get("/") | ||
|
||
assert [] == get_filters_from_query_string() | ||
|
||
def test_invalid_filter(self, flask_test_app_db): | ||
with flask_test_app_db: | ||
flask_test_app_db.get('/?test="test"') | ||
|
||
with pytest.raises(FilterError): | ||
get_filters_from_query_string() | ||
|
||
@pytest.mark.parametrize( | ||
"filter_input, filter_type", | ||
[ | ||
pytest.param( | ||
'distinct="ID"', DatabaseDistinctFieldFilter, id="DB distinct filter", | ||
), | ||
pytest.param( | ||
'include="TEST"', DatabaseIncludeFilter, id="DB include filter", | ||
), | ||
pytest.param("limit=10", DatabaseLimitFilter, id="DB limit filter"), | ||
pytest.param('order="ID DESC"', DatabaseOrderFilter, id="DB order filter"), | ||
pytest.param("skip=10", DatabaseSkipFilter, id="DB skip filter"), | ||
], | ||
) | ||
def test_valid_filter(self, flask_test_app_db, filter_input, filter_type): | ||
with flask_test_app_db: | ||
flask_test_app_db.get(f"/?{filter_input}") | ||
filters = get_filters_from_query_string() | ||
|
||
assert isinstance(filters[0], filter_type) | ||
|
||
def test_valid_multiple_filters(self, flask_test_app_db): | ||
with flask_test_app_db: | ||
flask_test_app_db.get("/?limit=10&skip=4") | ||
filters = get_filters_from_query_string() | ||
|
||
assert len(filters) == 2 |