示例#1
0
    def test_registry(self):
        """Verify registration and autodiscovery work correctly.

        Please note that this implicitly tests that autodiscovery works
        by virtue of the fact that the dashboards listed in
        ``settings.INSTALLED_APPS`` are loaded from the start.
        """
        # Registration
        self.assertEqual(2, len(base.Horizon._registry))
        horizon.register(MyDash)
        self.assertEqual(3, len(base.Horizon._registry))
        with self.assertRaises(ValueError):
            horizon.register(MyPanel)
        with self.assertRaises(ValueError):
            horizon.register("MyPanel")

        # Retrieval
        my_dash_instance_by_name = horizon.get_dashboard("mydash")
        self.assertIsInstance(my_dash_instance_by_name, MyDash)
        my_dash_instance_by_class = horizon.get_dashboard(MyDash)
        self.assertEqual(my_dash_instance_by_name, my_dash_instance_by_class)
        with self.assertRaises(base.NotRegistered):
            horizon.get_dashboard("fake")
        self.assertQuerysetEqual(horizon.get_dashboards(),
                                 ['<Dashboard: cats>',
                                  '<Dashboard: dogs>',
                                  '<Dashboard: mydash>'])

        # Removal
        self.assertEqual(3, len(base.Horizon._registry))
        horizon.unregister(MyDash)
        self.assertEqual(2, len(base.Horizon._registry))
        with self.assertRaises(base.NotRegistered):
            horizon.get_dashboard(MyDash)
示例#2
0
    def test_registry(self):
        """Verify registration and autodiscovery work correctly.

        Please note that this implicitly tests that autodiscovery works
        by virtue of the fact that the dashboards listed in
        ``settings.INSTALLED_APPS`` are loaded from the start.
        """
        # Registration
        self.assertEqual(2, len(base.Horizon._registry))
        horizon.register(MyDash)
        self.assertEqual(3, len(base.Horizon._registry))
        with self.assertRaises(ValueError):
            horizon.register(MyPanel)
        with self.assertRaises(ValueError):
            horizon.register("MyPanel")

        # Retrieval
        my_dash_instance_by_name = horizon.get_dashboard("mydash")
        self.assertIsInstance(my_dash_instance_by_name, MyDash)
        my_dash_instance_by_class = horizon.get_dashboard(MyDash)
        self.assertEqual(my_dash_instance_by_name, my_dash_instance_by_class)
        with self.assertRaises(base.NotRegistered):
            horizon.get_dashboard("fake")
        self.assertQuerysetEqual(
            horizon.get_dashboards(),
            ['<Dashboard: cats>', '<Dashboard: dogs>', '<Dashboard: mydash>'])

        # Removal
        self.assertEqual(3, len(base.Horizon._registry))
        horizon.unregister(MyDash)
        self.assertEqual(2, len(base.Horizon._registry))
        with self.assertRaises(base.NotRegistered):
            horizon.get_dashboard(MyDash)
示例#3
0
    def test_registry_two_dashboards(self):
        "Verify registration of 2 dashboards"

        # Registration
        self.assertEqual(2, len(base.Horizon._registry))
        horizon.register(MyDash)
        horizon.register(MyOtherDash)
        self.assertEqual(4, len(base.Horizon._registry))

        # Retrieval
        self.assertQuerysetEqual(horizon.get_dashboards(), [
            '<Dashboard: cats>', '<Dashboard: dogs>', '<Dashboard: mydash>',
            '<Dashboard: mydash2>'
        ])

        # Removal
        self.assertEqual(4, len(base.Horizon._registry))
        horizon.unregister(MyDash)
        horizon.unregister(MyOtherDash)
        self.assertEqual(2, len(base.Horizon._registry))
        with self.assertRaises(base.NotRegistered):
            horizon.get_dashboard(MyDash)
        with self.assertRaises(base.NotRegistered):
            horizon.get_dashboard(MyOtherDash)
示例#4
0
from django.utils.translation import ugettext_lazy as _

import horizon

# Rename "cats" to "wildcats"
cats = horizon.get_dashboard("cats")
cats.name = _("WildCats")

# Disable tigers panel
tigers = cats.get_panel("tigers")
cats.unregister(tigers.__class__)

# Remove dogs dashboard
dogs = horizon.get_dashboard("dogs")
horizon.unregister(dogs.__class__)