Fix renaming of stored playlists on disk

This commit is contained in:
Thomas Adamcik 2010-04-26 23:24:12 +02:00
parent 658925dfc1
commit cf05777e9f
2 changed files with 17 additions and 3 deletions

View File

@ -9,6 +9,7 @@ pygst.require('0.10')
import gst
import logging
import os
import shutil
import threading
from mopidy.backends import *
@ -131,10 +132,15 @@ class GStreamerStoredPlaylistsController(BaseStoredPlaylistsController):
if playlist not in self._playlists:
return
src = os.path.join(self._folder, playlist.name + '.m3u')
dst = os.path.join(self._folder, name + '.m3u')
renamed = playlist.with_(name=name)
index = self._playlists.index(playlist)
self._playlists[index] = renamed
shutil.move(src, dst)
def save(self, playlist):
file = os.path.join(self._folder, playlist.name + '.m3u')
open(file, 'w').close()

View File

@ -57,20 +57,28 @@ class GStreamerBackendStoredPlaylistsControllerTest(BaseStoredPlaylistsControlle
def test_created_playlist_is_persisted(self):
self.stored.create('test')
file= os.path.join(settings.PLAYLIST_FOLDER, 'test.m3u')
file = os.path.join(settings.PLAYLIST_FOLDER, 'test.m3u')
self.assert_(os.path.exists(file))
def test_saved_playlist_is_persisted(self):
self.stored.save(Playlist(name='test2'))
file= os.path.join(settings.PLAYLIST_FOLDER, 'test2.m3u')
file = os.path.join(settings.PLAYLIST_FOLDER, 'test2.m3u')
self.assert_(os.path.exists(file))
def test_deleted_playlist_get_removed(self):
playlist = self.stored.create('test')
self.stored.delete(playlist)
file= os.path.join(settings.PLAYLIST_FOLDER, 'test.m3u')
file = os.path.join(settings.PLAYLIST_FOLDER, 'test.m3u')
self.assert_(not os.path.exists(file))
def test_renamed_playlist_gets_moved(self):
playlist = self.stored.create('test')
self.stored.rename(playlist, 'test2')
file1 = os.path.join(settings.PLAYLIST_FOLDER, 'test.m3u')
file2 = os.path.join(settings.PLAYLIST_FOLDER, 'test2.m3u')
self.assert_(not os.path.exists(file1))
self.assert_(os.path.exists(file2))
if __name__ == '__main__':
unittest.main()