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
b68c83d0
Commit
b68c83d0
authored
Jul 11, 2016
by
Seb
Browse files
Missing tests from add view
parent
a0fc6b04
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/test_admin_views.py
View file @
b68c83d0
from
django.core.files.uploadedfile
import
SimpleUploadedFile
from
django.core.urlresolvers
import
reverse
from
django.template.defaultfilters
import
filesizeformat
from
django.test
import
TestCase
,
override_settings
from
wagtail.tests.utils
import
WagtailTestUtils
from
wagtail.wagtailcore.models
import
Collection
...
...
@@ -110,6 +111,49 @@ class TestVidoAddView(TestCase, WagtailTestUtils):
# The form should have an error
self
.
assertFormError
(
response
,
'form'
,
'file'
,
"This field is required."
)
@
override_settings
(
WAGTAILVIDEOS_MAX_UPLOAD_SIZE
=
1
)
def
test_add_too_large_file
(
self
):
video_file
=
create_test_video_file
()
response
=
self
.
post
({
'title'
:
"Test image"
,
'file'
:
SimpleUploadedFile
(
'small.mp4'
,
video_file
.
read
(),
"video/mp4"
),
})
# Shouldn't redirect anywhere
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertTemplateUsed
(
response
,
'wagtailvideos/videos/add.html'
)
# The form should have an error
self
.
assertFormError
(
response
,
'form'
,
'file'
,
"This file is too big ({file_size}). Maximum filesize {max_file_size}."
.
format
(
file_size
=
filesizeformat
(
video_file
.
size
),
max_file_size
=
filesizeformat
(
1
),
)
)
def
test_add_with_collections
(
self
):
root_collection
=
Collection
.
get_first_root_node
()
evil_plans_collection
=
root_collection
.
add_child
(
name
=
"Evil plans"
)
response
=
self
.
post
({
'title'
:
"Test video"
,
'file'
:
SimpleUploadedFile
(
'small.mp4'
,
create_test_video_file
().
read
(),
"video/mp4"
),
'collection'
:
evil_plans_collection
.
id
,
})
# Should redirect back to index
self
.
assertRedirects
(
response
,
reverse
(
'wagtailvideos:index'
))
# Check that the image was created
videos
=
Video
.
objects
.
filter
(
title
=
"Test video"
)
self
.
assertEqual
(
videos
.
count
(),
1
)
# Test that it was placed in the Evil Plans collection
video
=
videos
.
first
()
self
.
assertEqual
(
video
.
collection
,
evil_plans_collection
)
class
TestVideoEditView
(
TestCase
,
WagtailTestUtils
):
def
setUp
(
self
):
...
...
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