Exemplo n.º 1
0
    def test_delete_video(self):
        mock_delete_video = Mock()
        factories.VideoFactory(public_id="videoid", owner=self.user)
        with override_plugin_backend(delete_video=mock_delete_video):
            response = self.client.delete(
                reverse("api:v1:video-detail", kwargs={"id": "videoid"}))

        self.assertEqual(204, response.status_code)
        self.assertEqual(0, models.Video.objects.count())
        mock_delete_video.assert_called_once_with("videoid")
Exemplo n.º 2
0
    def test_get_subtitle(self):
        video = factories.VideoFactory(public_id='videoid', owner=self.user)
        factories.SubtitleFactory(video=video,
                                  public_id='subid',
                                  language='fr')

        with override_plugin_backend(
                subtitle_url=lambda *args: "http://sub.vtt"):
            response = self.client.get(
                reverse("api:v1:subtitle-detail", kwargs={'id': 'subid'}))

        self.assertEqual(200, response.status_code)
        subtitle = response.json()
        self.assertEqual('fr', subtitle['language'])
        self.assertEqual('subid', subtitle['id'])
        self.assertEqual('http://sub.vtt', subtitle['url'])
Exemplo n.º 3
0
    def test_get_subtitle(self):
        video = factories.VideoFactory(public_id="videoid", owner=self.user)
        factories.SubtitleFactory(video=video,
                                  public_id="subid",
                                  language="fr")

        with override_plugin_backend(
                subtitle_url=lambda *args: "http://sub.vtt"):
            response = self.client.get(
                reverse("api:v1:subtitle-detail", kwargs={"id": "subid"}))

        self.assertEqual(200, response.status_code)
        subtitle = response.json()
        self.assertEqual("fr", subtitle["language"])
        self.assertEqual("subid", subtitle["id"])
        self.assertEqual("http://sub.vtt", subtitle["url"])
Exemplo n.º 4
0
    def test_upload_subtitle_failed_upload(self, mock_logger):
        factories.VideoFactory(public_id="videoid", owner=self.user)
        url = reverse("api:v1:video-subtitles", kwargs={'id': 'videoid'})
        subfile = StringIO(self.SRT_CONTENT)

        upload_subtitle = Mock(side_effect=ValueError)
        with override_plugin_backend(upload_subtitle=upload_subtitle):
            self.assertRaises(
                ValueError,
                self.client.post,
                url,
                data={
                    'language': 'fr',
                    'name': 'sub.srt',
                    'file': subfile
                },
            )

        self.assertEqual(0, models.Subtitle.objects.count())
Exemplo n.º 5
0
    def test_cannot_modify_subtitle(self):
        video = factories.VideoFactory(public_id="videoid", owner=self.user)
        video.subtitles.create(public_id="subid", language="fr")
        url = reverse("api:v1:video-subtitles", kwargs={'id': 'videoid'})
        subfile = StringIO(self.SRT_CONTENT)

        with override_plugin_backend(upload_subtitle=lambda *args: None,
                                     subtitle_url=lambda *args: None):
            response = self.client.post(url,
                                        data={
                                            'id': 'subid',
                                            'language': 'en',
                                            'name': 'sub.srt',
                                            'file': subfile
                                        })

        # Subtitle is in fact created, not modified
        self.assertEqual(201, response.status_code)
        self.assertEqual('fr', video.subtitles.get(public_id='subid').language)
        self.assertEqual(
            'en',
            video.subtitles.exclude(public_id='subid').get().language)
Exemplo n.º 6
0
    def test_send_file_to_upload_url(self):
        self.client.logout(
        )  # upload should work even for non logged-in clients
        video_upload_url = factories.VideoUploadUrlFactory(
            public_video_id="videoid",
            owner=self.user,
            expires_at=time() + 3600,
            origin="example.com",
        )
        video_file = StringIO("some video content")

        upload_video = Mock()
        start_transcoding = Mock(return_value=[])
        create_thumbnail = Mock()
        with override_plugin_backend(
                upload_video=upload_video,
                start_transcoding=start_transcoding,
                iter_formats=Mock(return_value=[]),
                create_thumbnail=create_thumbnail,
        ):
            response = self.client.post(
                reverse(
                    "api:v1:video-upload",
                    kwargs={"video_id": video_upload_url.public_video_id},
                ),
                {
                    "name": "video.mp4",
                    "file": video_file
                },
            )

        self.assertEqual(200, response.status_code)
        self.assertEqual("example.com",
                         response["Access-Control-Allow-Origin"])
        upload_video.assert_called_once()
        create_thumbnail.assert_called_once()
        start_transcoding.assert_called_once_with("videoid")
        self.assertEqual("videoid", response.json()["id"])