def test_transcode_oncomplete(self):
        """
        test for transcode_oncomplete signal
        """

        # assume an encode job was submitted
        item = Item.objects.create(name='Hello')

        ctype = ContentType.objects.get_for_model(item)

        job = EncodeJob()
        job.id = '1396802241671-jkmme8'
        job.content_type = ctype
        job.object_id = item.id
        job.save()

        #
        with open(os.path.join(FIXTURE_DIRS, 'oncomplete.json')) as f:
            resp = json.loads(f.read())
            message = json.loads(resp['Message'])

        # send signal
        transcode_oncomplete.send(sender=None, message=message)

        #
        job = EncodeJob.objects.get(pk=message['jobId'])

        #
        self.assertEqual(1, EncodeJob.objects.count())
        self.assertEqual('1396802241671-jkmme8', job.id)
        self.assertEqual('Success', job.message)
        self.assertEqual(4, job.state)
    def test_transcode_onerror(self):
        """
        test for transcode_onerror signal
        """

        # assume an encode job was submitted
        item = Item.objects.create(name='Hello')

        ctype = ContentType.objects.get_for_model(item)

        job = EncodeJob()
        job.id = '1396802241671-jkmme8'
        job.content_type = ctype
        job.object_id = item.id
        job.save()

        #
        with open(os.path.join(FIXTURE_DIRS, 'onerror.json')) as f:
            resp = json.loads(f.read())
            message = json.loads(resp['Message'])

        # send signal
        transcode_onerror.send(sender=None, message=message)

        #
        job = EncodeJob.objects.get(pk=message['jobId'])
        error_message = "3002 25319782-210b-45b2-a8a2-fb929b87d46b: The specified object could not be saved in the specified bucket because an object by that name already exists: bucket=bucket_name, key=output.mp3."

        #
        self.assertEqual(1, EncodeJob.objects.count())
        self.assertEqual('1396802241671-jkmme8', job.id)
        self.assertEqual(error_message, job.message)
        self.assertEqual(2, job.state)
    def test_transcode_onerror(self):
        """
        test for transcode_onerror signal
        """

        # assume an encode job was submitted
        item = Item.objects.create(name='Hello')

        ctype = ContentType.objects.get_for_model(item)

        job = EncodeJob()
        job.id = '1396802241671-jkmme8'
        job.content_type = ctype
        job.object_id = item.id
        job.save()

        # 
        with open(os.path.join(FIXTURE_DIRS, 'onerror.json')) as f:
            resp = json.loads(f.read())
            message = json.loads(resp['Message'])

        # send signal
        transcode_onerror.send(sender=None, message=message)

        #
        job = EncodeJob.objects.get(pk=message['jobId'])
        error_message = "3002 25319782-210b-45b2-a8a2-fb929b87d46b: The specified object could not be saved in the specified bucket because an object by that name already exists: bucket=bucket_name, key=output.mp3."
        
        #
        self.assertEqual(1, EncodeJob.objects.count())
        self.assertEqual('1396802241671-jkmme8', job.id)
        self.assertEqual(error_message, job.message)
        self.assertEqual(2, job.state)
    def test_transcode_oncomplete(self):
        """
        test for transcode_oncomplete signal
        """

        # assume an encode job was submitted
        item = Item.objects.create(name='Hello')

        ctype = ContentType.objects.get_for_model(item)

        job = EncodeJob()
        job.id = '1396802241671-jkmme8'
        job.content_type = ctype
        job.object_id = item.id
        job.save()

        # 
        with open(os.path.join(FIXTURE_DIRS, 'oncomplete.json')) as f:
            resp = json.loads(f.read())
            message = json.loads(resp['Message'])

        # send signal
        transcode_oncomplete.send(sender=None, message=message)

        #
        job = EncodeJob.objects.get(pk=message['jobId'])

        #
        self.assertEqual(1, EncodeJob.objects.count())
        self.assertEqual('1396802241671-jkmme8', job.id)
        self.assertEqual('Success', job.message)
        self.assertEqual(4, job.state)
Example #5
0
    def create_job_for_object(self, obj):
        """
        Create an EncodeJob with the same message output as the Transcoder message

        Args:
            obj(Video): Video to create a job for

        Returns:
            EncodeJob object

        """
        content_type = ContentType.objects.get_for_model(obj)
        uuid = str(uuid4())
        if not hasattr(self, "message"):
            self.message = {  # pylint:disable=attribute-defined-outside-init
                "Job": {
                    "Status": "Error",
                    "Id": uuid
                }
            }
        job = EncodeJob()
        job.id = self.message["Job"]["Id"] if "Job" in self.message else uuid
        job.message = self.message
        job.content_type = content_type
        job.object_id = obj.pk
        job.save()
        return job