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')
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')
def test_case_insensitive_headers(): check_mimetype( 'http://localhost:8000/image.jpg', [ ('coNtENT-TypE', 'IMAgE/JpEG'), ('Content-Length', '654'), ], )
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)
def test_same_jpg_fail(): with pytest.raises(ValueError): check_mimetype( 'http://localhost:8000/image.jpg', [ ('Content-Type', 'image/jpg'), ('Content-Length', '654'), ], )
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)
def test_case_insensitive_headers_fail(): with pytest.raises(ValueError): check_mimetype( 'http://localhost:8000/image.jpg', [ ('CONTENT-TYPE', 'IMAGE/PNG'), ('Content-Length', '654'), ], )
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 )
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 )
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 )
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, )
def test_missing_file_suffix(): check_mimetype('http://localhost:8000/index', [ ('Content-Type', 'application/octet-stream'), ('Content-Length', '164'), ])
def test_normal_html(): check_mimetype('http://localhost:8000/index.html', [ ('Content-Type', 'text/html; charset=utf-8'), ('Content-Length', '164'), ])
def test_case_insensitive_file(): check_mimetype('http://localhost:8000/index.HTML', [ ('Content-Type', 'text/html; charset=utf-8'), ('Content-Length', '164'), ])
def test_case_insensitive_content_type(): check_mimetype('http://localhost:8000/index.html', [ ('Content-Type', 'TEXT/HTML; charset=utf-8'), ('Content-Length', '164'), ])
def test_directory(): check_mimetype('http://localhost:8000/foo/', [ ('Content-Type', 'text/html'), ])
def test_default_ignored(): check_mimetype('http://localhost:8000/picture.jpg', [ ('Content-Type', 'image/jpeg'), ('Content-Length', '164'), ], default='image/png')
def test_missing_file_default(): check_mimetype('http://localhost:8000/index', [ ('Content-Type', 'image/png'), ('Content-Length', '164'), ], default='image/png')
def test_missing_content_type(): with pytest.raises(ValueError): check_mimetype('http://localhost:8000/index.html', [ ('Content-Length', '164'), ])