Ejemplo n.º 1
0
    def test_available(self):
        factories.VideoUploadUrlFactory(public_video_id='available',
                                        expires_at=time() + 3600)
        factories.VideoUploadUrlFactory(
            public_video_id='almost_expired',
            expires_at=time() - 3000,
        )
        factories.VideoUploadUrlFactory(
            public_video_id='used',
            expires_at=time() + 3600,
            was_used=True,
        )
        factories.VideoUploadUrlFactory(
            public_video_id='expired',
            expires_at=time() - 3600,
        )

        available_video_ids = [
            u.public_video_id
            for u in models.VideoUploadUrl.objects.available()
        ]

        self.assertIn('available', available_video_ids)
        self.assertIn('almost_expired', available_video_ids)
        self.assertNotIn('used', available_video_ids)
        self.assertNotIn('expired', available_video_ids)
Ejemplo n.º 2
0
    def test_get_video_that_was_just_uploaded(self):
        factories.VideoUploadUrlFactory(public_video_id="videoid",
                                        expires_at=time() + 3600,
                                        owner=self.user)
        response = self.client.get(
            reverse("api:v1:video-detail", kwargs={"id": "videoid"}))

        self.assertEqual(200, response.status_code)
Ejemplo n.º 3
0
    def test_used_upload_urls_are_not_listed(self):
        factories.VideoUploadUrlFactory(
            public_video_id="unused",
            owner=self.user,
            expires_at=time() + 3600,
            was_used=False,
        )
        factories.VideoUploadUrlFactory(
            public_video_id="used",
            owner=self.user,
            expires_at=time() + 3600,
            was_used=True,
        )
        url = reverse("api:v1:videouploadurl-list")
        response = self.client.get(url)

        self.assertEqual(1, len(response.json()))
        self.assertEqual("unused", response.json()[0]["id"])
Ejemplo n.º 4
0
    def test_clean_upload_urls(self):
        factories.VideoUploadUrlFactory(public_video_id="available",
                                        expires_at=time(),
                                        was_used=False)
        factories.VideoUploadUrlFactory(public_video_id="expired",
                                        expires_at=time() - 7200,
                                        was_used=False)
        factories.VideoUploadUrlFactory(public_video_id="expired_used",
                                        expires_at=time() - 7200,
                                        was_used=True)
        send_task("clean_upload_urls")

        upload_url_ids = [
            url.public_video_id for url in models.VideoUploadUrl.objects.all()
        ]

        self.assertIn("available", upload_url_ids)
        self.assertIn("expired_used", upload_url_ids)
        self.assertEqual(2, len(upload_url_ids))
Ejemplo n.º 5
0
    def test_available(self):
        factories.VideoUploadUrlFactory(public_video_id="available",
                                        expires_at=time() + 3600)
        factories.VideoUploadUrlFactory(public_video_id="almost_expired",
                                        expires_at=time() - 3000)
        factories.VideoUploadUrlFactory(public_video_id="used",
                                        expires_at=time() + 3600,
                                        was_used=True)
        factories.VideoUploadUrlFactory(public_video_id="expired",
                                        expires_at=time() - 3600)

        available_video_ids = [
            u.public_video_id
            for u in models.VideoUploadUrl.objects.available()
        ]

        self.assertIn("available", available_video_ids)
        self.assertIn("almost_expired", available_video_ids)
        self.assertNotIn("used", available_video_ids)
        self.assertNotIn("expired", available_video_ids)
Ejemplo n.º 6
0
    def test_upload_url_invalidated_after_failed_upload(self):
        mock_backend = Mock(return_value=Mock(upload_video=Mock(
            side_effect=ValueError)))
        factories.VideoUploadUrlFactory(was_used=False,
                                        public_video_id="videoid",
                                        expires_at=time() + 3600)
        file_object = Mock()
        file_object.name = "Some video.mp4"
        with override_settings(PLUGIN_BACKEND=mock_backend):
            self.assertRaises(ValueError, tasks.upload_video, "videoid",
                              file_object)

        self.assertEqual(0, models.Video.objects.count())
        self.assertEqual(0, models.VideoUploadUrl.objects.available().count())
Ejemplo n.º 7
0
    def test_OPTIONS_on_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="*",
        )
        response = self.client.options(
            reverse("api:v1:video-upload",
                    kwargs={'video_id': video_upload_url.public_video_id}), )

        self.assertEqual(200, response.status_code)
        self.assertIn('Access-Control-Allow-Origin', response)
        self.assertEqual('*', response['Access-Control-Allow-Origin'])
Ejemplo n.º 8
0
    def test_send_empty_file_to_upload_url(self):
        video_upload_url = factories.VideoUploadUrlFactory(
            public_video_id='videoid',
            owner=self.user,
            expires_at=time() + 3600,
            origin="*",
        )
        response = self.client.post(
            reverse("api:v1:video-upload",
                    kwargs={'video_id': video_upload_url.public_video_id}),
            {
                'name': 'video.mp4',
                'file': StringIO('')
            },
        )

        self.assertEqual(400, response.status_code)
        self.assertEqual('*', response['Access-Control-Allow-Origin'])
        self.assertIn('file', response.json())
Ejemplo n.º 9
0
    def test_send_file_to_expired_upload_url(self):
        video_upload_url = factories.VideoUploadUrlFactory(
            public_video_id='videoid',
            owner=self.user,
            expires_at=time() - 7200,
            origin="*",
        )
        video_file = StringIO('some video content')

        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(404, response.status_code)
        self.assertNotIn('Access-Control-Allow-Origin', response)
Ejemplo n.º 10
0
    def test_send_empty_file_to_upload_url(self):
        video_upload_url = factories.VideoUploadUrlFactory(
            public_video_id="videoid",
            owner=self.user,
            expires_at=time() + 3600,
            origin="*",
        )
        response = self.client.post(
            reverse(
                "api:v1:video-upload",
                kwargs={"video_id": video_upload_url.public_video_id},
            ),
            {
                "name": "video.mp4",
                "file": StringIO("")
            },
        )

        self.assertEqual(400, response.status_code)
        self.assertEqual("*", response["Access-Control-Allow-Origin"])
        self.assertIn("file", response.json())
Ejemplo n.º 11
0
    def test_upload_video(self):
        mock_backend = Mock(return_value=Mock(
            upload_video=Mock(),
            start_transcoding=Mock(return_value=[]),
            iter_formats=Mock(return_value=[]),
        ))
        factories.VideoUploadUrlFactory(was_used=False,
                                        public_video_id="videoid",
                                        expires_at=time() + 3600)
        file_object = Mock()
        file_object.name = "Some video.mp4"
        with override_settings(PLUGIN_BACKEND=mock_backend):
            tasks.upload_video("videoid", file_object)

        self.assertEqual(1, models.Video.objects.count())
        self.assertEqual(1, models.VideoUploadUrl.objects.count())
        video = models.Video.objects.get()
        video_upload_url = models.VideoUploadUrl.objects.get()
        self.assertEqual("Some video.mp4", video.title)
        self.assertLess(10, len(video.public_thumbnail_id))
        self.assertTrue(video_upload_url.was_used)
Ejemplo n.º 12
0
    def test_send_file_to_expired_upload_url(self):
        video_upload_url = factories.VideoUploadUrlFactory(
            public_video_id="videoid",
            owner=self.user,
            expires_at=time() - 7200,
            origin="*",
        )
        video_file = StringIO("some video content")

        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(404, response.status_code)
        self.assertNotIn("Access-Control-Allow-Origin", response)
Ejemplo n.º 13
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"])