Skip to content

Commit

Permalink
falls back to id on empty title for all filename handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
beaufour committed Apr 28, 2015
1 parent 57dee7c commit c2951dc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions flickr_download/filename_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def title_and_id(pset, photo, suffix):
@param suffice: str, optional suffix
@return: str, the filename
"""
if not photo.title:
return idd(pset, photo, suffix)

return '{0}-{1}{2}.jpg'.format(photo.title, photo.id, suffix)


Expand All @@ -61,6 +64,9 @@ def title_increment(pset, photo, suffix):
@param suffice: str, optional suffix
@return: str, the filename
"""
if not photo.title:
return idd(pset, photo, suffix)

extra = ''
photo_index = INCREMENT_INDEX[pset.id][photo.title]
if photo_index:
Expand Down
14 changes: 13 additions & 1 deletion tests/filename_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_title(self):
self.assertEqual(fn(self._pset, self._photo, self._suffix),
'Some Photo.jpg')

def test_empty_title(self):
def test_title_empty_title(self):
photo = AttrDict({'title': '', 'id': 192})
fn = get_filename_handler('title')
self.assertEqual(fn(self._pset, photo, self._suffix),
Expand All @@ -27,6 +27,12 @@ def test_title_and_id(self):
self.assertEqual(fn(self._pset, self._photo, self._suffix),
'Some Photo-123.jpg')

def test_title_and_id_empty_title(self):
photo = AttrDict({'title': '', 'id': 1389})
fn = get_filename_handler('title_and_id')
self.assertEqual(fn(self._pset, photo, self._suffix),
'1389.jpg')

def test_id(self):
fn = get_filename_handler('id')
self.assertEqual(fn(self._pset, self._photo, self._suffix),
Expand All @@ -50,5 +56,11 @@ def test_title_increment(self):
self.assertEqual(fn(pset2, self._photo, self._suffix),
'Some Photo.jpg')

def test_title_increment_empty_title(self):
photo = AttrDict({'title': '', 'id': 175})
fn = get_filename_handler('title_increment')
self.assertEqual(fn(self._pset, photo, self._suffix),
'175.jpg')

if __name__ == '__main__':
unittest.main()

0 comments on commit c2951dc

Please sign in to comment.