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
42ab88dc
Commit
42ab88dc
authored
Mar 31, 2012
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated tests.
parent
cdccdcc7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
122 additions
and
7 deletions
+122
-7
base.py
flask_adminex/base.py
+1
-1
mock.py
tests/mock.py
+21
-1
mock.html
tests/templates/mock.html
+1
-0
test_base.py
tests/test_base.py
+99
-5
No files found.
flask_adminex/base.py
View file @
42ab88dc
...
@@ -288,7 +288,7 @@ class Admin(object):
...
@@ -288,7 +288,7 @@ class Admin(object):
self
.
url
=
url
self
.
url
=
url
if
index_view
is
None
:
if
index_view
is
None
:
index_view
=
AdminIndexView
()
index_view
=
AdminIndexView
(
url
=
self
.
url
)
self
.
app
=
app
self
.
app
=
app
self
.
index_view
=
index_view
self
.
index_view
=
index_view
...
...
tests/mock.py
View file @
42ab88dc
...
@@ -2,6 +2,26 @@ from flask.ext.adminex import base
...
@@ -2,6 +2,26 @@ from flask.ext.adminex import base
class
MockView
(
base
.
BaseView
):
class
MockView
(
base
.
BaseView
):
# Various properties
allow_call
=
True
allow_access
=
True
@
base
.
expose
(
'/'
)
@
base
.
expose
(
'/'
)
def
index
(
self
):
def
index
(
self
):
return
None
return
'Success!'
@
base
.
expose
(
'/test/'
)
def
test
(
self
):
return
self
.
render
(
'mock.html'
)
def
_handle_view
(
self
,
name
,
**
kwargs
):
if
self
.
allow_call
:
return
super
(
MockView
,
self
)
.
_handle_view
(
name
,
**
kwargs
)
else
:
return
'Failure!'
def
is_accessible
(
self
):
if
self
.
allow_access
:
return
super
(
MockView
,
self
)
.
is_accessible
()
else
:
return
False
tests/templates/mock.html
0 → 100644
View file @
42ab88dc
{% if admin_view %}Success!{% else %}Failure{% endif %}
\ No newline at end of file
tests/test_base.py
View file @
42ab88dc
from
nose.tools
import
ok_
,
eq_
from
nose.tools
import
ok_
,
eq_
,
raises
from
flask
import
Flask
from
flask
import
Flask
from
flask.ext.adminex
import
base
from
flask.ext.adminex
import
base
...
@@ -37,6 +37,17 @@ def test_base_registration():
...
@@ -37,6 +37,17 @@ def test_base_registration():
ok_
(
admin
.
index_view
.
blueprint
is
not
None
)
ok_
(
admin
.
index_view
.
blueprint
is
not
None
)
def
test_admin_customizations
():
app
=
Flask
(
__name__
)
admin
=
base
.
Admin
(
app
,
name
=
'Test'
,
url
=
'/foobar'
)
eq_
(
admin
.
name
,
'Test'
)
eq_
(
admin
.
url
,
'/foobar'
)
client
=
app
.
test_client
()
rv
=
client
.
get
(
'/foobar/'
)
eq_
(
rv
.
status_code
,
200
)
def
test_baseview_registration
():
def
test_baseview_registration
():
admin
=
base
.
Admin
()
admin
=
base
.
Admin
()
...
@@ -51,7 +62,6 @@ def test_baseview_registration():
...
@@ -51,7 +62,6 @@ def test_baseview_registration():
eq_
(
view
.
endpoint
,
'mockview'
)
eq_
(
view
.
endpoint
,
'mockview'
)
eq_
(
view
.
url
,
'/admin/mockview'
)
eq_
(
view
.
url
,
'/admin/mockview'
)
eq_
(
view
.
name
,
'Mock View'
)
eq_
(
view
.
name
,
'Mock View'
)
eq_
(
view
.
_urls
,
[(
'/'
,
'index'
,
(
'GET'
,))])
# Verify generated blueprint properties
# Verify generated blueprint properties
eq_
(
bp
.
name
,
view
.
endpoint
)
eq_
(
bp
.
name
,
view
.
endpoint
)
...
@@ -76,11 +86,95 @@ def test_baseview_registration():
...
@@ -76,11 +86,95 @@ def test_baseview_registration():
eq_
(
view
.
url
,
'/test/test'
)
eq_
(
view
.
url
,
'/test/test'
)
def
verify_baseview_urls
():
def
test_baseview_urls
():
app
=
Flask
(
__name__
)
admin
=
base
.
Admin
(
app
)
view
=
MockView
()
admin
.
add_view
(
view
)
eq_
(
len
(
view
.
_urls
),
2
)
@
raises
(
Exception
)
def
test_no_default
():
app
=
Flask
(
__name__
)
admin
=
base
.
Admin
(
app
)
admin
.
add_view
(
base
.
BaseView
())
def
test_call
():
app
=
Flask
(
__name__
)
admin
=
base
.
Admin
(
app
)
view
=
MockView
()
admin
.
add_view
(
view
)
client
=
app
.
test_client
()
rv
=
client
.
get
(
'/admin/'
)
eq_
(
rv
.
status_code
,
200
)
rv
=
client
.
get
(
'/admin/mockview/'
)
eq_
(
rv
.
data
,
'Success!'
)
rv
=
client
.
get
(
'/admin/mockview/test/'
)
eq_
(
rv
.
data
,
'Success!'
)
# Check authentication failure
view
.
allow_call
=
False
rv
=
client
.
get
(
'/admin/mockview/'
)
eq_
(
rv
.
data
,
'Failure!'
)
def
test_permissions
():
app
=
Flask
(
__name__
)
admin
=
base
.
Admin
(
app
)
view
=
MockView
()
admin
.
add_view
(
view
)
client
=
app
.
test_client
()
view
.
allow_access
=
False
rv
=
client
.
get
(
'/admin/mockview/'
)
eq_
(
rv
.
status_code
,
403
)
def
test_submenu
():
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
admin
=
base
.
Admin
(
app
)
admin
=
base
.
Admin
(
app
)
admin
.
add_view
(
MockView
(
name
=
'Test 1'
,
category
=
'Test'
,
endpoint
=
'test1'
))
view
=
Dummy
()
# Second view is not normally accessible
view
=
MockView
(
name
=
'Test 2'
,
category
=
'Test'
,
endpoint
=
'test2'
)
view
.
allow_access
=
False
admin
.
add_view
(
view
)
admin
.
add_view
(
view
)
eq_
(
len
(
view
.
_urls
,
1
))
ok_
(
'Test'
in
admin
.
_menu_categories
)
eq_
(
len
(
admin
.
_menu
),
2
)
eq_
(
admin
.
_menu
[
1
]
.
name
,
'Test'
)
eq_
(
len
(
admin
.
_menu
[
1
]
.
_children
),
2
)
# Categories don't have URLs and they're not accessible
eq_
(
admin
.
_menu
[
1
]
.
get_url
(),
None
)
eq_
(
admin
.
_menu
[
1
]
.
is_accessible
(),
False
)
eq_
(
len
(
admin
.
_menu
[
1
]
.
get_children
()),
1
)
ok_
(
repr
(
admin
.
_menu
[
1
])
.
startswith
(
'MenuItem '
))
def
test_delayed_init
():
app
=
Flask
(
__name__
)
admin
=
base
.
Admin
()
admin
.
add_view
(
MockView
())
admin
.
init_app
(
app
)
client
=
app
.
test_client
()
rv
=
client
.
get
(
'/admin/mockview/'
)
eq_
(
rv
.
data
,
'Success!'
)
@
raises
(
Exception
)
def
test_double_init
():
app
=
Flask
(
__name__
)
admin
=
base
.
Admin
(
app
)
admin
.
init_app
(
app
)
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