25
25
from django.contrib.auth.middleware import AuthenticationMiddleware # noqa
26
26
from django.contrib.messages.storage import default_storage # noqa
27
27
from django.core.handlers import wsgi
28
from django.core import urlresolvers
28
29
from django import http
29
30
from django.test.client import RequestFactory # noqa
30
31
from django.utils.importlib import import_module # noqa
107
110
* A full suite of test data through various attached objects and
108
111
managers (e.g. ``self.servers``, ``self.user``, etc.). See the
109
docs for :class:`~horizon.tests.test_data.utils.TestData` for more
113
:class:`~openstack_dashboard.test.test_data.utils.TestData`
114
for more information.
111
115
* The ``mox`` mocking framework via ``self.mox``.
112
116
* A set of request context data via ``self.context``.
113
117
* A ``RequestFactory`` class which supports Django's ``contrib.messages``
416
420
return sort_order[flavor.name]
423
class PluginTestCase(TestCase):
424
"""The ``PluginTestCase`` class is for use with tests which deal with the
425
pluggable dashboard and panel configuration, it takes care of backing up
426
and restoring the Horizon configuration.
429
super(PluginTestCase, self).setUp()
430
self.old_horizon_config = conf.HORIZON_CONFIG
431
conf.HORIZON_CONFIG = conf.LazySettings()
433
# Trigger discovery, registration, and URLconf generation if it
434
# hasn't happened yet.
436
# Store our original dashboards
437
self._discovered_dashboards = base.Horizon._registry.keys()
438
# Gather up and store our original panels for each dashboard
439
self._discovered_panels = {}
440
for dash in self._discovered_dashboards:
441
panels = base.Horizon._registry[dash]._registry.keys()
442
self._discovered_panels[dash] = panels
445
super(PluginTestCase, self).tearDown()
446
conf.HORIZON_CONFIG = self.old_horizon_config
447
# Destroy our singleton and re-create it.
448
base.HorizonSite._instance = None
450
base.Horizon = base.HorizonSite()
451
# Reload the convenience references to Horizon stored in __init__
452
reload(import_module("horizon"))
453
# Re-register our original dashboards and panels.
454
# This is necessary because autodiscovery only works on the first
455
# import, and calling reload introduces innumerable additional
456
# problems. Manual re-registration is the only good way for testing.
457
for dash in self._discovered_dashboards:
458
base.Horizon.register(dash)
459
for panel in self._discovered_panels[dash]:
463
def _reload_urls(self):
464
"""Clears out the URL caches, reloads the root urls module, and
465
re-triggers the autodiscovery mechanism for Horizon. Allows URLs
466
to be re-calculated after registering new dashboards. Useful
467
only for testing and should never be used on a live site.
469
urlresolvers.clear_url_caches()
470
reload(import_module(settings.ROOT_URLCONF))