Skip to content

Commit

Permalink
fix(manager): correct behaviour for excluded systems filter
Browse files Browse the repository at this point in the history
  • Loading branch information
tkasparek authored and blayson committed Nov 26, 2020
1 parent ebcccea commit 66e643e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
13 changes: 3 additions & 10 deletions manager/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,12 @@ def _filter_system_by_opt_out(query, args):
object: Modified query with system opt out filter applied
"""
# pylint: disable=singleton-comparison
if args['opt_out'] is not None and args['excluded'] is not None:
return query.where(SystemPlatform.opt_out == True) # noqa: E712
if args['excluded'] is not None:
return query # do not interfere with the query if excluded is set

if 'opt_out' in args and args['opt_out']:
query = query.where(SystemPlatform.opt_out == args['opt_out'])
else:
elif 'opt_out' in args and args['opt_out'] == False: # noqa: E712
query = query.where(SystemPlatform.opt_out == False) # noqa: E712
return query

Expand All @@ -244,18 +242,13 @@ def _filter_system_by_excluded(query, args):
object: Modified query with system excluded filter applied
"""
# pylint: disable=singleton-comparison
if args['opt_out'] is not None and args['excluded'] is not None:
return query.where(SystemPlatform.opt_out == True) # noqa: E712
if args['opt_out'] is not None:
return query # do not interfere with the query if opt_out is set

expr = [True, False] if args['excluded'] is None else args['excluded']
if expr == [True, False]:
if args['excluded'] == [True, False]:
query = query.where(SystemPlatform.opt_out == False) # noqa: E712
elif expr == [False, True]:
elif args['excluded'] == [False, True]:
query = query.where(SystemPlatform.opt_out == True) # noqa: E712
elif expr == [False, False]:
query = query.where(SystemPlatform.opt_out.is_null(True))

return query

Expand Down
9 changes: 4 additions & 5 deletions tests/manager_tests/test_system_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
class TestSystemHandler(FlaskTestCase):

def test_systems(self):
response = self.vfetch("systems").check_response()
response2 = self.vfetch('systems/ids').check_response()
response = self.vfetch("systems?excluded=true,false").check_response()
response2 = self.vfetch('systems/ids?excluded=true,false').check_response()
assert len(response.body.data) == len(response2.body.data) == 7 == response.body.meta.total_items

def test_empty_uuid(self):
response = self.vfetch('systems?uuid=').check_response()
assert len(response.body.data) == 7
assert len(response.body.data) == 8

def test_systems_cves_not_exists(self):
self.vfetch("systems/b1f21450-0000-1111-2222-000000000000/cves").check_response(status_code=404)
Expand Down Expand Up @@ -115,8 +115,7 @@ def test_system_excluded_filter(self):

response1 = self.vfetch('systems?excluded=false,false').check_response()
response2 = self.vfetch('systems/ids?excluded=false,false').check_response()
assert not response1.body.data
assert not response2.body.data
assert len(response1.body.data) == len(response2.body.data) == 8

@pytest.mark.parametrize('value,expected', IMPACT_FILTER, ids=[x[0] for x in IMPACT_FILTER])
def test_impact_filter(self, value, expected):
Expand Down

0 comments on commit 66e643e

Please sign in to comment.