Ejemplo n.º 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')
Ejemplo n.º 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')
Ejemplo n.º 3
0
def test_case_insensitive_headers():
    check_mimetype(
        'http://localhost:8000/image.jpg',
        [
            ('coNtENT-TypE', 'IMAgE/JpEG'),
            ('Content-Length', '654'),
        ],
    )
Ejemplo n.º 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)
Ejemplo n.º 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'),
            ],
        )
Ejemplo n.º 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)
Ejemplo n.º 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'),
            ],
        )
Ejemplo n.º 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
    )
Ejemplo n.º 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
    )
Ejemplo n.º 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
        )
Ejemplo n.º 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,

        )
Ejemplo n.º 12
0
def test_missing_file_suffix():
    check_mimetype('http://localhost:8000/index', [
        ('Content-Type', 'application/octet-stream'),
        ('Content-Length', '164'),
    ])
Ejemplo n.º 13
0
def test_normal_html():
    check_mimetype('http://localhost:8000/index.html', [
        ('Content-Type', 'text/html; charset=utf-8'),
        ('Content-Length', '164'),
    ])
Ejemplo n.º 14
0
def test_case_insensitive_file():
    check_mimetype('http://localhost:8000/index.HTML', [
        ('Content-Type', 'text/html; charset=utf-8'),
        ('Content-Length', '164'),
    ])
Ejemplo n.º 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'),
    ])
Ejemplo n.º 16
0
def test_directory():
    check_mimetype('http://localhost:8000/foo/', [
        ('Content-Type', 'text/html'),
    ])
Ejemplo n.º 17
0
def test_default_ignored():
    check_mimetype('http://localhost:8000/picture.jpg', [
        ('Content-Type', 'image/jpeg'),
        ('Content-Length', '164'),
    ],
                   default='image/png')
Ejemplo n.º 18
0
def test_missing_file_default():
    check_mimetype('http://localhost:8000/index', [
        ('Content-Type', 'image/png'),
        ('Content-Length', '164'),
    ],
                   default='image/png')
Ejemplo n.º 19
0
def test_missing_content_type():
    with pytest.raises(ValueError):
        check_mimetype('http://localhost:8000/index.html', [
            ('Content-Length', '164'),
        ])