Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
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
Exemple #6
0
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
Exemple #7
0
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
Exemple #8
0
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
Exemple #9
0
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
Exemple #10
0
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
Exemple #11
0
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
Exemple #12
0
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
Exemple #13
0
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
Exemple #14
0
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
Exemple #15
0
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
Exemple #16
0
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
Exemple #17
0
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
Exemple #18
0
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
Exemple #19
0
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
Exemple #20
0
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
Exemple #21
0
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
Exemple #22
0
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
Exemple #23
0
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
Exemple #24
0
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
Exemple #25
0
def test_array_bad_query():
    # arrange
    metadata = []
    regex_filter = Filter('field', FilterComparison.REGEX, '.*2.*')
    # act
    match = regex_filter.filter(metadata)
    # assert
    assert not match
Exemple #26
0
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