Example #1
0
def test_policy_mime_rules_no_images():
    mime_type_rules = PolicyMimeTypeRules([
        {
            'pattern': '^image/',
            'match': 'MATCHES',
            'save': False
        },
        {
            'save': True
        },
    ])
    assert mime_type_rules.should_save('text/plain')
    assert mime_type_rules.should_save('application/pdf')
    assert not mime_type_rules.should_save('image/png')
Example #2
0
def test_policy_mime_rules_text_only():
    mime_type_rules = PolicyMimeTypeRules([
        {
            'pattern': '^text/',
            'match': 'MATCHES',
            'save': True
        },
        {
            'save': False
        },
    ])
    assert mime_type_rules.should_save('text/plain')
    assert not mime_type_rules.should_save('application/pdf')
    assert not mime_type_rules.should_save('image/png')

    # Same rules but with the match & save inverted.
    mime_type_rules = PolicyMimeTypeRules([
        {
            'pattern': '^text/',
            'match': 'DOES_NOT_MATCH',
            'save': False
        },
        {
            'save': True
        },
    ])
    assert mime_type_rules.should_save('text/plain')
    assert not mime_type_rules.should_save('application/pdf')
    assert not mime_type_rules.should_save('image/png')