Skip to content

Commit

Permalink
#250: Add test to mock TypeError when setting query limits
Browse files Browse the repository at this point in the history
- All possible through the use of mocking!
  • Loading branch information
MRichards99 committed Aug 13, 2021
1 parent 1130f4e commit e0cb2e0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/icat/filters/test_limit_filter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from unittest.mock import patch

import pytest

from datagateway_api.common.exceptions import FilterError
from datagateway_api.common.filter_order_handler import FilterOrderHandler
from datagateway_api.common.icat.filters import (
icat_set_limit,
PythonICATLimitFilter,
PythonICATSkipFilter,
)
Expand Down Expand Up @@ -54,3 +57,14 @@ def test_limit_and_skip_merge_correctly(self, icat_query, skip_value, limit_valu
filter_handler.apply_filters(icat_query)

assert icat_query.limit == (skip_value, limit_value)

def test_invalid_icat_set_limit(self, icat_query):
"""
The validity of this function is tested when applying a limit filter, an explict
invalid test case is required to cover when invalid arguments are given
"""
with patch(
"icat.query.Query.setLimit", side_effect=TypeError("Mocked Exception"),
):
with pytest.raises(FilterError):
icat_set_limit(icat_query, 50, 50)

0 comments on commit e0cb2e0

Please sign in to comment.