예제 #1
0
 def test_admin_theme_css_setting(self):
     # test for improper configuration : not a list
     setattr(admin_theme_settings, 'OPENWISP_ADMIN_THEME_LINKS',
             'string instead of list')
     self.assertIn(
         'OPENWISP_ADMIN_THEME_LINKS',
         str(admin_theme_settings_checks(OpenWispAdminThemeConfig)[0]))
     # test for improper configuration : list_elements != type(dict)
     setattr(admin_theme_settings, 'OPENWISP_ADMIN_THEME_LINKS',
             ['/static/custom-admin-theme.css'])
     self.assertIn(
         'OPENWISP_ADMIN_THEME_LINKS',
         str(admin_theme_settings_checks(OpenWispAdminThemeConfig)[0]))
     # test for improper configuration: dict missing required keys
     setattr(admin_theme_settings, 'OPENWISP_ADMIN_THEME_LINKS',
             [{
                 'wrong': True
             }])
     self.assertIn(
         'OPENWISP_ADMIN_THEME_LINKS',
         str(admin_theme_settings_checks(OpenWispAdminThemeConfig)[0]))
     # test with desired configuration
     setattr(admin_theme_settings, 'OPENWISP_ADMIN_THEME_LINKS',
             [{
                 'href': '/static/custom-admin-theme.css',
                 'rel': 'stylesheet',
                 'type': 'text/css',
                 'media': 'all'
             }])
     response = self.client.get(reverse('admin:index'))
     self.assertContains(response,
                         '/static/custom-admin-theme.css" media="all"')
예제 #2
0
    def test_admin_theme_css_setting(self):
        # test for improper configuration : not a list
        with patch.object(admin_theme_settings, 'OPENWISP_ADMIN_THEME_LINKS',
                          'string instead of list'):
            self.assertIn(
                'OPENWISP_ADMIN_THEME_LINKS',
                str(admin_theme_settings_checks(OpenWispAdminThemeConfig)[0]),
            )
        # test for improper configuration : list_elements != type(dict)
        with patch.object(
                admin_theme_settings,
                'OPENWISP_ADMIN_THEME_LINKS',
            ['/static/custom-admin-theme.css'],
        ):
            self.assertIn(
                'OPENWISP_ADMIN_THEME_LINKS',
                str(admin_theme_settings_checks(OpenWispAdminThemeConfig)[0]),
            )
        # test for improper configuration: dict missing required keys
        with patch.object(admin_theme_settings, 'OPENWISP_ADMIN_THEME_LINKS',
                          [{
                              'wrong': True
                          }]):
            self.assertIn(
                'OPENWISP_ADMIN_THEME_LINKS',
                str(admin_theme_settings_checks(OpenWispAdminThemeConfig)[0]),
            )
        # test with desired configuration
        with patch.object(
                admin_theme_settings,
                'OPENWISP_ADMIN_THEME_LINKS',
            [{
                'href': '/static/custom-admin-theme.css',
                'rel': 'stylesheet',
                'type': 'text/css',
                'media': 'all',
            }],
        ):
            response = self.client.get(reverse('admin:index'))
            self.assertContains(response,
                                '/static/custom-admin-theme.css" media="all"')

        # test if files are loaded with staticfiles
        response = self.client.get(reverse('admin:index'))
        self.assertContains(response,
                            '/static/admin/css/openwisp.css" media="all"')
        self.assertContains(response, '/static/menu-test.css" media="all"')
        self.assertContains(response,
                            'href="/static/ui/openwisp/images/favicon.png"')
        self.assertContains(response, '/static/dummy.js')
예제 #3
0
 def test_admin_theme_js_setting(self):
     # test for improper configuration : not a list
     setattr(admin_theme_settings, 'OPENWISP_ADMIN_THEME_JS',
             'string instead of list')
     self.assertIn(
         'OPENWISP_ADMIN_THEME_JS',
         str(admin_theme_settings_checks(OpenWispAdminThemeConfig)[0]))
     # test for improper configuration : list_elements != type(str)
     setattr(admin_theme_settings, 'OPENWISP_ADMIN_THEME_JS', [0, 1, 2])
     self.assertIn(
         'OPENWISP_ADMIN_THEME_JS',
         str(admin_theme_settings_checks(OpenWispAdminThemeConfig)[0]))
     # test with desired configuration
     setattr(admin_theme_settings, 'OPENWISP_ADMIN_THEME_JS',
             ['/static/openwisp-utils/js/uuid.js'])
     response = self.client.get(reverse('admin:index'))
     self.assertContains(response,
                         'src="/static/openwisp-utils/js/uuid.js"')
예제 #4
0
    def test_admin_theme_css_setting(self):

        # test for improper configuration : not a list
        setattr(admin_theme_settings, 'OPENWISP_ADMIN_THEME_CSS',
                'string instead of list')
        self.assertIn(
            'OPENWISP_ADMIN_THEME_CSS',
            str(admin_theme_settings_checks(OpenWispAdminThemeConfig)[0]))

        # test for improper configuration : list_elements != type(str)
        setattr(admin_theme_settings, 'OPENWISP_ADMIN_THEME_CSS', [0, 1, 2])
        self.assertIn(
            'OPENWISP_ADMIN_THEME_CSS',
            str(admin_theme_settings_checks(OpenWispAdminThemeConfig)[0]))

        # test with desired configuration
        setattr(admin_theme_settings, 'OPENWISP_ADMIN_THEME_CSS',
                ['http://127.0.0.1:8000/static/custom-admin-theme.css'])
        response = self.client.get(reverse('admin:index'))
        self.assertContains(
            response,
            'href="http://127.0.0.1:8000/static/custom-admin-theme.css"')