Skip to content

Commit

Permalink
[Fixes #41692207] Added UNKNOWN as a catch-all file type for unknown …
Browse files Browse the repository at this point in the history
…file types. Modified set_filetype() to accept any file types.
  • Loading branch information
hackdna committed Dec 28, 2012
1 parent 92c9c6e commit 12c57cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 6 additions & 3 deletions refinery/file_store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def file_path(instance, filename):
WIG = 'wig'
XML = 'xml'
ZIP = 'zip'
UNKNOWN = '' # special catch-all type with no corresponding extension

# file types with descriptions used by FileStoreItem.filetype choice field
FILE_TYPES = (
Expand Down Expand Up @@ -166,6 +167,7 @@ def file_path(instance, filename):
(WIG, 'Wiggle Track Format'),
(XML, 'XML file'),
(ZIP, 'Zip compressed archive'),
(UNKNOWN, 'Unknown file type'),
)

# mapping of file extensions to file types
Expand Down Expand Up @@ -352,7 +354,8 @@ def set_filetype(self, filetype=''):
try:
self.filetype = FILE_EXTENSIONS[filetype]
except KeyError:
logger.error("'%s' is an invalid file type", filetype)
logger.info("'%s' is an unknown file type", filetype)
self.filetype = UNKNOWN
return False

self.save()
Expand All @@ -373,7 +376,7 @@ def is_symlinked(self):

def is_local(self):
'''Check if the datafile can be used as a file object.
:returns: bool -- True if the datafile can be used as a file object, False otherwise.
'''
Expand All @@ -389,7 +392,7 @@ def is_local(self):

def delete_datafile(self):
'''Delete datafile if it exists on disk.
:returns: bool -- True if deletion succeeded, False otherwise.
'''
Expand Down
12 changes: 7 additions & 5 deletions refinery/file_store/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_get_file_type(self):
'''Check that the correct file type is returned
'''
filetype = 'bb'
filetype = models.BIGBED
item_from_path = models.FileStoreItem.objects.create(source=self.url_source,
sharename=self.sharename,
filetype=filetype)
Expand All @@ -128,23 +128,25 @@ def test_set_valid_file_type(self):
sharename=self.sharename)
item_from_url = models.FileStoreItem.objects.create(source=self.path_source,
sharename=self.sharename)
filetype = 'wig'
filetype = models.WIG
self.assertTrue(item_from_path.set_filetype(filetype))
self.assertEqual(item_from_path.filetype, filetype)
self.assertTrue(item_from_url.set_filetype(filetype))
self.assertEqual(item_from_url.filetype, filetype)

def test_set_invalid_file_type(self):
'''Check that an invalid file type is not set
def test_set_unkown_file_type(self):
'''Check that an unknown file type is not set
'''
item_from_url = models.FileStoreItem.objects.create(source=self.path_source,
sharename=self.sharename)
item_from_path = models.FileStoreItem.objects.create(source=self.url_source,
sharename=self.sharename)
filetype = 'invalidtype'
filetype = 'unknowntype'
self.assertFalse(item_from_path.set_filetype(filetype))
self.assertEqual(item_from_path.filetype, models.UNKNOWN)
self.assertFalse(item_from_url.set_filetype(filetype))
self.assertEqual(item_from_url.filetype, models.UNKNOWN)

def test_set_file_type_automatically(self):
'''Check that a file type is set automatically
Expand Down

0 comments on commit 12c57cd

Please sign in to comment.