Skip to content

Commit

Permalink
Add tests for where filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Reillyhewitson committed Nov 3, 2022
1 parent 6972dcc commit 3a5a4a3
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion test/datagateway_api/db/test_database_filter_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

from datagateway_api.src.common.exceptions import FilterError
from datagateway_api.src.common.helpers import get_entity_object_from_name
from datagateway_api.src.datagateway_api.database.filters import DatabaseFilterUtilities
from datagateway_api.src.datagateway_api.database.filters import (
DatabaseFilterUtilities,
DatabaseWhereFilter,
)
from datagateway_api.src.datagateway_api.database.helpers import ReadQuery
from datagateway_api.src.datagateway_api.database.backend import get_rows_by_filter


class TestDatabaseFilterUtilities:
Expand Down Expand Up @@ -128,3 +132,44 @@ def test_invalid_get_field(self, flask_test_app_db):
test_utility = DatabaseFilterUtilities()
with pytest.raises(FilterError):
test_utility._get_field(table, "unknown")

@pytest.mark.parametrize(
"operation, value",
[
pytest.param("eq", "Title for DataGateway API Testing (DB) 0", id="equal"),
pytest.param(
"ne", "Title for DataGateway API Testing (DB) 0", id="not equal (ne)"
),
pytest.param("like", "Title for DataGateway API Testing (DB) 0", id="like"),
pytest.param(
"nlike", "Title for DataGateway API Testing (DB) 0", id="not like"
),
pytest.param(
"lt", "Title for DataGateway API Testing (DB) 0", id="less than"
),
pytest.param(
"lte",
"Title for DataGateway API Testing (DB) 0",
id="less than or equal",
),
pytest.param(
"gt", "Title for DataGateway API Testing (DB) 0", id="greater than"
),
pytest.param(
"gte",
"Title for DataGateway API Testing (DB) 0",
id="greater than or equal",
),
],
)
def test_valid_where_operation(
self, flask_test_app_db, operation, value, single_investigation_test_data_db
):
test_utility = DatabaseWhereFilter("title", value, operation)
table = get_entity_object_from_name("Investigation")

test_query = ReadQuery(table)

test_utility.apply_filter(test_query)
print(test_query.base_query.first())
assert test_query.base_query.first() != None

0 comments on commit 3a5a4a3

Please sign in to comment.