示例#1
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')
示例#2
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')
示例#3
0
def test_policy_mime_rules_missing_save():
    with pytest.raises(PolicyValidationError):
        PolicyMimeTypeRules([
            {
                'pattern': '^text/(',
                'match': 'MATCHES'
            },
            {
                'save': False
            },
        ])
    with pytest.raises(PolicyValidationError):
        PolicyMimeTypeRules([
            {
                'pattern': '^text/(',
                'match': 'MATCHES',
                'save': True
            },
            {},
        ])
示例#4
0
def test_policy_mime_rules_invalid_terminal():
    # Save is required in terminal rule:
    with pytest.raises(PolicyValidationError):
        PolicyMimeTypeRules([
            {
                'pattern': '^text/',
                'match': 'MATCHES',
                'save': True
            },
            {},
        ])
    # Pattern is not allowed in terminal rule:
    with pytest.raises(PolicyValidationError):
        PolicyMimeTypeRules([
            {
                'pattern': '^text/',
                'match': 'MATCHES',
                'save': True
            },
            {
                'pattern': '^image/',
                'save': True
            },
        ])
    # Match is not allowed in terminal rule:
    with pytest.raises(PolicyValidationError):
        PolicyMimeTypeRules([
            {
                'pattern': '^text/',
                'match': 'MATCHES',
                'save': True
            },
            {
                'match': 'MATCHES',
                'save': True
            },
        ])
示例#5
0
def test_policy_mime_rules_no_rules():
    with pytest.raises(PolicyValidationError):
        PolicyMimeTypeRules([])