22
22
from django.conf import settings # noqa
23
23
from django.contrib.auth.models import User # noqa
24
from django.core.exceptions import ImproperlyConfigured # noqa
24
25
from django.core import urlresolvers
25
26
from django.utils.importlib import import_module # noqa
102
103
dash.register(panel)
104
105
def _reload_urls(self):
106
Clears out the URL caches, reloads the root urls module, and
106
"""Clears out the URL caches, reloads the root urls module, and
107
107
re-triggers the autodiscovery mechanism for Horizon. Allows URLs
108
108
to be re-calculated after registering new dashboards. Useful
109
109
only for testing and should never be used on a live site.
111
111
urlresolvers.clear_url_caches()
112
112
reload(import_module(settings.ROOT_URLCONF))
113
113
base.Horizon._urls()
116
116
class HorizonTests(BaseHorizonTests):
118
118
def test_registry(self):
119
""" Verify registration and autodiscovery work correctly.
119
"""Verify registration and autodiscovery work correctly.
121
121
Please note that this implicitly tests that autodiscovery works
122
122
by virtue of the fact that the dashboards listed in
193
193
self.assertEqual(tigers._registered_with, cats)
194
194
self.assertEqual(tigers.get_absolute_url(), "/cats/tigers/")
196
def test_panel_without_slug_fails(self):
197
class InvalidPanel(horizon.Panel):
200
self.assertRaises(ImproperlyConfigured, InvalidPanel)
202
def test_registry_without_registerable_class_attr_fails(self):
203
class InvalidRegistry(base.Registry):
206
self.assertRaises(ImproperlyConfigured, InvalidRegistry)
196
208
def test_index_url_name(self):
197
209
cats = horizon.get_dashboard("cats")
198
210
tigers = cats.get_panel("tigers")
210
222
reversed(urlpatterns)
212
224
def test_horizon_test_isolation_1(self):
213
""" Isolation Test Part 1: sets a value. """
225
"""Isolation Test Part 1: sets a value."""
214
226
cats = horizon.get_dashboard("cats")
217
229
def test_horizon_test_isolation_2(self):
218
""" Isolation Test Part 2: The value set in part 1 should be gone. """
230
"""Isolation Test Part 2: The value set in part 1 should be gone."""
219
231
cats = horizon.get_dashboard("cats")
220
232
self.assertFalse(hasattr(cats, "evil"))
297
309
settings.SECURE_PROXY_SSL_HEADER = None
312
class GetUserHomeTests(BaseHorizonTests):
313
"""Test get_user_home parameters."""
316
self.orig_user_home = settings.HORIZON_CONFIG['user_home']
317
super(BaseHorizonTests, self).setUp()
318
self.original_username = "testname"
319
self.test_user = User()
320
self.test_user.username = self.original_username
323
settings.HORIZON_CONFIG['user_home'] = self.orig_user_home
324
conf.HORIZON_CONFIG._setup()
326
def test_using_callable(self):
327
def fancy_user_fnc(user):
328
return user.username.upper()
330
settings.HORIZON_CONFIG['user_home'] = fancy_user_fnc
331
conf.HORIZON_CONFIG._setup()
333
self.assertEqual(self.test_user.username.upper(),
334
base.Horizon.get_user_home(self.test_user))
336
def test_using_module_function(self):
337
module_func = 'django.utils.html.strip_tags'
338
settings.HORIZON_CONFIG['user_home'] = module_func
339
conf.HORIZON_CONFIG._setup()
341
self.test_user.username = '<ignore>testname<ignore>'
342
self.assertEqual(self.original_username,
343
base.Horizon.get_user_home(self.test_user))
345
def test_using_url(self):
347
settings.HORIZON_CONFIG['user_home'] = fixed_url
348
conf.HORIZON_CONFIG._setup()
350
self.assertEqual(fixed_url,
351
base.Horizon.get_user_home(self.test_user))
300
354
class CustomPanelTests(BaseHorizonTests):
302
""" Test customization of dashboards and panels
356
"""Test customization of dashboards and panels
303
357
using 'customization_module' to HORIZON_CONFIG.