Ejemplo n.º 1
0
    def test_factory_returns_model(self):
        class NotImplementedModel(models.Model):
            class Meta:
                app_label = 'some_test_label'

        with self.assertRaises(NotImplementedError):
            factories.create(NotImplementedModel)
Ejemplo n.º 2
0
    def test_video_show_correct_default_quality(self):

        video = factories.create(
            models.Video,
            title='Vid 1',
            slug='vid-1',
            default_quality='720p',
        )
        transcoding1 = factories.create(
            models.Transcoding,
            video=video,
            quality='480p',
            type='video/webm',
            url='http://480p.webm',
        )
        transcoding2 = factories.create(
            models.Transcoding,
            video=video,
            quality='480p',
            type='video/mp4',
            url='http://480p.mp4',
        )
        transcoding3 = factories.create(
            models.Transcoding,
            video=video,
            quality='720p',
            type='video/webm',
            url='http://720p.webm',
        )
        transcoding4 = factories.create(
            models.Transcoding,
            video=video,
            quality='720p',
            type='video/mp4',
            url='http://720p.mp4',
        )

        resp: HttpResponse = self.client.get(reverse('video', args=['vid-1']))

        self.assertEqual(resp.status_code, 200)

        content: str = resp.content.decode(resp.charset)

        self.assertInHTML(
            """<video width="1280" height="720" controls="controls">
				<source src="http://720p.mp4" type='video/mp4' />
				<source src="http://720p.webm" type='video/webm' />
				You need a browser that understands HTML5 video and supports h.264 or vp8 codecs.
			</video>""",
            content,
        )

        self.assertInHTML(
            '<a href="vid-1.html?quality=480p" onclick="vidTimeInUrl(this);">480p versie</a>',
            content)

        self.assertInHTML('<strong>720p versie</strong>', content)
Ejemplo n.º 3
0
    def test_does_not_create_video_when_providing_one(self):
        transcoding = factories.create(Transcoding,
                                       quality='720p',
                                       type='video/mp4',
                                       url='http://another_url',
                                       video=factories.create(
                                           Video,
                                           slug='yet-another-video-slug'))

        self.assertEquals(Video.objects.all().count(), 1)
Ejemplo n.º 4
0
	def test_upload_and_url_cannot_both_be_filled(self):
		video = factories.create(Video)
		with self.assertRaisesMessage(IntegrityError, 'CHECK constraint failed: upload_and_url_cannot_both_be_filled'):
			Transcoding.objects.create(
				video=video,
				quality=qualities[0].name,
				type=str(transcoding_types[0]),
				url='https://some_url',
				upload=factories.create(Upload)
			)
Ejemplo n.º 5
0
    def test_can_overwrite_kwargs(self):
        transcoding = factories.create(Transcoding,
                                       quality='720p',
                                       type='video/mp4',
                                       url='http://another_url',
                                       video=factories.create(
                                           Video,
                                           slug='yet-another-video-slug'))

        self.assertEqual(transcoding.video.slug, 'yet-another-video-slug')
        self.assertEqual(transcoding.quality, '720p')
        self.assertEqual(transcoding.type, 'video/mp4')
        self.assertEqual(transcoding.url, 'http://another_url')
Ejemplo n.º 6
0
    def test_can_assign_upload(self):
        transcoding = factories.create(
            Transcoding,
            quality='720p',
            type='video/mp4',
            video=factories.create(Video, slug='yet-another-video-slug'),
            upload=factories.create(Upload,
                                    file=SimpleUploadedFile(
                                        'my_upload.txt', b'some_contents')))

        self.assertTrue(
            os.path.exists(os.path.join(self.media_root.name,
                                        'my_upload.txt')))
        with open(os.path.join(self.media_root.name, 'my_upload.txt'),
                  'rb') as f:
            self.assertEquals(f.read(), b'some_contents')
Ejemplo n.º 7
0
 def test_factory_returns_model(self):
     video = factories.create(Video)
     self.assertEqual(video.slug, 'slug-1')
     self.assertEqual(video.title, 'Title 1')
     self.assertEqual(video.description, 'Description 1')
     self.assertIsInstance(video.created_at, datetime)
     self.assertIsInstance(video.updated_at, datetime)
Ejemplo n.º 8
0
	def test_either_upload_or_url_must_be_filled(self):
		video = factories.create(Video)

		with self.assertRaisesMessage(IntegrityError, 'CHECK constraint failed: upload_or_url_is_filled'):
			Transcoding.objects.create(
				video=video,
				quality=qualities[0].name,
				type=str(transcoding_types[0]),
			)
Ejemplo n.º 9
0
 def test_upload_does_not_create_file_when_providing_upload(self):
     upload = factories.create(Upload,
                               file=SimpleUploadedFile(
                                   'my_file.txt', b'some contents'))
     self.assertEqual(upload.file.name, 'my_file.txt')
     self.assertFalse(
         os.path.exists(os.path.join(self.media_root.name,
                                     'some_file.txt')))
     self.assertTrue(
         os.path.exists(os.path.join(self.media_root.name, 'my_file.txt')))
