示例#1
0
文件: tasks.py 项目: rodo/calorine
    def test_importupload_success(self):
        """
        Simple upload

        Assume all is ok
        """
        http = TestServer()
        http.start()
        url = 'http://127.0.0.1:%d/progress-url-test' % (http.port)

        Upload.objects.all().delete()

        fpath = os.path.join(os.path.dirname(__file__),
                             'samples',
                             'first',
                             'test.ogg')

        newpath = move_file(fpath, 'toto.ogg')

        upl = Upload.objects.create(uuid='123456789',
                                    user=self.user,
                                    path=newpath,
                                    filename='The Healing Game.ogg',
                                    content_type='application/ogg')

        result = import_upload(upl.uuid, 2, url)

        self.assertEqual(result['state'], 'done')
示例#2
0
文件: tasks.py 项目: rodo/calorine
def store_upload(upload):
    """Store the file uploaded
    """
    oggname = None
    newpath = move_file(upload.path, upload.filename)
    try:
        mime = Mime.objects.get(name=upload.content_type)
        logger.info("will use %s() to convert %s" % (mime.function,
                                                     mime.name))
    except ObjectDoesNotExist:
        logger.error("(%s) wrong mime/type for %s %s" % ('store_upload',
                                                         newpath,
                                                         upload.content_type))
        upload.status = 'bad format'
        upload.save()
        return 1

    convert = getattr(calorine.caro.converters, mime.function)
    oggname = convert(newpath, upload)

    if oggname is None:
        return 2
    else:
        importsong(oggname)
        upload.status = 'done'
        upload.save()
        mail_uploader.delay(upload)
        return 0
示例#3
0
文件: tasks.py 项目: rodo/calorine
    def test_store_upload_wrongfile(self):
        """
        Test with a wrong file, text.mp3 contains plaintext
        """
        settings.REMOVE_UPLOAD_FILES = False

        fpath = os.path.join(os.path.dirname(__file__),
                             'samples',
                             'text.mp3')

        move_file(fpath, 'text.mp3')

        upl = Upload.objects.create(uuid='123456789',
                                    user=self.user,
                                    path=os.path.join(self.tpath, 'text.mp3'),
                                    filename='text.mp3',
                                    content_type='audio/mp3')
        self.assertEqual(store_upload(upl), 2)
示例#4
0
文件: tasks.py 项目: rodo/calorine
    def test_store_upload_mp3(self):
        """
        Test with a picture with cover
        """
        settings.REMOVE_UPLOAD_FILES = False

        fpath = os.path.join(os.path.dirname(__file__),
                             'samples',
                             'Cocaine.mp3')

        move_file(fpath, 'Cocaine.mp3')

        upl = Upload.objects.create(uuid='123456789',
                                    user=self.user,
                                    path=os.path.join(self.tpath,
                                                      'Cocaine.mp3'),
                                    filename='Cocaine.mp3',
                                    content_type='audio/mp3')
        self.assertEqual(store_upload(upl), 0)
示例#5
0
    def test_convert_mp4(self):
        """Convert mp4 in ogg
        """
        fpath = path.join(path.dirname(__file__),
                          'samples',
                          'test.m4a')

        newpath = move_file(fpath, 'test.m4a')

        upl = Upload.objects.create(uuid='123456789',
                                    user=self.user,
                                    path=newpath,
                                    filename='Cocaine.mp3',
                                    content_type='audio/mp3')

        oggpath = convert_mp4(newpath, upl)

        self.assertTrue(path.exists(oggpath))
        self.assertEqual(upl.status, 'uploaded')
示例#6
0
文件: tasks.py 项目: rodo/calorine
    def test_store_upload_nonaudio(self):
        """
        Test with a picture with cover
        """
        settings.REMOVE_UPLOAD_FILES = False

        fpath = os.path.join(os.path.dirname(__file__),
                             'samples',
                             'first',
                             'test.ogg')

        newpath = move_file(fpath, 'toto.ogg')

        upl = Upload.objects.create(uuid='123456789',
                                    user=self.user,
                                    path=newpath,
                                    filename='The Healing Game.ogg',
                                    content_type='image/jpeg')

        result = store_upload(upl)

        self.assertEqual(result, 1)