def test_none_does_not_match(): # arrange text_filter = Filter('mimetype', FilterComparison.EQ, 'text/plain') # act match = text_filter.filter(None) # assert assert not match
def test_gt_matches_larger(): # arrange metadata = {'filesize': '20'} size_filter = Filter('filesize', FilterComparison.GT, '0') # act match = size_filter.filter(metadata) # assert assert match
def test_array_bad_query(): # arrange metadata = [] regex_filter = Filter('field', FilterComparison.REGEX, '.*2.*') # act match = regex_filter.filter(metadata) # assert assert not match
def test_lte_no_match_larger(): # arrange metadata = {'filesize': '20'} size_filter = Filter('filesize', FilterComparison.LTE, '0') # act match = size_filter.filter(metadata) # assert assert not match
def test_regex_no_match(): # arrange metadata = {'field': 'sdf'} regex_filter = Filter('field', FilterComparison.REGEX, 'a.*f') # act match = regex_filter.filter(metadata) # assert assert not match
def test_empty_dict_no_match(): # arrange metadata = {} regex_filter = Filter('field', FilterComparison.REGEX, '.*2.*') # act match = regex_filter.filter(metadata) # assert assert not match
def test_eq_matches_same_int(): # arrange metadata = {'filesize': 2320} size_filter = Filter('filesize', FilterComparison.EQ, '2320') # act match = size_filter.filter(metadata) # assert assert match
def test_lt_matches_smaller(): # arrange metadata = {'filesize': '20'} size_filter = Filter('filesize', FilterComparison.LT, '30') # act match = size_filter.filter(metadata) # assert assert match
def test_gt_matches_value_int(): # arrange metadata = {'filesize': 20} size_filter = Filter('filesize', FilterComparison.GT, '0') # act match = size_filter.filter(metadata) # assert assert match
def test_endswith_ints_match(): # arrange metadata = {'field': 123} ends_filter = Filter('field', FilterComparison.ENDS_WITH, '23') # act match = ends_filter.filter(metadata) # assert assert match
def test_eq_matches_same_string(): # arrange metadata = {'filesize': 'asdf'} size_filter = Filter('filesize', FilterComparison.EQ, 'asdf') # act match = size_filter.filter(metadata) # assert assert match
def test_startswith_ints_match(): # arrange metadata = {'field': 123} starts_filter = Filter('field', FilterComparison.STARTS_WITH, '1') # act match = starts_filter.filter(metadata) # assert assert match
def test_endswith_no_match(): # arrange metadata = {'field': 'asdfg'} ends_filter = Filter('field', FilterComparison.ENDS_WITH, 'asdf') # act match = ends_filter.filter(metadata) # assert assert not match
def test_contains_ints_match(): # arrange metadata = {'field': '123'} contains_filter = Filter('field', FilterComparison.CONTAINS, '2') # act match = contains_filter.filter(metadata) # assert assert match
def test_startswith_no_match(): # arrange metadata = {'field': 'asdfg'} starts_filter = Filter('field', FilterComparison.STARTS_WITH, 'sdf') # act match = starts_filter.filter(metadata) # assert assert not match
def test_eq_no_match_different(): # arrange metadata = {'filesize': '2320'} size_filter = Filter('filesize', FilterComparison.EQ, 'asdf') # act match = size_filter.filter(metadata) # assert assert not match
def test_contains_no_match_if_not_contained(): # arrange metadata = {'field': 'asd'} contains_filter = Filter('field', FilterComparison.CONTAINS, 'asdf') # act match = contains_filter.filter(metadata) # assert assert not match
def test_regex_matches(): # arrange metadata = {'field': 'asdf'} regex_filter = Filter('field', FilterComparison.REGEX, '^a.*f$') # act match = regex_filter.filter(metadata) # assert assert match
def test_gte_no_match_smaller(): # arrange metadata = {'filesize': '20'} size_filter = Filter('filesize', FilterComparison.GTE, '30') # act match = size_filter.filter(metadata) # assert assert not match
def test_lte_not_match_target_is_string(): # arrange metadata = {'filesize': '0'} size_filter = Filter('filesize', FilterComparison.LTE, 'asdf') # act match = size_filter.filter(metadata) # assert assert not match
def test_regex_ints_match(): # arrange metadata = {'field': 123} regex_filter = Filter('field', FilterComparison.REGEX, '.*2.*') # act match = regex_filter.filter(metadata) # assert assert match
def test_lt_not_match_value_is_string(): # arrange metadata = {'filesize': 'asdf'} size_filter = Filter('filesize', FilterComparison.LT, '0') # act match = size_filter.filter(metadata) # assert assert not match
def test_lte_matches_smaller_and_same(): # arrange same = {'filesize': '30'} smaller = {'filesize': '0'} size_filter = Filter('filesize', FilterComparison.LTE, '30') # act smaller_match = size_filter.filter(smaller) same_match = size_filter.filter(same) # assert assert smaller_match and same_match
def test_lt_no_match_larger_same(): # arrange larger = {'filesize': '20'} same = {'filesize': '0'} size_filter = Filter('filesize', FilterComparison.LT, '0') # act larger_match = size_filter.filter(larger) same_match = size_filter.filter(same) # assert assert not larger_match and not same_match
def test_gt_no_match_smaller_same(): # arrange same = {'filesize': '30'} smaller = {'filesize': '0'} size_filter = Filter('filesize', FilterComparison.GT, '30') # act smaller_match = size_filter.filter(smaller) same_match = size_filter.filter(same) # assert assert not smaller_match and not same_match
def test_gte_matches_larger_and_same(): # arrange larger = {'filesize': '20'} same = {'filesize': '0'} size_filter = Filter('filesize', FilterComparison.GTE, '0') # act larger_match = size_filter.filter(larger) same_match = size_filter.filter(same) # assert assert larger_match and same_match
def test_any_excluded(): # arrange bounty_filter = BountyFilter(None, [ Filter('mimetype', FilterComparison.EQ, 'text/plain'), Filter('mimetype', FilterComparison.EQ, 'text/html') ]) # act allowed = bounty_filter.is_allowed({'mimetype': 'text/html'}) # assert assert not allowed
def test_scans_artifact_accepted_match_only_one(): # arrange bounty_filter = BountyFilter([ Filter('mimetype', FilterComparison.EQ, 'text/plain'), Filter('mimetype', FilterComparison.EQ, 'text/html') ], None) # act allowed = bounty_filter.is_allowed({'mimetype': 'text/html'}) # assert assert allowed
def test_parse_filter_adds_both_favor_and_penalize(): # arrange # assert filters = parse_filters(None, None, [('favor', 'mimetype', 'contains', 'text'), ('penalize', 'mimetype', 'contains', 'pdf')]) # act assert filters['favor'][0] == Filter('mimetype', FilterComparison.CONTAINS, 'text') assert filters['penalize'][0] == Filter('mimetype', FilterComparison.CONTAINS, 'pdf')
def test_parse_filter_adds_both_accept_and_reject(): # arrange # assert filters = parse_filters(None, None, [('reject', 'mimetype', 'contains', 'text'), ('accept', 'mimetype', 'contains', 'pdf')]) # act assert filters['accept'][0] == Filter('mimetype', FilterComparison.CONTAINS, 'pdf') assert filters['reject'][0] == Filter('mimetype', FilterComparison.CONTAINS, 'text')