Fix uri_to_mpd_relative_path so that it handles None
This commit is contained in:
parent
8240dbbb55
commit
014e29ffa2
@ -87,6 +87,8 @@ def uri_to_mpd_relative_path(uri):
|
||||
:type uri: string
|
||||
:rtype: string
|
||||
"""
|
||||
if uri is None:
|
||||
return ''
|
||||
path = path_to_uri(settings.LOCAL_MUSIC_FOLDER)
|
||||
return re.sub('^' + re.escape(path), '', uri)
|
||||
|
||||
|
||||
@ -67,6 +67,11 @@ class UriToMpdRelativePathTest(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
settings.runtime.clear()
|
||||
|
||||
def test_none_file_returns_empty_string(self):
|
||||
uri = 'file:///dir/subdir/music/album/song.mp3'
|
||||
result = translator.uri_to_mpd_relative_path(None)
|
||||
self.assertEqual('', result)
|
||||
|
||||
def test_file_gets_stripped(self):
|
||||
uri = 'file:///dir/subdir/music/album/song.mp3'
|
||||
result = translator.uri_to_mpd_relative_path(uri)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user