Commit 28fc2f21 authored by Laurent Bachelier's avatar Laurent Bachelier

Directories have the "directory" mimetype by default

parent 8082b6cf
......@@ -162,6 +162,8 @@ class File(IObject):
def get_mimetype(self):
if self.mimetype:
return self.mimetype
if self.isdir():
return 'directory'
return mimetypes.guess_type(self.get_name())[0]
def get_hash(self):
......
......@@ -303,3 +303,16 @@ class StorageTest(TestCase):
f = self.storage.get_file('/penguin.txt')
assert f.get_mimetype() == 'text/penguin'
os.mkdir(os.path.join(self.root, 'penguins'))
f = self.storage.get_file('/penguins')
assert f.get_mimetype() == 'directory'
f.mimetype = 'text/penguins'
f.save()
f = self.storage.get_file('/penguins')
assert f.get_mimetype() == 'text/penguins'
os.mkdir(os.path.join(self.root, 'penguins.txt'))
f = self.storage.get_file('/penguins.txt')
assert f.get_mimetype() == 'directory'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment