server/tests: update func.mime tests

This commit is contained in:
rr- 2016-08-14 11:47:58 +02:00
parent c23c401c4d
commit 264f9ee70b
3 changed files with 18 additions and 0 deletions

View file

@ -33,6 +33,7 @@ def get_extension(mime_type):
'image/png': 'png',
'video/mp4': 'mp4',
'video/webm': 'webm',
'application/octet-stream': 'dat',
}
return extension_map.get((mime_type or '').strip().lower(), None)

View file

@ -0,0 +1 @@
hello

View file

@ -9,10 +9,26 @@ from szurubooru.func import mime
('png.png', 'image/png'),
('jpeg.jpg', 'image/jpeg'),
('gif.gif', 'image/gif'),
('text.txt', 'application/octet-stream'),
])
def test_get_mime_type(read_asset, input_path, expected_mime_type):
assert mime.get_mime_type(read_asset(input_path)) == expected_mime_type
def test_get_mime_type_for_empty_file():
assert mime.get_mime_type(b'') == 'application/octet-stream'
@pytest.mark.parametrize('mime_type,expected_extension', [
('video/mp4', 'mp4'),
('video/webm', 'webm'),
('application/x-shockwave-flash', 'swf'),
('image/png', 'png'),
('image/jpeg', 'jpg'),
('image/gif', 'gif'),
('application/octet-stream', 'dat'),
])
def test_get_extension(mime_type, expected_extension):
assert mime.get_extension(mime_type) == expected_extension
@pytest.mark.parametrize('input_mime_type,expected_state', [
('application/x-shockwave-flash', True),
('APPLICATION/X-SHOCKWAVE-FLASH', True),