Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Websites UFRPE
Wagtail Videos
Commits
7324ab7e
Commit
7324ab7e
authored
Jan 22, 2021
by
Seb
Browse files
Add videochooser block + tests
parent
92dafd28
Changes
7
Hide whitespace changes
Inline
Side-by-side
tests/app/migrations/0002_testpage_video_streamfield.py
0 → 100644
View file @
7324ab7e
# Generated by Django 3.1.5 on 2021-01-21 22:54
from
django.db
import
migrations
import
wagtail.core.fields
import
wagtailvideos.blocks
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'app'
,
'0001_initial'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'testpage'
,
name
=
'video_streamfield'
,
field
=
wagtail
.
core
.
fields
.
StreamField
([(
'video'
,
wagtailvideos
.
blocks
.
VideoChooserBlock
())],
blank
=
True
),
),
]
tests/app/models.py
View file @
7324ab7e
from
__future__
import
unicode_literals
from
django.db
import
models
from
wagtail.core.models
import
Page
from
wagtail.core.fields
import
StreamField
from
wagtail.admin.edit_handlers
import
StreamFieldPanel
from
wagtailvideos.edit_handlers
import
VideoChooserPanel
from
wagtailvideos.blocks
import
VideoChooserBlock
class
TestPage
(
Page
):
video_field
=
models
.
ForeignKey
(
'wagtailvideos.Video'
,
related_name
=
'+'
,
null
=
True
,
blank
=
True
,
on_delete
=
models
.
SET_NULL
)
video_streamfield
=
StreamField
([
(
'video'
,
VideoChooserBlock
())
],
blank
=
True
)
content_panels
=
Page
.
content_panels
+
[
VideoChooserPanel
(
'video_field'
)
VideoChooserPanel
(
'video_field'
),
StreamFieldPanel
(
'video_streamfield'
),
]
tests/app/settings.py
View file @
7324ab7e
...
...
@@ -50,14 +50,13 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware'
,
'django.contrib.messages.middleware.MessageMiddleware'
,
'django.middleware.clickjacking.XFrameOptionsMiddleware'
,
'wagtail.core.middleware.SiteMiddleware'
,
]
TEMPLATES
=
[
{
'BACKEND'
:
'django.template.backends.django.DjangoTemplates'
,
'APP_DIRS'
:
True
,
'DIRS'
:
[
'tests/templates'
],
'OPTIONS'
:
{
'context_processors'
:
[
'django.contrib.auth.context_processors.auth'
,
...
...
tests/app/test_block.py
0 → 100644
View file @
7324ab7e
from
wagtail.core.models
import
Page
,
Site
from
wagtail.tests.utils
import
WagtailPageTests
from
wagtail.tests.utils.form_data
import
nested_form_data
,
streamfield
from
tests.app.models
import
TestPage
from
tests.utils
import
create_test_video_file
from
wagtailvideos.models
import
Video
class
TestVideoBlock
(
WagtailPageTests
):
def
setUp
(
self
):
super
().
setUp
()
self
.
root_page
=
Page
.
objects
.
get
(
pk
=
1
)
self
.
video
=
Video
.
objects
.
create
(
title
=
"Test Video"
,
file
=
create_test_video_file
()
)
def
test_block_admin
(
self
):
self
.
assertCanCreate
(
self
.
root_page
,
TestPage
,
nested_form_data
({
'title'
:
'VideoPage'
,
'video_streamfield'
:
streamfield
([
(
'video'
,
self
.
video
.
id
)
])
}))
def
test_block_basic_render
(
self
):
page
=
self
.
root_page
.
add_child
(
instance
=
TestPage
(
title
=
'Test'
,
slug
=
'vidtest'
,
video_streamfield
=
[
(
'video'
,
self
.
video
)
]
))
Site
.
objects
.
create
(
hostname
=
'localhost'
,
port
=
8080
,
root_page
=
page
,
site_name
=
'Test Site'
,
is_default_site
=
True
)
response
=
self
.
client
.
get
(
page
.
full_url
)
self
.
assertContains
(
response
,
self
.
video
.
video_tag
(
attrs
=
{
"controls"
:
True
}))
tests/templates/app/test_page.html
0 → 100644
View file @
7324ab7e
{% load wagtailvideos_tags %}
<h1>
{{ page.title }}
</h1>
{% if self.video_field %}
{% video self.video_field controls %}
{% endif %}
{{ self.video_streamfield }}
\ No newline at end of file
tests/test_admin_views.py
View file @
7324ab7e
from
__future__
import
unicode_literals
import
json
from
django.contrib.auth
import
get_user_model
...
...
@@ -9,10 +7,10 @@ from django.template.defaultfilters import filesizeformat
from
django.test
import
TestCase
,
override_settings
from
django.urls
import
reverse
from
mock
import
patch
from
tests.utils
import
create_test_video_file
from
wagtail.core.models
import
Collection
,
GroupCollectionPermission
from
wagtail.tests.utils
import
WagtailTestUtils
from
tests.utils
import
create_test_video_file
from
wagtailvideos.models
import
Video
...
...
wagtailvideos/blocks.py
0 → 100644
View file @
7324ab7e
from
wagtail.core.blocks
import
ChooserBlock
from
django.utils.functional
import
cached_property
class
VideoChooserBlock
(
ChooserBlock
):
@
cached_property
def
target_model
(
self
):
from
wagtailvideos.models
import
Video
return
Video
@
cached_property
def
widget
(
self
):
from
wagtailvideos.widgets
import
AdminVideoChooser
return
AdminVideoChooser
def
render_basic
(
self
,
value
,
context
=
None
):
if
value
:
return
value
.
video_tag
(
attrs
=
{
"controls"
:
True
})
else
:
return
""
class
Meta
:
icon
=
'media'
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment