Exemple #1
0
    def test_miscellaneous_DASHBOARD_CHARTS_validation(self):
        with self.subTest('Registering with incomplete config'):
            with self.assertRaises(AssertionError):
                register_dashboard_chart(-1, dict())

        with self.subTest('Registering with invalid position argument'):
            with self.assertRaises(ImproperlyConfigured):
                register_dashboard_chart(['Test Chart'], dict())

        with self.subTest('Registering with invalid config'):
            with self.assertRaises(ImproperlyConfigured):
                register_dashboard_chart(-1, tuple())

        with self.subTest('Unregistering with invalid name'):
            with self.assertRaises(ImproperlyConfigured):
                unregister_dashboard_chart(dict())

        with self.subTest('Test filters required when not group_by'):
            with self.assertRaises(AssertionError) as ctx:
                register_dashboard_chart(
                    -1,
                    {
                        'name': 'Test Chart',
                        'query_params': {
                            'app_label': 'app_label',
                            'model': 'model_name',
                            'annotate': {},
                        },
                    },
                )
            self.assertIn('filters', str(ctx.exception))
Exemple #2
0
    def test_register_dashboard_chart(self):
        from openwisp_utils.admin_theme.dashboard import DASHBOARD_CHARTS

        dashboard_element = {
            'name': 'Test Chart',
            'query_params': {
                'app_label': 'app_label',
                'model': 'model_name',
                'group_by': 'property',
            },
            'colors': {
                'value1': 'red',
                'value2': 'green'
            },
        }

        with self.subTest('Registering new dashboard element'):
            register_dashboard_chart(-1, dashboard_element)
            self.assertIn(-1, DASHBOARD_CHARTS)

        with self.subTest('Registering a chart at existing position'):
            with self.assertRaises(ImproperlyConfigured):
                register_dashboard_chart(-1, dashboard_element)

        with self.subTest('Unregistering a chart that does not exists'):
            with self.assertRaises(ImproperlyConfigured):
                unregister_dashboard_chart('Chart Test')

        with self.subTest('Unregistering "Test Chart"'):
            unregister_dashboard_chart('Test Chart')
            self.assertNotIn(-1, DASHBOARD_CHARTS)
Exemple #3
0
 def test_non_existent_model(self):
     register_dashboard_chart(
         -1,
         {
             'name': 'Test Chart',
             'query_params': {
                 'app_label': 'app_label',
                 'model': 'model_name',
                 'group_by': 'property',
             },
         },
     )
     with self.assertRaises(ImproperlyConfigured):
         self.client.get(reverse('admin:index'))
     unregister_dashboard_chart('Test Chart')
Exemple #4
0
 def remove_dashboard_charts(self):
     unregister_dashboard_chart('Geographic positioning')
     unregister_dashboard_chart('Device Models')
     unregister_dashboard_chart('System type')