Skip to content

Commit

Permalink
BUG: fix client-filter not returning filtered value
Browse files Browse the repository at this point in the history
this was not returning the item, but rather True or False if the item passed the filter causing errors later on
  • Loading branch information
anish-mudaraddi committed Oct 13, 2023
1 parent 386ef28 commit d7dd174
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/openstack_query/runners/runner_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def _apply_client_side_filter(
:param items: A list of openstack resources
:param client_filter: A client filter to apply
"""
return [client_filter(item) for item in items]
return [item for item in items if client_filter(item) is True]

@abstractmethod
def _run_query(
Expand Down
26 changes: 20 additions & 6 deletions tests/lib/openstack_query/runners/test_runner_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,29 +336,43 @@ def test_apply_client_side_filter_no_items(instance):
assert res == []


def test_apply_client_side_filter_one_item(instance):
def test_apply_client_side_filter_one_item_true(instance):
"""
Tests that apply_client_side_filter method functions expectedly
method should run given client_filter with one item
method when run on one item which should pass filter should return that item
"""
mock_client_filter = MagicMock()
mock_client_filter.return_value = True
mock_items = ["item1"]
res = instance._apply_client_side_filter(mock_items, mock_client_filter)
mock_client_filter.assert_called_once_with("item1")
assert res == [mock_client_filter.return_value]
assert res == mock_items


def test_apply_client_side_filter_one_item_false(instance):
"""
Tests that apply_client_side_filter method functions expectedly
method when run on one item which should fail filter should return empty list
"""
mock_client_filter = MagicMock()
mock_client_filter.return_value = False
mock_items = ["item1"]
res = instance._apply_client_side_filter(mock_items, mock_client_filter)
mock_client_filter.assert_called_once_with("item1")
assert res == []


def test_apply_client_side_filter_one_many_items(instance):
"""
Tests that apply_client_side_filter method functions expectedly
method should run given client_filter with many items
method should run given client_filter with many items - one pass, one fail
"""
mock_client_filter = MagicMock()
mock_client_filter.side_effect = ["out1", "out2"]
mock_client_filter.side_effect = [True, False]
mock_items = ["item1", "item2"]
res = instance._apply_client_side_filter(mock_items, mock_client_filter)
mock_client_filter.assert_has_calls([call("item1"), call("item2")])
assert res == ["out1", "out2"]
assert res == ["item1"]


def test_run_pagination_query_gt_0(run_paginated_query_test):
Expand Down

0 comments on commit d7dd174

Please sign in to comment.