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
c6198e49
Commit
c6198e49
authored
Oct 25, 2022
by
Seb
Browse files
fix tests
parent
98eb4a71
Changes
4
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
c6198e49
...
@@ -12,21 +12,22 @@ stages:
...
@@ -12,21 +12,22 @@ stages:
head
:
head
:
extends
:
.python_test
extends
:
.python_test
image
:
python:3.
8
image
:
python:3.
10
before_script
:
before_script
:
-
pip install .['testing']
-
pip install .['testing']
lts_211
:
# TODO add 4.0+ LTS once released
image
:
python:3.8
# lts_211:
extends
:
.python_test
# image: python:3.8
before_script
:
# extends: .python_test
-
pip install .['testing'] wagtail~=2.11 django~=3.1
# before_script:
# - pip install .['testing'] wagtail~=2.11 django~=3.1
lts_215
:
#
lts_215:
image
:
python:3.10
#
image: python:3.10
extends
:
.python_test
#
extends: .python_test
before_script
:
#
before_script:
-
pip install .['testing'] wagtail~=2.15 django~=4.0
#
- pip install .['testing'] wagtail~=2.15 django~=4.0
flake8
:
flake8
:
stage
:
lint
stage
:
lint
...
...
tests/app/settings.py
View file @
c6198e49
...
@@ -38,6 +38,7 @@ DATABASES = {
...
@@ -38,6 +38,7 @@ DATABASES = {
}
}
WAGTAIL_SITE_NAME
=
'Wagtail Videos'
WAGTAIL_SITE_NAME
=
'Wagtail Videos'
WAGTAILADMIN_BASE_URL
=
'http://localhost:8080'
DEBUG
=
True
DEBUG
=
True
...
...
tests/test_admin_views.py
View file @
c6198e49
...
@@ -62,7 +62,7 @@ class TestVideoAddView(TestCase, WagtailTestUtils):
...
@@ -62,7 +62,7 @@ class TestVideoAddView(TestCase, WagtailTestUtils):
# as standard, only the root collection exists and so no 'Collection' option
# as standard, only the root collection exists and so no 'Collection' option
# is displayed on the form
# is displayed on the form
self
.
assertNotContains
(
response
,
'<label
for="id_collection
">'
)
self
.
assertNotContains
(
response
,
'<label
class="w-field__label" for="id_collection" id="id_collection-label
">'
)
# Ensure the form supports file uploads
# Ensure the form supports file uploads
self
.
assertContains
(
response
,
'enctype="multipart/form-data"'
)
self
.
assertContains
(
response
,
'enctype="multipart/form-data"'
)
...
@@ -76,7 +76,7 @@ class TestVideoAddView(TestCase, WagtailTestUtils):
...
@@ -76,7 +76,7 @@ class TestVideoAddView(TestCase, WagtailTestUtils):
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertTemplateUsed
(
response
,
'wagtailvideos/videos/add.html'
)
self
.
assertTemplateUsed
(
response
,
'wagtailvideos/videos/add.html'
)
self
.
assertContains
(
response
,
'<label
for="id_collection
">'
)
self
.
assertContains
(
response
,
'<label
class="w-field__label" for="id_collection" id="id_collection-label
">'
)
self
.
assertContains
(
response
,
collection_name
)
self
.
assertContains
(
response
,
collection_name
)
def
test_add
(
self
):
def
test_add
(
self
):
...
@@ -302,18 +302,18 @@ class TestVideoChooserView(TestCase, WagtailTestUtils):
...
@@ -302,18 +302,18 @@ class TestVideoChooserView(TestCase, WagtailTestUtils):
self
.
login
()
self
.
login
()
def
get
(
self
,
params
=
{}):
def
get
(
self
,
params
=
{}):
return
self
.
client
.
get
(
reverse
(
'wagtailvideos:choose
r
'
),
params
)
return
self
.
client
.
get
(
reverse
(
'wagtailvideos
_chooser
:choose'
),
params
)
def
test_simple
(
self
):
def
test_simple
(
self
):
response
=
self
.
get
()
response
=
self
.
get
()
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
response_json
=
json
.
loads
(
response
.
content
.
decode
())
response_json
=
json
.
loads
(
response
.
content
.
decode
())
self
.
assertEqual
(
response_json
[
'step'
],
'choose
r
'
)
self
.
assertEqual
(
response_json
[
'step'
],
'choose'
)
def
test_search
(
self
):
def
test_search
(
self
):
response
=
self
.
get
({
'q'
:
"Hello"
})
response
=
self
.
get
({
'q'
:
"Hello"
})
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
context
[
'
query_string
'
],
"Hello"
)
self
.
assertEqual
(
response
.
context
[
'
search_query
'
],
"Hello"
)
def
test_pagination
(
self
):
def
test_pagination
(
self
):
pages
=
[
'0'
,
'1'
,
'-1'
,
'9999'
,
'Not a page'
]
pages
=
[
'0'
,
'1'
,
'-1'
,
'9999'
,
'Not a page'
]
...
@@ -351,13 +351,13 @@ class TestVideoChooserChosenView(TestCase, WagtailTestUtils):
...
@@ -351,13 +351,13 @@ class TestVideoChooserChosenView(TestCase, WagtailTestUtils):
)
)
def
get
(
self
,
params
=
{}):
def
get
(
self
,
params
=
{}):
return
self
.
client
.
get
(
reverse
(
'wagtailvideos
:video_
chosen'
,
args
=
(
self
.
video
.
id
,)),
params
)
return
self
.
client
.
get
(
reverse
(
'wagtailvideos
_chooser:
chosen'
,
args
=
(
self
.
video
.
id
,)),
params
)
def
test_simple
(
self
):
def
test_simple
(
self
):
response
=
self
.
get
()
response
=
self
.
get
()
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
response_json
=
json
.
loads
(
response
.
content
.
decode
())
response_json
=
json
.
loads
(
response
.
content
.
decode
())
self
.
assertEqual
(
response_json
[
'step'
],
'
video_
chosen'
)
self
.
assertEqual
(
response_json
[
'step'
],
'chosen'
)
class
TestVideoChooserUploadView
(
TestCase
,
WagtailTestUtils
):
class
TestVideoChooserUploadView
(
TestCase
,
WagtailTestUtils
):
...
@@ -365,17 +365,19 @@ class TestVideoChooserUploadView(TestCase, WagtailTestUtils):
...
@@ -365,17 +365,19 @@ class TestVideoChooserUploadView(TestCase, WagtailTestUtils):
self
.
login
()
self
.
login
()
def
get
(
self
,
params
=
{}):
def
get
(
self
,
params
=
{}):
return
self
.
client
.
get
(
reverse
(
'wagtailvideos
:
chooser
_upload
'
),
params
)
return
self
.
client
.
get
(
reverse
(
'wagtailvideos
_
chooser
:create
'
),
params
)
def
test_simple
(
self
):
def
test_simple
(
self
):
response
=
self
.
get
()
response
=
self
.
get
()
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertTemplateUsed
(
response
,
'wagtailvideos/chooser/chooser.html'
)
self
.
assertTemplateUsed
(
response
,
"wagtailadmin/generic/chooser/creation_form.html"
)
response_json
=
json
.
loads
(
response
.
content
.
decode
())
response_json
=
json
.
loads
(
response
.
content
.
decode
())
self
.
assertEqual
(
response_json
[
'
step
'
],
'chooser'
)
self
.
assertEqual
(
response_json
[
"
step
"
],
"reshow_creation_form"
)
def
test_upload
(
self
):
def
test_upload
(
self
):
response
=
self
.
client
.
post
(
reverse
(
'wagtailvideos
:
chooser
_upload
'
),
{
response
=
self
.
client
.
post
(
reverse
(
'wagtailvideos
_
chooser
:create
'
),
{
'title'
:
"Test video"
,
'title'
:
"Test video"
,
'file'
:
SimpleUploadedFile
(
'small.mp4'
,
create_test_video_file
().
read
(),
"video/mp4"
),
'file'
:
SimpleUploadedFile
(
'small.mp4'
,
create_test_video_file
().
read
(),
"video/mp4"
),
})
})
...
@@ -388,34 +390,16 @@ class TestVideoChooserUploadView(TestCase, WagtailTestUtils):
...
@@ -388,34 +390,16 @@ class TestVideoChooserUploadView(TestCase, WagtailTestUtils):
self
.
assertEqual
(
videos
.
count
(),
1
)
self
.
assertEqual
(
videos
.
count
(),
1
)
def
test_upload_no_file_selected
(
self
):
def
test_upload_no_file_selected
(
self
):
response
=
self
.
client
.
post
(
reverse
(
'wagtailvideos
:
chooser
_upload
'
),
{
response
=
self
.
client
.
post
(
reverse
(
'wagtailvideos
_
chooser
:create
'
),
{
'title'
:
"Test video"
,
'title'
:
"Test video"
,
})
})
# Shouldn't redirect anywhere
# Shouldn't redirect anywhere
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertTemplateUsed
(
response
,
'wagtail
videos/chooser/chooser
.html'
)
self
.
assertTemplateUsed
(
response
,
'wagtail
admin/generic/chooser/creation_form
.html'
)
# The form should have an error
# The form should have an error
self
.
assertFormError
(
response
,
'uploadform'
,
'file'
,
"This field is required."
)
self
.
assertFormError
(
response
,
'form'
,
'file'
,
"This field is required."
)
def
test_pagination_after_upload_form_error
(
self
):
for
i
in
range
(
0
,
20
):
Video
.
objects
.
create
(
title
=
"Test video %d"
%
i
,
file
=
create_test_video_file
(),
)
response
=
self
.
client
.
post
(
reverse
(
'wagtailvideos:chooser_upload'
),
{
'title'
:
"Test video"
,
})
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertTemplateUsed
(
response
,
'wagtailvideos/chooser/chooser.html'
)
# The re-rendered video chooser listing should be paginated
self
.
assertContains
(
response
,
"Page 1 of "
)
self
.
assertEqual
(
12
,
len
(
response
.
context
[
'videos'
]))
class
TestVideoChooserUploadViewWithLimitedPermissions
(
TestCase
,
WagtailTestUtils
):
class
TestVideoChooserUploadViewWithLimitedPermissions
(
TestCase
,
WagtailTestUtils
):
...
@@ -448,22 +432,30 @@ class TestVideoChooserUploadViewWithLimitedPermissions(TestCase, WagtailTestUtil
...
@@ -448,22 +432,30 @@ class TestVideoChooserUploadViewWithLimitedPermissions(TestCase, WagtailTestUtil
self
.
client
.
login
(
username
=
'moriarty'
,
password
=
'password'
)
self
.
client
.
login
(
username
=
'moriarty'
,
password
=
'password'
)
def
test_get
(
self
):
def
test_get
(
self
):
response
=
self
.
client
.
get
(
reverse
(
'wagtailvideos
:
chooser
_upload
'
))
response
=
self
.
client
.
get
(
reverse
(
'wagtailvideos
_
chooser
:create
'
))
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertTemplateUsed
(
response
,
'wagtailvideos/chooser/chooser.html'
)
self
.
assertTemplateUsed
(
response
,
"wagtailadmin/generic/chooser/creation_form.html"
)
# user only has access to one collection, so no 'Collection' option
# user only has access to one collection, so no 'Collection' option
# is displayed on the form
# is displayed on the form
self
.
assertNotContains
(
response
,
'<label for="id_collection">'
)
self
.
assertNotContains
(
response
,
'<label class="w-field__label" for="id_collection" id="id_collection-label">'
,
)
def
test_get_chooser
(
self
):
def
test_get_chooser
(
self
):
response
=
self
.
client
.
get
(
reverse
(
'wagtailvideos:choose
r
'
))
response
=
self
.
client
.
get
(
reverse
(
'wagtailvideos
_chooser
:choose'
))
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertTemplateUsed
(
response
,
'wagtailvideos/chooser/chooser.html'
)
self
.
assertTemplateUsed
(
response
,
'wagtailvideos/chooser/chooser.html'
)
# user only has access to one collection, so no 'Collection' option
# user only has access to one collection, so no 'Collection' option
# is displayed on the form
# is displayed on the form
self
.
assertNotContains
(
response
,
'<label for="id_collection">'
)
self
.
assertNotContains
(
response
,
'<label class="w-field__label" for="id_collection" id="id_collection-label">'
,
)
class
TestMultipleVideoUploader
(
TestCase
,
WagtailTestUtils
):
class
TestMultipleVideoUploader
(
TestCase
,
WagtailTestUtils
):
...
...
wagtailvideos/urls.py
View file @
c6198e49
...
@@ -3,6 +3,7 @@ from django.urls import path, re_path
...
@@ -3,6 +3,7 @@ from django.urls import path, re_path
from
wagtailvideos.views
import
multiple
,
videos
from
wagtailvideos.views
import
multiple
,
videos
app_name
=
'wagtailvideos'
app_name
=
'wagtailvideos'
urlpatterns
=
[
urlpatterns
=
[
path
(
'add/'
,
videos
.
add
,
name
=
'add'
),
path
(
'add/'
,
videos
.
add
,
name
=
'add'
),
re_path
(
r
'^usage/(\d+)/$'
,
videos
.
usage
,
name
=
'video_usage'
),
re_path
(
r
'^usage/(\d+)/$'
,
videos
.
usage
,
name
=
'video_usage'
),
...
...
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