Commit d8ee980d authored by Alex Pyrgiotis's avatar Alex Pyrgiotis

admin: Add tests for default catalog view

parent 2b7c40a0
......@@ -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):
......
......@@ -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) + '/' +
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment