Beispiel #1
0
def test_missing_file_default_fail():
    with pytest.raises(ValueError):
        check_mimetype('http://localhost:8000/index', [
            ('Content-Type', 'text/html'),
            ('Content-Length', '164'),
        ],
                       default='image/png')
Beispiel #2
0
def test_default_ignored_fail():
    with pytest.raises(ValueError):
        check_mimetype('http://localhost:8000/picture.jpg', [
            ('Content-Type', 'image/png'),
            ('Content-Length', '164'),
        ],
                       default='image/png')
Beispiel #3
0
def test_case_insensitive_headers():
    check_mimetype(
        'http://localhost:8000/image.jpg',
        [
            ('coNtENT-TypE', 'IMAgE/JpEG'),
            ('Content-Length', '654'),
        ],
    )
Beispiel #4
0
def test_default_include(testname):
    url_path, headers, default = TEST_DATA_DEFAULT[testname]
    error = testname[-5:] == '_fail'

    if error:
        with pytest.raises(ValueError):
            check_mimetype(url_path, headers, default=default)
    else:
        check_mimetype(url_path, headers, default=default)
Beispiel #5
0
def test_same_jpg_fail():
    with pytest.raises(ValueError):
        check_mimetype(
            'http://localhost:8000/image.jpg',
            [
                ('Content-Type', 'image/jpg'),
                ('Content-Length', '654'),
            ],
        )
Beispiel #6
0
def test_kwargs_exclude(testname):
    url_path, headers= TEST_DATA[testname]
    error = testname[-5:] == '_fail'

    if error:
        with pytest.raises(ValueError):
            check_mimetype(url_path, headers)
    else:
        check_mimetype(url_path, headers)
Beispiel #7
0
def test_case_insensitive_headers_fail():
    with pytest.raises(ValueError):
        check_mimetype(
            'http://localhost:8000/image.jpg',
            [
                ('CONTENT-TYPE', 'IMAGE/PNG'),
                ('Content-Length', '654'),
            ],
        )
Beispiel #8
0
def test_get_mimetype_capital_mimetype(monkeypatch):
    def get_mimetype(url_path):
        return ["image/PNG"]

    check_mimetype(
        'http://localhost:8000/image.png',
        [
            ('Content-Type', 'image/png'),
            ('Content-Length', '164'),
        ],
        get_mimetype=get_mimetype
    )
Beispiel #9
0
def test_missing_file_suffix_get_mimetype():
    def get_mimetype(url_path):
        return ["image/png"]

    check_mimetype(
        'http://localhost:8000/index',
        [
            ('Content-Type', 'image/png'),
            ('Content-Length', '164'),
        ],
        get_mimetype=get_mimetype
    )
Beispiel #10
0
def test_missing_file_suffix_get_mimetype_fail():
    def get_mimetype(url_path):
        return ["image/png"]

    with pytest.raises(ValueError):
        check_mimetype(
            'http://localhost:8000/index',
            [
                ('Content-Type', 'image/jpeg'),
                ('Content-Length', '164'),
            ],
            get_mimetype=get_mimetype
        )
Beispiel #11
0
def test_missing_file_suffix_get_mimetype_fail_default_ignored():
    def get_mimetype(url_path):
        return ["image/bmp"]

    with pytest.raises(ValueError):
        check_mimetype(
            'http://localhost:8000/index',
            [
                ('Content-Type', 'text/html'),
                ('Content-Length', '164'),
            ],
            default='text/html',
            get_mimetype=get_mimetype,

        )
Beispiel #12
0
def test_missing_file_suffix():
    check_mimetype('http://localhost:8000/index', [
        ('Content-Type', 'application/octet-stream'),
        ('Content-Length', '164'),
    ])
Beispiel #13
0
def test_normal_html():
    check_mimetype('http://localhost:8000/index.html', [
        ('Content-Type', 'text/html; charset=utf-8'),
        ('Content-Length', '164'),
    ])
Beispiel #14
0
def test_case_insensitive_file():
    check_mimetype('http://localhost:8000/index.HTML', [
        ('Content-Type', 'text/html; charset=utf-8'),
        ('Content-Length', '164'),
    ])
Beispiel #15
0
def test_case_insensitive_content_type():
    check_mimetype('http://localhost:8000/index.html', [
        ('Content-Type', 'TEXT/HTML; charset=utf-8'),
        ('Content-Length', '164'),
    ])
Beispiel #16
0
def test_directory():
    check_mimetype('http://localhost:8000/foo/', [
        ('Content-Type', 'text/html'),
    ])
Beispiel #17
0
def test_default_ignored():
    check_mimetype('http://localhost:8000/picture.jpg', [
        ('Content-Type', 'image/jpeg'),
        ('Content-Length', '164'),
    ],
                   default='image/png')
Beispiel #18
0
def test_missing_file_default():
    check_mimetype('http://localhost:8000/index', [
        ('Content-Type', 'image/png'),
        ('Content-Length', '164'),
    ],
                   default='image/png')
Beispiel #19
0
def test_missing_content_type():
    with pytest.raises(ValueError):
        check_mimetype('http://localhost:8000/index.html', [
            ('Content-Length', '164'),
        ])