mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	fixes #78
This commit is contained in:
		@@ -51,7 +51,11 @@ def get_default_file_extension(mime_type):
 | 
				
			|||||||
        if mime_type in supported_mime_types:
 | 
					        if mime_type in supported_mime_types:
 | 
				
			||||||
            return supported_mime_types[mime_type]
 | 
					            return supported_mime_types[mime_type]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return None
 | 
					    ext = mimetypes.guess_extension(mime_type)
 | 
				
			||||||
 | 
					    if ext:
 | 
				
			||||||
 | 
					        return ext
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        return ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def is_file_ext_supported(ext):
 | 
					def is_file_ext_supported(ext):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
import os
 | 
					 | 
				
			||||||
import shutil
 | 
					import shutil
 | 
				
			||||||
import tempfile
 | 
					import tempfile
 | 
				
			||||||
 | 
					from datetime import datetime
 | 
				
			||||||
from pathlib import Path
 | 
					from pathlib import Path
 | 
				
			||||||
from unittest import mock
 | 
					from unittest import mock
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -44,3 +44,23 @@ class TestDocument(TestCase):
 | 
				
			|||||||
            mock_unlink.assert_any_call(file_path)
 | 
					            mock_unlink.assert_any_call(file_path)
 | 
				
			||||||
            mock_unlink.assert_any_call(thumb_path)
 | 
					            mock_unlink.assert_any_call(thumb_path)
 | 
				
			||||||
            self.assertEqual(mock_unlink.call_count, 2)
 | 
					            self.assertEqual(mock_unlink.call_count, 2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_file_name(self):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        doc = Document(mime_type="application/pdf", title="test", created=datetime(2020, 12, 25))
 | 
				
			||||||
 | 
					        self.assertEqual(doc.file_name, "20201225-test.pdf")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_file_name_jpg(self):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        doc = Document(mime_type="image/jpeg", title="test", created=datetime(2020, 12, 25))
 | 
				
			||||||
 | 
					        self.assertEqual(doc.file_name, "20201225-test.jpg")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_file_name_unknown(self):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        doc = Document(mime_type="application/zip", title="test", created=datetime(2020, 12, 25))
 | 
				
			||||||
 | 
					        self.assertEqual(doc.file_name, "20201225-test.zip")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_file_name_invalid(self):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        doc = Document(mime_type="image/jpegasd", title="test", created=datetime(2020, 12, 25))
 | 
				
			||||||
 | 
					        self.assertEqual(doc.file_name, "20201225-test")
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user