Ejemplo n.º 10
0
    def test_factory_can_create_multiple_models(self):
        video1 = factories.create(Video)
        video2 = factories.create(Video)
        video3 = factories.create(Video)

        self.assertEqual(video1.slug, 'slug-1')
        self.assertEqual(video1.title, 'Title 1')
        self.assertEqual(video1.description, 'Description 1')
        self.assertIsInstance(video1.created_at, datetime)
        self.assertIsInstance(video1.updated_at, datetime)

        self.assertEqual(video2.slug, 'slug-2')
        self.assertEqual(video2.title, 'Title 2')
        self.assertEqual(video2.description, 'Description 2')
        self.assertIsInstance(video2.created_at, datetime)
        self.assertIsInstance(video2.updated_at, datetime)

        self.assertEqual(video3.slug, 'slug-3')
        self.assertEqual(video3.title, 'Title 3')
        self.assertEqual(video3.description, 'Description 3')
        self.assertIsInstance(video3.created_at, datetime)
        self.assertIsInstance(video3.updated_at, datetime)
Ejemplo n.º 11
0
    def test_video_uploads_shows_correctly(self):

        image = factories.create(models.Upload)
        movie = factories.create(models.Upload)

        video = factories.create(models.Video,
                                 title='Vid 1',
                                 slug='vid-1',
                                 poster=image,
                                 og_image=image)
        transcoding = factories.create(
            models.Transcoding,
            video=video,
            quality='480p',
            type='video/webm',
            upload=movie,
        )

        resp: HttpResponse = self.client.get(
            reverse('video', args=['vid-1']) + '?quality=720p')

        self.assertEqual(resp.status_code, 200)

        content: str = resp.content.decode(resp.charset)

        self.assertInHTML(
            """<video width="853" height="480" poster="{image}" controls="controls">
				<source src="{url}" type='video/webm' />
				You need a browser that understands HTML5 video and supports vp8 codecs.
			</video>""".format(url=movie.file.url, image=image.file.url),
            content,
        )

        self.assertInHTML(
            '<meta property="og:image" content="{image}" />'.format(
                image=image.file.url),
            content,
        )
Ejemplo n.º 12
0
	def test_no_duplicate_qualities_for_same_video_and_type_can_be_created(self):
		video = factories.create(Video)

		Transcoding.objects.create(
			video=video,
			quality=qualities[0].name,
			type=str(transcoding_types[0]),
			url='https://some_url',
		)

		with self.assertRaisesMessage(IntegrityError, 'UNIQUE constraint failed: transcodings.video_id, transcodings.quality, transcodings.type'):
			Transcoding.objects.create(
				video=video,
				quality=qualities[0].name,
				type=str(transcoding_types[0]),
				url='https://some_url',
			)
Ejemplo n.º 13
0
    def test_video_view_renders_properly(self):

        video = factories.create(
            models.Video,
            title='Vid 1',
            slug='vid-1',
            default_quality='480p',
        )
        transcoding1 = factories.create(
            models.Transcoding,
            video=video,
            quality='480p',
            type='video/webm',
            url='http://480p.webm',
        )
        transcoding2 = factories.create(
            models.Transcoding,
            video=video,
            quality='480p',
            type='video/mp4',
            url='http://480p.mp4',
        )
        transcoding3 = factories.create(
            models.Transcoding,
            video=video,
            quality='720p',
            type='video/webm',
            url='http://720p.webm',
        )
        transcoding4 = factories.create(
            models.Transcoding,
            video=video,
            quality='720p',
            type='video/mp4',
            url='http://720p.mp4',
        )

        resp: HttpResponse = self.client.get(reverse('video', args=['vid-1']))

        self.assertEqual(resp.status_code, 200)

        content: str = resp.content.decode(resp.charset)

        srctag = '<source src="{url}" type="{type}" />'

        self.assertInHTML(
            """<video width="853" height="480" controls="controls">
				<source src="http://480p.mp4" type='video/mp4' />
				<source src="http://480p.webm" type='video/webm' />
				You need a browser that understands HTML5 video and supports h.264 or vp8 codecs.
			</video>""",
            content,
        )

        self.assertInHTML('<title>Vid 1</title>', content)

        self.assertInHTML('<h1>Vid 1</h1>', content)

        self.assertInHTML('<p>Description 1</p>', content)

        self.assertInHTML('<strong>480p versie</strong>', content)

        self.assertInHTML(
            '<a href="vid-1.html?quality=720p" onclick="vidTimeInUrl(this);">720p versie</a>',
            content)

        self.assertInHTML(
            '<script src="static/js/video.js" type="text/javascript"></script>',
            content)
Ejemplo n.º 14
0
 def test_factory_returns_model(self):
     transcoding = factories.create(Transcoding)
     self.assertEqual(transcoding.video.slug, 'slug-1')
     self.assertEqual(transcoding.quality, '360p')
     self.assertEqual(transcoding.type, 'video/webm')
     self.assertEqual(transcoding.url, 'https://some_url')
Ejemplo n.º 15
0
 def test_model_is_created(self):
     upload = factories.create(Upload)
     self.assertEqual(upload.file.name, 'some_file.txt')
     self.assertTrue(
         os.path.exists(os.path.join(self.media_root.name,
                                     'some_file.txt')))
Ejemplo n.º 16
0
 def test_factory_runs_only_2_queries(self):
     """ Factory should only use 2 queries: one for selecting primary key, and one for inserting record """
     with self.assertNumQueries(2):
         video = factories.create(Video)