Skip to content

Commit

Permalink
Some tests and migration rangling
Browse files Browse the repository at this point in the history
  • Loading branch information
seb-b committed Jan 29, 2021
1 parent f4b2a75 commit df2262e
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 24 deletions.
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------
Expand Down
3 changes: 2 additions & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
'wagtail.contrib.styleguide',
]

WAGTAILVIDEOS_VIDEO_MODEL = 'app.CustomVideoModel'
WAGTAILVIDEOS_VIDEO_MODEL = 'app.CustomVideoModel'
WAGTAIL_USAGE_COUNT_ENABLED = True
7 changes: 3 additions & 4 deletions tests/app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 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
Expand All @@ -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 = [
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Meta:

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())
Expand Down
4 changes: 4 additions & 0 deletions tests/small.vtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
WEBVTT
00:00:03.000 --> 00:00:04.000
Weapon of mass destruction
7 changes: 1 addition & 6 deletions tests/test_admin_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,6 @@ def test_edit(self):
'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")
Expand All @@ -254,9 +251,6 @@ def test_edit_with_new_video_file(self):
'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)
Expand Down Expand Up @@ -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()

Expand Down
15 changes: 13 additions & 2 deletions tests/test_template_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

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):
Expand Down Expand Up @@ -33,3 +33,14 @@ def test_bad_video(self):
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))
7 changes: 5 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import os

import tests
Expand All @@ -9,3 +7,8 @@
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')
16 changes: 10 additions & 6 deletions wagtailvideos/migrations/0011_tracklisting_videotrack.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion wagtailvideos/templates/wagtailvideos/videos/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit df2262e

Please sign in to comment.