"Fossies" - the Fresh Open Source Software Archive

Member "horizon-14.0.4/openstack_dashboard/test/test_plugins/test_panel.py" (22 Oct 2019, 4044 Bytes) of package /linux/misc/openstack/horizon-14.0.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    2 #    not use this file except in compliance with the License. You may obtain
    3 #    a copy of the License at
    4 #
    5 #         http://www.apache.org/licenses/LICENSE-2.0
    6 #
    7 #    Unless required by applicable law or agreed to in writing, software
    8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   10 #    License for the specific language governing permissions and limitations
   11 #    under the License.
   12 
   13 import copy
   14 
   15 from django.conf import settings
   16 from django.test.utils import override_settings
   17 
   18 import horizon
   19 
   20 from openstack_dashboard.dashboards.admin.info import panel as info_panel
   21 from openstack_dashboard.test import helpers as test
   22 from openstack_dashboard.test.test_panels.plugin_panel \
   23     import panel as plugin_panel
   24 from openstack_dashboard.test.test_panels.nonloading_panel \
   25     import panel as nonloading_panel
   26 from openstack_dashboard.test.test_plugins import panel_config
   27 from openstack_dashboard.utils import settings as util_settings
   28 
   29 
   30 HORIZON_CONFIG = copy.deepcopy(settings.HORIZON_CONFIG)
   31 INSTALLED_APPS = list(settings.INSTALLED_APPS)
   32 
   33 # NOTE: Ensure dashboards and default_dashboard are not included in
   34 # HORIZON_CONFIG to ensure warning messages from update_dashboards below.
   35 HORIZON_CONFIG.pop('dashboards', None)
   36 HORIZON_CONFIG.pop('default_dashboard', None)
   37 HORIZON_CONFIG.pop('js_files', None)
   38 HORIZON_CONFIG.pop('js_spec_files', None)
   39 HORIZON_CONFIG.pop('scss_files', None)
   40 HORIZON_CONFIG.pop('xstatic_modules', None)
   41 
   42 util_settings.update_dashboards([panel_config,], HORIZON_CONFIG, INSTALLED_APPS)
   43 
   44 
   45 @override_settings(HORIZON_CONFIG=HORIZON_CONFIG,
   46                    INSTALLED_APPS=INSTALLED_APPS)
   47 class PanelPluginTests(test.PluginTestCase):
   48     urls = 'openstack_dashboard.test.extensible_header_urls'
   49 
   50     def test_add_panel(self):
   51         dashboard = horizon.get_dashboard("admin")
   52         panel_group = dashboard.get_panel_group('admin')
   53         # Check that the panel is in its configured dashboard.
   54         self.assertIn(plugin_panel.PluginPanel,
   55                       [p.__class__ for p in dashboard.get_panels()])
   56         # Check that the panel is in its configured panel group.
   57         self.assertIn(plugin_panel.PluginPanel,
   58                       [p.__class__ for p in panel_group])
   59         # Ensure that static resources are properly injected
   60         pc = panel_config._10_admin_add_panel
   61         self.assertEqual(pc.ADD_JS_FILES, HORIZON_CONFIG['js_files'])
   62         self.assertEqual(pc.ADD_JS_SPEC_FILES, HORIZON_CONFIG['js_spec_files'])
   63         self.assertEqual(pc.ADD_SCSS_FILES, HORIZON_CONFIG['scss_files'])
   64         self.assertEqual(pc.ADD_XSTATIC_MODULES,
   65                          HORIZON_CONFIG['xstatic_modules'])
   66         self.assertEqual(pc.ADD_HEADER_SECTIONS,
   67                          HORIZON_CONFIG['header_sections'])
   68 
   69     def test_extensible_header(self):
   70         with self.settings(ROOT_URLCONF=self.urls):
   71             response = self.client.get('/header/')
   72             self.assertIn('sample context', response.content.decode('utf-8'))
   73 
   74     def test_remove_panel(self):
   75         dashboard = horizon.get_dashboard("admin")
   76         panel_group = dashboard.get_panel_group('admin')
   77         # Check that the panel is no longer in the configured dashboard.
   78         self.assertNotIn(info_panel.Info,
   79                          [p.__class__ for p in dashboard.get_panels()])
   80         # Check that the panel is no longer in the configured panel group.
   81         self.assertNotIn(info_panel.Info,
   82                          [p.__class__ for p in panel_group])
   83 
   84     def test_default_panel(self):
   85         dashboard = horizon.get_dashboard("admin")
   86         self.assertEqual('defaults', dashboard.default_panel)
   87 
   88     def test_panel_not_added(self):
   89         dashboard = horizon.get_dashboard("admin")
   90         self.assertNotIn(nonloading_panel.NonloadingPanel,
   91                          [p.__class__ for p in dashboard.get_panels()])