Exemplo n.º 1
0
    def test_dashboard(self):
        syspanel = steer.get_dashboard("syspanel")
        self.assertEqual(syspanel._registered_with, Steer)
        self.assertQuerysetEqual(syspanel.get_panels()['System Panel'],
                                 ['<Panel: Overview>',
                                 '<Panel: Instances>',
                                 '<Panel: Services>',
                                 '<Panel: Flavors>',
                                 '<Panel: Images>',
                                 '<Panel: Tenants>',
                                 '<Panel: Users>',
                                 '<Panel: Quotas>'])
        self.assertEqual(syspanel.get_absolute_url(), "/syspanel/")
        # Test registering a module with a dashboard that defines panels
        # as a dictionary.
        syspanel.register(MyPanel)
        self.assertQuerysetEqual(syspanel.get_panels()['Other'],
                                 ['<Panel: My Panel>'])

        # Test registering a module with a dashboard that defines panels
        # as a tuple.
        settings_dash = steer.get_dashboard("settings")
        settings_dash.register(MyPanel)
        self.assertQuerysetEqual(settings_dash.get_panels(),
                                 ['<Panel: User Settings>',
                                  '<Panel: Tenant Settings>',
                                  '<Panel: My Panel>'])
Exemplo n.º 2
0
 def test_index_url_name(self):
     syspanel = steer.get_dashboard("syspanel")
     instances = syspanel.get_panel("instances")
     instances.index_url_name = "does_not_exist"
     with self.assertRaises(NoReverseMatch):
         instances.get_absolute_url()
     instances.index_url_name = "index"
     self.assertEqual(instances.get_absolute_url(), "/syspanel/instances/")
Exemplo n.º 3
0
 def test_index_url_name(self):
     syspanel = steer.get_dashboard("syspanel")
     instances = syspanel.get_panel("instances")
     instances.index_url_name = "does_not_exist"
     with self.assertRaises(NoReverseMatch):
         instances.get_absolute_url()
     instances.index_url_name = "index"
     self.assertEqual(instances.get_absolute_url(), "/syspanel/instances/")
Exemplo n.º 4
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(len(Steer._registry), 3)
        steer.register(MyDash)
        self.assertEqual(len(Steer._registry), 4)
        with self.assertRaises(ValueError):
            steer.register(MyPanel)
        with self.assertRaises(ValueError):
            steer.register("MyPanel")

        # Retrieval
        my_dash_instance_by_name = steer.get_dashboard("mydash")
        self.assertTrue(isinstance(my_dash_instance_by_name, MyDash))
        my_dash_instance_by_class = steer.get_dashboard(MyDash)
        self.assertEqual(my_dash_instance_by_name, my_dash_instance_by_class)
        with self.assertRaises(base.NotRegistered):
            steer.get_dashboard("fake")
        self.assertQuerysetEqual(steer.get_dashboards(), [
            '<Dashboard: Project>', '<Dashboard: Admin>',
            '<Dashboard: Settings>', '<Dashboard: My Dashboard>'
        ])

        # Removal
        self.assertEqual(len(Steer._registry), 4)
        steer.unregister(MyDash)
        self.assertEqual(len(Steer._registry), 3)
        with self.assertRaises(base.NotRegistered):
            steer.get_dashboard(MyDash)
Exemplo n.º 5
0
    def test_dashboard(self):
        syspanel = steer.get_dashboard("syspanel")
        self.assertEqual(syspanel._registered_with, Steer)
        self.assertQuerysetEqual(syspanel.get_panels()['System Panel'], [
            '<Panel: Overview>', '<Panel: Instances>', '<Panel: Services>',
            '<Panel: Flavors>', '<Panel: Images>', '<Panel: Tenants>',
            '<Panel: Users>', '<Panel: Quotas>'
        ])
        self.assertEqual(syspanel.get_absolute_url(), "/syspanel/")
        # Test registering a module with a dashboard that defines panels
        # as a dictionary.
        syspanel.register(MyPanel)
        self.assertQuerysetEqual(syspanel.get_panels()['Other'],
                                 ['<Panel: My Panel>'])

        # Test registering a module with a dashboard that defines panels
        # as a tuple.
        settings_dash = steer.get_dashboard("settings")
        settings_dash.register(MyPanel)
        self.assertQuerysetEqual(settings_dash.get_panels(), [
            '<Panel: User Settings>', '<Panel: Tenant Settings>',
            '<Panel: My Panel>'
        ])
