~ubuntu-branches/ubuntu/trusty/horizon/trusty-proposed

« back to all changes in this revision

Viewing changes to horizon/test/tests/base.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-12-05 14:39:15 UTC
  • mto: This revision was merged to the branch mainline in revision 61.
  • Revision ID: package-import@ubuntu.com-20131205143915-5u8q3kdxdw8e7maz
Tags: upstream-2014.1~b1
ImportĀ upstreamĀ versionĀ 2014.1~b1

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
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
26
27
 
102
103
                dash.register(panel)
103
104
 
104
105
    def _reload_urls(self):
105
 
        '''
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.
110
 
        '''
 
110
        """
111
111
        urlresolvers.clear_url_caches()
112
112
        reload(import_module(settings.ROOT_URLCONF))
113
113
        base.Horizon._urls()
116
116
class HorizonTests(BaseHorizonTests):
117
117
 
118
118
    def test_registry(self):
119
 
        """ Verify registration and autodiscovery work correctly.
 
119
        """Verify registration and autodiscovery work correctly.
120
120
 
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/")
195
195
 
 
196
    def test_panel_without_slug_fails(self):
 
197
        class InvalidPanel(horizon.Panel):
 
198
            name = 'Invalid'
 
199
 
 
200
        self.assertRaises(ImproperlyConfigured, InvalidPanel)
 
201
 
 
202
    def test_registry_without_registerable_class_attr_fails(self):
 
203
        class InvalidRegistry(base.Registry):
 
204
            pass
 
205
 
 
206
        self.assertRaises(ImproperlyConfigured, InvalidRegistry)
 
207
 
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)
211
223
 
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")
215
227
        cats.evil = True
216
228
 
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"))
221
233
 
297
309
        settings.SECURE_PROXY_SSL_HEADER = None
298
310
 
299
311
 
 
312
class GetUserHomeTests(BaseHorizonTests):
 
313
    """Test get_user_home parameters."""
 
314
 
 
315
    def setUp(self):
 
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
 
321
 
 
322
    def tearDown(self):
 
323
        settings.HORIZON_CONFIG['user_home'] = self.orig_user_home
 
324
        conf.HORIZON_CONFIG._setup()
 
325
 
 
326
    def test_using_callable(self):
 
327
        def fancy_user_fnc(user):
 
328
            return user.username.upper()
 
329
 
 
330
        settings.HORIZON_CONFIG['user_home'] = fancy_user_fnc
 
331
        conf.HORIZON_CONFIG._setup()
 
332
 
 
333
        self.assertEqual(self.test_user.username.upper(),
 
334
                               base.Horizon.get_user_home(self.test_user))
 
335
 
 
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()
 
340
 
 
341
        self.test_user.username = '<ignore>testname<ignore>'
 
342
        self.assertEqual(self.original_username,
 
343
                               base.Horizon.get_user_home(self.test_user))
 
344
 
 
345
    def test_using_url(self):
 
346
        fixed_url = "/url"
 
347
        settings.HORIZON_CONFIG['user_home'] = fixed_url
 
348
        conf.HORIZON_CONFIG._setup()
 
349
 
 
350
        self.assertEqual(fixed_url,
 
351
                         base.Horizon.get_user_home(self.test_user))
 
352
 
 
353
 
300
354
class CustomPanelTests(BaseHorizonTests):
301
355
 
302
 
    """ Test customization of dashboards and panels
 
356
    """Test customization of dashboards and panels
303
357
    using 'customization_module' to HORIZON_CONFIG.
304
358
    """
305
359
 
334
388
 
335
389
class CustomPermissionsTests(BaseHorizonTests):
336
390
 
337
 
    """ Test customization of permissions on panels
 
391
    """Test customization of permissions on panels
338
392
    using 'customization_module' to HORIZON_CONFIG.
339
393
    """
340
394