Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
4742a1c2
Commit
4742a1c2
authored
Aug 05, 2013
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Automatic image resizing support
parent
590b8305
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
+33
-0
test_form_upload.py
flask_admin/tests/test_form_upload.py
+33
-0
No files found.
flask_admin/tests/test_form_upload.py
View file @
4742a1c2
...
...
@@ -94,6 +94,7 @@ def test_image_upload_field():
safe_delete
(
path
,
'test1_thumb.jpg'
)
safe_delete
(
path
,
'test2.png'
)
safe_delete
(
path
,
'test2_thumb.jpg'
)
safe_delete
(
path
,
'test1.jpg'
)
class
TestForm
(
form
.
BaseForm
):
upload
=
form
.
ImageUploadField
(
'Upload'
,
...
...
@@ -103,6 +104,11 @@ def test_image_upload_field():
class
TestNoResizeForm
(
form
.
BaseForm
):
upload
=
form
.
ImageUploadField
(
'Upload'
,
base_path
=
path
,
endpoint
=
'test'
)
class
TestAutoResizeForm
(
form
.
BaseForm
):
upload
=
form
.
ImageUploadField
(
'Upload'
,
base_path
=
path
,
max_size
=
(
64
,
64
,
True
))
class
Dummy
(
object
):
pass
...
...
@@ -170,6 +176,33 @@ def test_image_upload_field():
ok_
(
op
.
exists
(
op
.
join
(
path
,
'test1.png'
)))
ok_
(
not
op
.
exists
(
op
.
join
(
path
,
'test1_thumb.jpg'
)))
# Check upload, auto-resize
filename
=
op
.
join
(
op
.
dirname
(
__file__
),
'data'
,
'copyleft.png'
)
with
open
(
filename
,
'rb'
)
as
fp
:
with
app
.
test_request_context
(
method
=
'POST'
,
data
=
{
'upload'
:
(
fp
,
'test1.png'
)}):
my_form
=
TestAutoResizeForm
(
helpers
.
get_form_data
())
ok_
(
my_form
.
validate
())
my_form
.
populate_obj
(
dummy
)
eq_
(
dummy
.
upload
,
'test1.png'
)
ok_
(
op
.
exists
(
op
.
join
(
path
,
'test1.png'
)))
filename
=
op
.
join
(
op
.
dirname
(
__file__
),
'data'
,
'copyleft.tiff'
)
with
open
(
filename
,
'rb'
)
as
fp
:
with
app
.
test_request_context
(
method
=
'POST'
,
data
=
{
'upload'
:
(
fp
,
'test1.tiff'
)}):
my_form
=
TestAutoResizeForm
(
helpers
.
get_form_data
())
ok_
(
my_form
.
validate
())
my_form
.
populate_obj
(
dummy
)
eq_
(
dummy
.
upload
,
'test1.jpg'
)
ok_
(
op
.
exists
(
op
.
join
(
path
,
'test1.jpg'
)))
def
test_relative_path
():
app
=
Flask
(
__name__
)
...
...
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