Commit df2262e4 authored by Seb's avatar Seb
Browse files

Some tests and migration rangling

parent f4b2a75a
......@@ -142,7 +142,8 @@ Same as Wagtail Images, a custom model can be used to replace the built in Video
Video text tracks:
~~~~~~~~~~~~~~~~~~
To enable the uploading and displaying of subtitles or captions you'll need to add ``wagtail.contrib.modeladmin`` to your installed apps.
To enable the uploading and displaying of VTT tracks (e.g. subtitles, captions) you'll need to add ``wagtail.contrib.modeladmin`` to your installed apps.
Once added, there will be an new area in the admin for attaching VTT files to videos with associaled metadata.
Future features
---------------
......
......@@ -11,4 +11,5 @@ INSTALLED_APPS += [
'wagtail.contrib.styleguide',
]
WAGTAILVIDEOS_VIDEO_MODEL = 'app.CustomVideoModel'
\ No newline at end of file
WAGTAILVIDEOS_VIDEO_MODEL = 'app.CustomVideoModel'
WAGTAIL_USAGE_COUNT_ENABLED = True
# Generated by Django 2.2.17 on 2021-01-29 03:21
# Generated by Django 2.2.17 on 2021-01-29 05:03
from django.conf import settings
from django.db import migrations, models
......@@ -17,10 +17,9 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('wagtailcore', '0059_apply_collection_ordering'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('wagtailvideos', '0010_video_ordering'),
('taggit', '0003_taggeditem_add_unique_index'),
('wagtailcore', '0059_apply_collection_ordering'),
]
operations = [
......@@ -50,7 +49,7 @@ class Migration(migrations.Migration):
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
('video_streamfield', wagtail.core.fields.StreamField([('video', wagtailvideos.blocks.VideoChooserBlock())], blank=True)),
('video_field', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailvideos.Video')),
('video_field', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='app.CustomVideoModel')),
],
options={
'abstract': False,
......
......@@ -33,7 +33,7 @@ class CustomVideoTranscode(AbstractVideoTranscode):
class TestPage(Page):
video_field = models.ForeignKey(
'wagtailvideos.Video', related_name='+', null=True, blank=True, on_delete=models.SET_NULL)
CustomVideoModel, related_name='+', null=True, blank=True, on_delete=models.SET_NULL)
video_streamfield = StreamField([
('video', VideoChooserBlock())
......
WEBVTT
00:00:03.000 --> 00:00:04.000
Weapon of mass destruction
\ No newline at end of file
......@@ -235,9 +235,6 @@ class TestVideoEditView(TestCase, WagtailTestUtils):
'title': "Edited",
})
# Should redirect back to index
self.assertRedirects(response, reverse('wagtailvideos:index'))
# Check that the video was edited
video = Video.objects.get(id=self.video.id)
self.assertEqual(video.title, "Edited")
......@@ -254,9 +251,6 @@ class TestVideoEditView(TestCase, WagtailTestUtils):
'file': SimpleUploadedFile('new.mp4', new_file.read(), "video/mp4"),
})
# Should redirect back to index
self.assertRedirects(response, reverse('wagtailvideos:index'))
# Check that the video file size changed (assume it changed to the correct value)
video = Video.objects.get(id=self.video.id)
self.assertNotEqual(video.file_size, 100000)
......@@ -476,6 +470,7 @@ class TestMultipleVideoUploader(TestCase, WagtailTestUtils):
"""
This tests the multiple video upload views located in wagtailvideos/views/multiple.py
"""
def setUp(self):
self.login()
......
......@@ -2,9 +2,9 @@ from __future__ import unicode_literals
from django.template import Context, Template, TemplateSyntaxError
from django.test import TestCase
from tests.utils import create_test_video_file
from tests.utils import create_test_video_file, create_test_vtt_file
from wagtailvideos.models import Video
from wagtailvideos.models import Video, TrackListing, VideoTrack
class TestVideoTag(TestCase):
......@@ -33,3 +33,14 @@ class TestVideoTag(TestCase):
self.render_video_tag(None)
except TemplateSyntaxError as e:
self.assertEqual(str(e), 'video tag requires a Video object as the first parameter')
def test_render_tracks(self):
listing = TrackListing.objects.create(video=self.video)
track = VideoTrack.objects.create(
listing=listing,
file=create_test_vtt_file(),
label='Test subtitles',
kind='subtitles',
language='en',
)
self.assertInHTML(track.track_tag(), self.render_video_tag(self.video))
from __future__ import unicode_literals
import os
import tests
......@@ -9,3 +7,8 @@ from django.core.files import File
def create_test_video_file():
video_file = open(os.path.join(tests.__path__[0], 'small.mp4'), 'rb')
return File(video_file, name='small.mp4')
def create_test_vtt_file():
vtt_file = open(os.path.join(tests.__path__[0], 'small.vtt'), 'rb')
return File(vtt_file, name='small.vtt')
......@@ -65,7 +65,8 @@
<dt>{% trans "Duration" %}</dt>
<dd>{{ video.formatted_duration }}</dd>
{% endif %}
{% if usage_count_enabled %}
{% usage_count_enabled as uc_enabled %}
{% if uc_enabled %}
<dt>{% trans "Usage" %}</dt>
<dd>
<a href="{{ video.usage_url }}">{% blocktrans count usage_count=video.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment