Skip to content

Commit

Permalink
test: test between operator #297
Browse files Browse the repository at this point in the history
  • Loading branch information
VKTB committed Jan 19, 2022
1 parent d254642 commit f5525c9
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions test/datagateway_api/icat/filters/test_where_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class TestICATWhereFilter:
pytest.param("gte", 5, ["%s >= '5'"], id="greater than or equal"),
pytest.param("in", [1, 2, 3, 4], ["%s in (1, 2, 3, 4)"], id="in a list"),
pytest.param("in", [], ["%s in (NULL)"], id="empty list"),
pytest.param("between", [1, 2], ["%s between '1' and '2'"], id="between"),
],
)
def test_valid_operations(
Expand All @@ -33,9 +34,23 @@ def test_valid_operations(

assert icat_query.conditions == {"id": expected_condition_value}

def test_invalid_in_operation(self, icat_query):
@pytest.mark.parametrize(
"operation, value",
[
pytest.param("in", "1, 2, 3, 4, 5", id="in a list (in)"),
pytest.param("between", "1, 2, 3, 4, 5", id="between - string value"),
pytest.param("between", [], id="between - empty list"),
pytest.param(
"between", [1], id="between - list with less than two elements",
),
pytest.param(
"between", [1, 2, 3], id="between - list with more than two elements",
),
],
)
def test_invalid_operations_raise_bad_request_error(self, operation, value):
with pytest.raises(BadRequestError):
PythonICATWhereFilter("id", "1, 2, 3, 4, 5", "in")
PythonICATWhereFilter("id", value, operation)

def test_invalid_operation(self, icat_query):
test_filter = PythonICATWhereFilter("id", 10, "non")
Expand Down

0 comments on commit f5525c9

Please sign in to comment.