Пример #1
0
    def test_download_artist(self):
        # Upload some files
        zipped_dropbox = os.path.join(TEST_FILES_DIR, 'test_dropbox.zip')
        with zipfile.ZipFile(zipped_dropbox, 'r') as f:
            f.extractall(self.dropbox)
        update.update()

        # make request
        c = Client()
        response = c.get(reverse('download_artist', args=[1]))

        # check response have right headers
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-Type'], 'application/zip')
        self.assertEqual(response['Content-Disposition'],
                         'attachment; filename=The%20Artist.zip')

        # check structure of returned zip file
        songs = Song.objects.filter(album__artist=1)
        original_song_names = [s.filefield.name[2:] for s in songs]

        content = ContentFile(response.content)
        self.assertTrue(zipfile.is_zipfile(content))
        with zipfile.ZipFile(content, 'r') as z:
            self.assertIsNone(z.testzip())
            self.assertItemsEqual(z.namelist(), original_song_names)
Пример #2
0
def update_library(request):
    #TODO: run asynchronously (using celery?)
    update.update()
    messages.add_message(request,
                         messages.INFO,
                         _('Library successfully updated'),
                         fail_silently=True)
    return redirect(reverse(library_home))
Пример #3
0
    def handle_noargs(self, **options):
        update()

        if os.listdir(settings.DROPBOX):
            self.stdout.write(
                'Some files were left in the dropbox. '
                'Please have a look to investigate.')
            self.stdout.write(
                '\nDROPBOX: %(dropbox)s\n' % {'dropbox': settings.DROPBOX})
Пример #4
0
    def test_importing_dummy_file_removes_it_from_dropbox(self):
        # create the dummy file
        filename = os.path.join(self.dropbox, '.DS_Store')
        with open(filename, 'w'):
            pass

        self.assertTrue(os.path.exists(filename))

        update.update()

        self.assertFalse(os.path.exists(filename))
        self.assertNoLogError()
Пример #5
0
    def setUp(self):
        if not os.path.exists(TEST_MEDIA_DIR):
            os.mkdir(TEST_MEDIA_DIR)
        if not os.path.exists(TEST_DROPBOX_DIR):
            os.mkdir(TEST_DROPBOX_DIR)

        # Swap CustomStorage for song.filefield and album.cover for
        # testing so that it uses the temporary media folder instead
        # of settings.MEDIA_ROOT
        test_storage = CustomStorage(location=TEST_MEDIA_DIR)
        self._songfield = Song._meta.get_field_by_name("filefield")[0]
        self._default_storage = self._songfield.storage
        self._songfield.storage = test_storage
        self._albumfield = Album._meta.get_field_by_name("cover")[0]
        self._albumfield.storage = test_storage

        # Upload some songs to the library
        zipped_dropbox = os.path.join(TEST_FILES_DIR, "test_dropbox.zip")
        with zipfile.ZipFile(zipped_dropbox, "r") as f:
            f.extractall(TEST_DROPBOX_DIR)
        update.update()