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
38c7894b
Commit
38c7894b
authored
Jul 27, 2015
by
Paul Brown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add basic tests for hybrid_property
parent
08305dd0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
0 deletions
+49
-0
test_basic.py
flask_admin/tests/sqla/test_basic.py
+49
-0
No files found.
flask_admin/tests/sqla/test_basic.py
View file @
38c7894b
...
@@ -8,6 +8,8 @@ from flask_admin._compat import iteritems
...
@@ -8,6 +8,8 @@ from flask_admin._compat import iteritems
from
flask_admin.contrib.sqla
import
ModelView
,
filters
from
flask_admin.contrib.sqla
import
ModelView
,
filters
from
flask_babelex
import
Babel
from
flask_babelex
import
Babel
from
sqlalchemy.ext.hybrid
import
hybrid_property
from
.
import
setup
from
.
import
setup
from
datetime
import
datetime
,
time
,
date
from
datetime
import
datetime
,
time
,
date
...
@@ -1217,6 +1219,53 @@ def test_column_filters():
...
@@ -1217,6 +1219,53 @@ def test_column_filters():
ok_
(
'test1_val_2'
not
in
data
)
ok_
(
'test1_val_2'
not
in
data
)
def
test_hybrid_property
():
app
,
db
,
admin
=
setup
()
class
Model1
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
name
=
db
.
Column
(
db
.
String
)
width
=
db
.
Column
(
db
.
Integer
)
height
=
db
.
Column
(
db
.
Integer
)
@
hybrid_property
def
number_of_pixels
(
self
):
return
self
.
width
*
self
.
height
db
.
create_all
()
db
.
session
.
add
(
Model1
(
id
=
1
,
name
=
"test_row_1"
,
width
=
25
,
height
=
25
))
db
.
session
.
add
(
Model1
(
id
=
2
,
name
=
"test_row_2"
,
width
=
10
,
height
=
10
))
db
.
session
.
commit
()
client
=
app
.
test_client
()
view
=
CustomModelView
(
Model1
,
db
.
session
,
column_default_sort
=
'number_of_pixels'
,
column_filters
=
[
filters
.
IntGreaterFilter
(
Model1
.
number_of_pixels
,
'Number of Pixels'
)]
)
admin
.
add_view
(
view
)
# filters - hybrid_property integer - greater
rv
=
client
.
get
(
'/admin/model1/?flt0_0=600'
)
eq_
(
rv
.
status_code
,
200
)
data
=
rv
.
data
.
decode
(
'utf-8'
)
ok_
(
'test_row_1'
in
data
)
ok_
(
'test_row_2'
not
in
data
)
# sorting
rv
=
client
.
get
(
'/admin/model1/?sort=0'
)
eq_
(
rv
.
status_code
,
200
)
_
,
data
=
view
.
get_list
(
0
,
None
,
None
,
None
,
None
)
eq_
(
len
(
data
),
2
)
eq_
(
data
[
0
]
.
name
,
'test_row_2'
)
eq_
(
data
[
1
]
.
name
,
'test_row_1'
)
def
test_url_args
():
def
test_url_args
():
app
,
db
,
admin
=
setup
()
app
,
db
,
admin
=
setup
()
...
...
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