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
62692891
Commit
62692891
authored
Jun 27, 2019
by
P.J. Janse van Rensburg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test search on hybrid property
parent
ecff1057
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletion
+18
-1
test_basic.py
flask_admin/tests/sqla/test_basic.py
+18
-1
No files found.
flask_admin/tests/sqla/test_basic.py
View file @
62692891
...
@@ -10,6 +10,7 @@ from flask_admin.contrib.sqla import ModelView, filters, tools
...
@@ -10,6 +10,7 @@ from flask_admin.contrib.sqla import ModelView, filters, tools
from
flask_babelex
import
Babel
from
flask_babelex
import
Babel
from
sqlalchemy.ext.hybrid
import
hybrid_property
from
sqlalchemy.ext.hybrid
import
hybrid_property
from
sqlalchemy
import
cast
from
sqlalchemy_utils
import
EmailType
,
ChoiceType
,
UUIDType
,
URLType
,
CurrencyType
,
ColorType
,
ArrowType
,
IPAddressType
from
sqlalchemy_utils
import
EmailType
,
ChoiceType
,
UUIDType
,
URLType
,
CurrencyType
,
ColorType
,
ArrowType
,
IPAddressType
from
.
import
setup
from
.
import
setup
...
@@ -1559,6 +1560,14 @@ def test_hybrid_property():
...
@@ -1559,6 +1560,14 @@ def test_hybrid_property():
def
number_of_pixels
(
self
):
def
number_of_pixels
(
self
):
return
self
.
width
*
self
.
height
return
self
.
width
*
self
.
height
@
hybrid_property
def
number_of_pixels_str
(
self
):
return
str
(
self
.
number_of_pixels
())
@
number_of_pixels_str
.
expression
def
number_of_pixels_str
(
cls
):
return
cast
(
cls
.
width
*
cls
.
height
,
db
.
String
)
db
.
create_all
()
db
.
create_all
()
db
.
session
.
add
(
Model1
(
id
=
1
,
name
=
"test_row_1"
,
width
=
25
,
height
=
25
))
db
.
session
.
add
(
Model1
(
id
=
1
,
name
=
"test_row_1"
,
width
=
25
,
height
=
25
))
...
@@ -1571,7 +1580,8 @@ def test_hybrid_property():
...
@@ -1571,7 +1580,8 @@ def test_hybrid_property():
Model1
,
db
.
session
,
Model1
,
db
.
session
,
column_default_sort
=
'number_of_pixels'
,
column_default_sort
=
'number_of_pixels'
,
column_filters
=
[
filters
.
IntGreaterFilter
(
Model1
.
number_of_pixels
,
column_filters
=
[
filters
.
IntGreaterFilter
(
Model1
.
number_of_pixels
,
'Number of Pixels'
)]
'Number of Pixels'
)],
column_searchable_list
=
[
'number_of_pixels_str'
,
]
)
)
admin
.
add_view
(
view
)
admin
.
add_view
(
view
)
...
@@ -1592,6 +1602,13 @@ def test_hybrid_property():
...
@@ -1592,6 +1602,13 @@ def test_hybrid_property():
eq_
(
data
[
0
]
.
name
,
'test_row_2'
)
eq_
(
data
[
0
]
.
name
,
'test_row_2'
)
eq_
(
data
[
1
]
.
name
,
'test_row_1'
)
eq_
(
data
[
1
]
.
name
,
'test_row_1'
)
# searching
rv
=
client
.
get
(
'/admin/model1/?search=100'
)
eq_
(
rv
.
status_code
,
200
)
data
=
rv
.
data
.
decode
(
'utf-8'
)
ok_
(
'test_row_2'
in
data
)
ok_
(
'test_row_1'
not
in
data
)
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