Exemplo n.º 6
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(len(Steer._registry), 3)
        steer.register(MyDash)
        self.assertEqual(len(Steer._registry), 4)
        with self.assertRaises(ValueError):
            steer.register(MyPanel)
        with self.assertRaises(ValueError):
            steer.register("MyPanel")

        # Retrieval
        my_dash_instance_by_name = steer.get_dashboard("mydash")
        self.assertTrue(isinstance(my_dash_instance_by_name, MyDash))
        my_dash_instance_by_class = steer.get_dashboard(MyDash)
        self.assertEqual(my_dash_instance_by_name, my_dash_instance_by_class)
        with self.assertRaises(base.NotRegistered):
            steer.get_dashboard("fake")
        self.assertQuerysetEqual(steer.get_dashboards(),
                                 ['<Dashboard: Project>',
                                  '<Dashboard: Admin>',
                                  '<Dashboard: Settings>',
                                  '<Dashboard: My Dashboard>'])

        # Removal
        self.assertEqual(len(Steer._registry), 4)
        steer.unregister(MyDash)
        self.assertEqual(len(Steer._registry), 3)
        with self.assertRaises(base.NotRegistered):
            steer.get_dashboard(MyDash)
Exemplo n.º 7
0
                terminated_instances.append(i)
            else:
                running_instances.append(i)

    instances = running_instances
    if show_terminated:
        instances += terminated_instances

    if request.GET.get('format', 'html') == 'csv':
        template_name = 'engine/instances_and_volumes/instances/usage.csv'
        mimetype = "text/csv"
    else:
        template_name = 'engine/instances_and_volumes/instances/usage.html'
        mimetype = "text/html"

    dash_url = steer.get_dashboard('engine').get_absolute_url()

    return shortcuts.render(request, template_name, {
                                'usage': usage,
                                'ram_unit': ram_unit,
                                'total_ram': total_ram,
                                'csv_link': '?format=csv',
                                'show_terminated': show_terminated,
                                'datetime_start': datetime_start,
                                'datetime_end': datetime_end,
                                'instances': instances,
                                'dash_url': dash_url},
                            content_type=mimetype)


@login_required
Exemplo n.º 8
0
def user_home(user):
    if user.admin:
        return steer.get_dashboard('syspanel').get_absolute_url()
    return steer.get_dashboard('engine').get_absolute_url()
Exemplo n.º 9
0
 def test_panels(self):
     syspanel = steer.get_dashboard("syspanel")
     instances = syspanel.get_panel("instances")
     self.assertEqual(instances._registered_with, syspanel)
     self.assertEqual(instances.get_absolute_url(), "/syspanel/instances/")
Exemplo n.º 10
0
 def test_panels(self):
     syspanel = steer.get_dashboard("syspanel")
     instances = syspanel.get_panel("instances")
     self.assertEqual(instances._registered_with, syspanel)
     self.assertEqual(instances.get_absolute_url(), "/syspanel/instances/")
Exemplo n.º 11
0
                terminated_instances.append(i)
            else:
                running_instances.append(i)

    instances = running_instances
    if show_terminated:
        instances += terminated_instances

    if request.GET.get('format', 'html') == 'csv':
        template_name = 'engine/instances_and_volumes/instances/usage.csv'
        mimetype = "text/csv"
    else:
        template_name = 'engine/instances_and_volumes/instances/usage.html'
        mimetype = "text/html"

    dash_url = steer.get_dashboard('engine').get_absolute_url()

    return shortcuts.render(request,
                            template_name, {
                                'usage': usage,
                                'ram_unit': ram_unit,
                                'total_ram': total_ram,
                                'csv_link': '?format=csv',
                                'show_terminated': show_terminated,
                                'datetime_start': datetime_start,
                                'datetime_end': datetime_end,
                                'instances': instances,
                                'dash_url': dash_url
                            },
                            content_type=mimetype)