예제 #1
0
파일: test_utils.py 프로젝트: tutuca/vortex
    def test_remove_empty_directories(self):
        artist = Artist.objects.get(pk=1)
        original_path = artist.filepath

        artist.name = "Brian"
        artist.save()
        sync_song_files()
        sync_cover_images()

        self.assertTrue(os.path.exists(full_path(original_path)))
        self.assertTrue(os.path.exists(full_path(artist.filepath)))

        remove_empty_directories()

        self.assertFalse(os.path.exists(full_path(original_path)))
        self.assertTrue(os.path.exists(full_path(artist.filepath)))
예제 #2
0
    def test_save_album_without_change_is_idempotent(self):
        album = Album.objects.get(title='First Album')
        self.assertEqual(album.title, 'First Album')
        self.assertEqual(album.artist.name, 'The Artist')
        self.assertEqual(album.filepath, 'T/The Artist/First Album')
        self.assertTrue(os.path.exists(full_path(album.filepath)))
        self.assertItemsEqual(os.listdir(full_path(album.filepath)),
                              ['cover.jpg', 'The First Song.ogg'])

        album.save()

        self.assertEqual(album.title, 'First Album')
        self.assertEqual(album.artist.name, 'The Artist')
        self.assertEqual(album.filepath, 'T/The Artist/First Album')
        self.assertTrue(os.path.exists(full_path(album.filepath)))
        self.assertItemsEqual(os.listdir(full_path(album.filepath)),
                              ['cover.jpg', 'The First Song.ogg'])
예제 #3
0
파일: test_utils.py 프로젝트: tutuca/vortex
    def test_sync_cover_images(self):
        album = Album.objects.get(pk=1)
        original_coverpath = album.cover_filepath
        self.assertEqual(album.cover_filepath, "T/The Artist/The Album/cover.jpg")
        self.assertTrue(os.path.exists(full_path(album.cover_filepath)))

        album.title = "Egg"
        album.save()

        self.assertEqual(album.cover_filepath, "T/The Artist/Egg/cover.jpg")
        self.assertTrue(os.path.exists(full_path(original_coverpath)))
        self.assertFalse(os.path.exists(full_path(album.cover_filepath)))

        sync_cover_images()

        self.assertFalse(os.path.exists(full_path(original_coverpath)))
        self.assertTrue(os.path.exists(full_path(album.cover_filepath)))
예제 #4
0
파일: test_utils.py 프로젝트: tutuca/vortex
    def test_sync_song_files(self):
        song = Song.objects.get(pk=1)
        original_filepath = song.filepath
        self.assertEqual(song.filepath, "T/The Artist/The Album/04 - The Fourth Song.ogg")
        self.assertTrue(os.path.exists(full_path(song.filepath)))

        song.title = "Spam"
        song.save()

        self.assertEqual(song.filepath, "T/The Artist/The Album/04 - Spam.ogg")
        self.assertTrue(os.path.exists(full_path(original_filepath)))
        self.assertFalse(os.path.exists(full_path(song.filepath)))

        sync_song_files()

        self.assertFalse(os.path.exists(full_path(original_filepath)))
        self.assertTrue(os.path.exists(full_path(song.filepath)))
예제 #5
0
    def test_save_artist_without_change_is_idempotent(self):
        artist = Artist.objects.get(name='First Artist')
        self.assertEqual(artist.name, 'First Artist')
        self.assertEqual(artist.filepath, 'F/First Artist')
        self.assertItemsEqual(
            artist.album_set.values_list('title', flat=True),
            ['First Album', 'Common Album'])
        self.assertTrue(os.path.exists(full_path(artist.filepath)))
        self.assertItemsEqual(os.listdir(full_path(artist.filepath)),
                              ['First Album', 'Common Album'])

        artist.save()

        self.assertEqual(artist.name, 'First Artist')
        self.assertEqual(artist.filepath, 'F/First Artist')
        self.assertItemsEqual(
            artist.album_set.values_list('title', flat=True),
            ['First Album', 'Common Album'])
        self.assertTrue(os.path.exists(full_path(artist.filepath)))
        self.assertItemsEqual(os.listdir(full_path(artist.filepath)),
                              ['First Album', 'Common Album'])
예제 #6
0
    def test_save_song_without_change_is_idempotent(self):
        self.assertEqual(self.song.title, 'The Song')
        self.assertEqual(self.song.album.title, 'The Album')
        self.assertEqual(self.song.album.artist.name, 'The Artist')
        self.assertEqual(self.song.filefield.name,
                         'T/The Artist/The Album/The Song.ogg')
        self.assertTrue(os.path.exists(full_path(self.song.filefield.name)))

        original_content = self.song.filefield.read()

        self.song.save()

        self.assertEqual(self.song.title, 'The Song')
        self.assertEqual(self.song.album.title, 'The Album')
        self.assertEqual(self.song.album.artist.name, 'The Artist')
        self.assertEqual(self.song.filefield.name,
                         'T/The Artist/The Album/The Song.ogg')
        self.assertTrue(os.path.exists(full_path(self.song.filefield.name)))

        self.song.filefield.seek(0)
        current_content = self.song.filefield.read()

        self.assertEqual(original_content, current_content)
예제 #7
0
파일: views.py 프로젝트: tutuca/vortex
def _download(instance):
    """Returns a HTTP response that is a ZIP file of the folder
    at instance.filepath.
    """
    tfile = tempfile.NamedTemporaryFile(suffix='.zip')
    zip_folder(full_path(instance.filepath), tfile.name)

    #TODO: Use iterator instead in case data is too big for memory. This
    # implies that the temporary file needs to stay on disk during download,
    # and that it is deleted at some later time.
    tfile.seek(0)
    data = tfile.read()
    tfile.close()

    response = HttpResponse(data, content_type='application/zip')
    filename = iri_to_uri(urlquote(unicode(instance)))
    response['Content-Disposition'] = \
        u'attachment; filename=%s.zip' % filename
    return response
예제 #8
0
파일: test_utils.py 프로젝트: tutuca/vortex
    def test_sync_songs_and_cover(self):
        artist = Artist.objects.get(pk=1)
        original_path = artist.filepath
        self.assertEqual(artist.filepath, "T/The Artist")
        self.assertTrue(os.path.exists(full_path(artist.filepath)))
        self.assertTrue(os.path.exists(os.path.join(full_path(artist.filepath), "The Album", "cover.jpg")))

        artist.name = "Brian"
        artist.save()

        self.assertEqual(artist.filepath, "B/Brian")
        self.assertTrue(os.path.exists(full_path(original_path)))
        self.assertFalse(os.path.exists(full_path(artist.filepath)))
        self.assertTrue(os.path.exists(os.path.join(full_path(original_path), "The Album", "cover.jpg")))

        sync_song_files()
        sync_cover_images()

        self.assertTrue(os.path.exists(full_path(artist.filepath)))
        self.assertTrue(os.path.exists(os.path.join(full_path(artist.filepath), "The Album", "cover.jpg")))