Skip to content

Commit

Permalink
Added tests to cover invalid lookup cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bartonip committed Jun 28, 2020
1 parent f27eae4 commit ff2288a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pyodata/v2/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,7 @@ class GetEntitySetFilterChainable:
"range",
"in",
"length",
"eq"
]

def __init__(self, request, filter_expressions, exprs):
Expand Down Expand Up @@ -1221,7 +1222,8 @@ def decode_expression(self, expr, val):
# field_heirarchy.append(part)
elif part in self.__class__.operators:
operator = part

else:
raise ValueError("'{}' is not a valid property or operator".format(part))
# field = "/".join(field_heirarchy)

# target_field = self.proprty_obj(field_heirarchy[-1])
Expand Down
25 changes: 23 additions & 2 deletions tests/test_service_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1959,7 +1959,7 @@ def test_count_with_chainable_filter_or(service):
assert request.execute() == 3

@responses.activate
def test_count_with_multiple_filters_startswith(service):
def test_count_with_multiple_chainable_filters_startswith(service):
"""Check getting $count with $filter calling startswith"""
from pyodata.v2.service import FilterExpression as Q
# pylint: disable=redefined-outer-name
Expand All @@ -1978,9 +1978,30 @@ def test_count_with_multiple_filters_startswith(service):
assert request.execute() == 3


@responses.activate
def test_count_with_chainable_filters_invalid_property_lookup(service):
"""Check getting $count with $filter calling startswith"""
# pylint: disable=redefined-outer-name

employees = service.entity_sets.Employees.get_entities()
with pytest.raises(ValueError) as ex:
request = employees.filter(Foo="Bar")

assert str(ex.value) == "'Foo' is not a valid property or operator"


@responses.activate
def test_count_with_chainable_filters_invalid_operator_lookup(service):
"""Check getting $count with $filter calling startswith"""
# pylint: disable=redefined-outer-name

employees = service.entity_sets.Employees.get_entities()
with pytest.raises(ValueError) as ex:
request = employees.filter(NickName__foo="Bar")

assert str(ex.value) == "'foo' is not a valid property or operator"



@responses.activate
def test_count_with_chained_filters(service):
"""Check getting $count with chained filters"""
Expand Down

0 comments on commit ff2288a

Please sign in to comment.