test_video_uploads_shows_correctly

This commit is contained in:
2020-05-08 22:32:08 +02:00
parent f8a3151672
commit 8ace8d3312
2 changed files with 51 additions and 10 deletions

View File

@@ -18,17 +18,16 @@ def create(model: Type[T], **kwargs) -> T:
if model is models.Transcoding:
video = create(models.Video, title='Title', slug='slug', description='Description') \
if 'video' not in kwargs else None
return models.Transcoding.objects.create(
**{
**dict(
defaults = dict(
video=video,
quality=models.qualities[0].name,
type=str(models.transcoding_types[0]),
url='https://some_url',
),
**kwargs
}
)
if 'upload' not in kwargs:
# only URL if no upload for they are multually exclusive
defaults['url'] = 'https://some_url'
return models.Transcoding.objects.create(**{**defaults, **kwargs})
if model is models.Upload:
return _upload(**kwargs)

View File

@@ -203,3 +203,45 @@ class VideoTestCase(TestCase):
)
self.assertInHTML('<strong>720p versie</strong>', content)
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,
)