Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
d8ee980d
Commit
d8ee980d
authored
Sep 11, 2014
by
Alex Pyrgiotis
Browse files
admin: Add tests for default catalog view
parent
2b7c40a0
Changes
2
Hide whitespace changes
Inline
Side-by-side
snf-admin-app/synnefo_admin/admin/tests/utils.py
View file @
d8ee980d
...
...
@@ -14,14 +14,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#import logging
import
unittest
import
sys
from
django.core
import
mail
from
django.conf
import
settings
from
synnefo.db
import
models_factory
as
mf
from
astakos.im
import
settings
as
astakos_settings
from
snf_django.lib.api
import
faults
from
snf_django.utils.testing
import
override_settings
from
synnefo_admin
import
admin_settings
from
synnefo_admin.admin
import
views
...
...
@@ -53,6 +55,11 @@ class MockRequest(object):
self
.
POST
.
update
(
content
)
def
reload_settings
():
"""Reload admin settings after a Django setting has changed."""
reload
(
sys
.
modules
[
'synnefo_admin.admin_settings'
])
class
TestAdminUtilsUnit
(
unittest
.
TestCase
):
"""Unit test suite for admin utility functions."""
...
...
@@ -145,6 +152,19 @@ class TestAdminUtilsUnit(unittest.TestCase):
verify_sent_email
(
request
,
mail
.
outbox
[
1
])
self
.
assertEqual
(
default_sender
,
astakos_settings
.
SERVER_EMAIL
)
def
test_default_view
(
self
):
"""Test if the default_view() function works as expected."""
self
.
assertEqual
(
utils
.
default_view
(),
'user'
)
with
override_settings
(
settings
,
ADMIN_VIEWS_ORDER
=
[]):
reload_settings
()
self
.
assertEqual
(
utils
.
default_view
(),
None
)
with
override_settings
(
settings
,
ADMIN_VIEWS_ORDER
=
[
'one'
,
'two'
]):
reload_settings
()
self
.
assertEqual
(
utils
.
default_view
(),
'one'
)
reload_settings
()
class
TestAdminUtilsIntegration
(
AdminTestCase
):
...
...
snf-admin-app/synnefo_admin/admin/tests/views.py
View file @
d8ee980d
...
...
@@ -13,7 +13,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
logging
import
mock
import
unittest
...
...
@@ -44,15 +43,19 @@ class TestAdminViewsUnit(unittest.TestCase):
def
test_import_module_fail
(
self
):
"""Test if importing malformed view modules fails properly."""
gib
=
gibberish
()
with
self
.
assertRaises
(
AdminHttp404
)
as
cm1
:
views
.
get_view_module_or_404
(
gib
)
views
.
get_view_module_or_404
(
None
)
self
.
assertEqual
(
cm1
.
exception
.
message
,
"No category provided."
)
gib
=
gibberish
()
with
self
.
assertRaises
(
AdminHttp404
)
as
cm2
:
views
.
get_view_module_or_404
(
gib
)
with
self
.
assertRaises
(
AdminHttp404
)
as
cm3
:
views
.
get_json_view_or_404
(
gib
)
self
.
assertEqual
(
cm1
.
exception
.
message
,
"No category found with this name: %s"
%
gib
)
self
.
assertEqual
(
cm2
.
exception
.
message
,
"No category found with this name: %s"
%
gib
)
self
.
assertEqual
(
cm3
.
exception
.
message
,
"No category found with this name: %s"
%
gib
)
@
mock
.
patch
(
"astakosclient.AstakosClient"
,
new
=
AstakosClientMock
)
...
...
@@ -107,7 +110,8 @@ class TestAdminViewsIntegration(django.test.TestCase):
user_token
=
"0001"
)
self
.
assertEqual
(
r
.
status_code
,
404
)
@
for_all_views
(
views
=
[
'home'
,
'logout'
,
'charts'
,
'stats'
,
'actions'
])
@
for_all_views
(
views
=
[
'default'
,
'home'
,
'logout'
,
'charts'
,
'stats'
,
'actions'
])
def
test_enabled_setting_for_other_views
(
self
):
"""Test if the ADMIN_ENABLED setting is respected by the rest views."""
admin_settings
.
ADMIN_ENABLED
=
False
...
...
@@ -139,7 +143,8 @@ class TestAdminViewsIntegration(django.test.TestCase):
user_token
=
"0001"
)
self
.
assertEqual
(
r
.
status_code
,
404
)
@
for_all_views
(
views
=
[
'home'
,
'logout'
,
'charts'
,
'stats'
,
'actions'
])
@
for_all_views
(
views
=
[
'default'
,
'home'
,
'logout'
,
'charts'
,
'stats'
,
'actions'
])
def
test_404_in_other_views
(
self
):
"""Test if authorized users get 404 in all other views."""
r
=
self
.
client
.
get
(
reverse
(
'admin-%s'
%
self
.
current_view
)
+
'/'
+
...
...
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