From 264f9ee70b6bebc162a6152f0750aebfeb6f6b66 Mon Sep 17 00:00:00 2001 From: rr- Date: Sun, 14 Aug 2016 11:47:58 +0200 Subject: [PATCH] server/tests: update func.mime tests --- server/szurubooru/func/mime.py | 1 + server/szurubooru/tests/assets/text.txt | 1 + server/szurubooru/tests/func/test_mime.py | 16 ++++++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 server/szurubooru/tests/assets/text.txt diff --git a/server/szurubooru/func/mime.py b/server/szurubooru/func/mime.py index 76d6e281..54fe225e 100644 --- a/server/szurubooru/func/mime.py +++ b/server/szurubooru/func/mime.py @@ -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) diff --git a/server/szurubooru/tests/assets/text.txt b/server/szurubooru/tests/assets/text.txt new file mode 100644 index 00000000..ce013625 --- /dev/null +++ b/server/szurubooru/tests/assets/text.txt @@ -0,0 +1 @@ +hello diff --git a/server/szurubooru/tests/func/test_mime.py b/server/szurubooru/tests/func/test_mime.py index 1d5a13af..eaf69898 100644 --- a/server/szurubooru/tests/func/test_mime.py +++ b/server/szurubooru/tests/func/test_mime.py @@ -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),