Ejemplo n.º 1
0
class ToolbarPoolTests(CMSTestCase):
    def setUp(self):
        self.pool = ToolbarPool()

    def test_register(self):
        self.pool.register(TestToolbar)
        self.pool.register(CMSToolbar)
        self.assertEqual(
            self.pool.toolbars, {
                'cms.toolbar_base.CMSToolbar': CMSToolbar,
                'cms.tests.toolbar_pool.TestToolbar': TestToolbar
            })

        self.assertRaises(ToolbarAlreadyRegistered, self.pool.register,
                          TestToolbar)

    def test_register_type(self):
        self.assertRaises(ImproperlyConfigured, self.pool.register, str)
        self.assertRaises(ImproperlyConfigured, self.pool.register, object)

    def test_register_order(self):
        self.pool.register(TestToolbar)
        self.pool.register(CMSToolbar)

        test_toolbar = SortedDict()
        test_toolbar['cms.tests.toolbar_pool.TestToolbar'] = TestToolbar
        test_toolbar['cms.toolbar_base.CMSToolbar'] = CMSToolbar
        self.assertEqual(list(test_toolbar.keys()),
                         list(self.pool.toolbars.keys()))

    def test_unregister(self):
        self.pool.register(TestToolbar)
        self.pool.unregister(TestToolbar)
        self.assertEqual(self.pool.toolbars, {})

        self.assertRaises(ToolbarNotRegistered, self.pool.unregister,
                          TestToolbar)

    def test_settings(self):
        toolbars = toolbar_pool.toolbars
        toolbar_pool.clear()
        with self.settings(CMS_TOOLBARS=[
                'cms.cms_toolbar.BasicToolbar',
                'cms.cms_toolbar.PlaceholderToolbar'
        ]):
            toolbar_pool.register(TestToolbar)
            self.assertEqual(len(list(self.pool.get_toolbars().keys())), 2)
            api.create_page("home", "simple.html", "en", published=True)
            with self.login_user_context(self.get_superuser()):
                response = self.client.get(
                    "/en/?%s" % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'))
                self.assertEqual(response.status_code, 200)
        toolbar_pool.toolbars = toolbars

    def test_watch_models(self):
        toolbar_pool.discover_toolbars()
        self.assertEqual(type(toolbar_pool.get_watch_models()), list)
Ejemplo n.º 2
0
 def test_settings(self):
     pool = ToolbarPool()
     toolbars = toolbar_pool.toolbars
     toolbar_pool.clear()
     with self.settings(CMS_TOOLBARS=['cms.cms_toolbars.BasicToolbar', 'cms.cms_toolbars.PlaceholderToolbar']):
         toolbar_pool.register(TestToolbar)
         self.assertEqual(len(list(pool.get_toolbars().keys())), 2)
         api.create_page("home", "simple.html", "en", published=True)
         with self.login_user_context(self.get_superuser()):
             response = self.client.get("/en/?%s" % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'))
             self.assertEqual(response.status_code, 200)
     toolbar_pool.toolbars = toolbars
Ejemplo n.º 3
0
class ToolbarPoolTests(CMSTestCase):
    def setUp(self):
        self.pool = ToolbarPool()

    def test_register(self):
        self.pool.register(TestToolbar)
        self.pool.register(CMSToolbar)
        self.assertEqual(
            self.pool.toolbars,
            {"cms.toolbar_base.CMSToolbar": CMSToolbar, "cms.tests.toolbar_pool.TestToolbar": TestToolbar},
        )

        self.assertRaises(ToolbarAlreadyRegistered, self.pool.register, TestToolbar)

    def test_register_type(self):
        self.assertRaises(ImproperlyConfigured, self.pool.register, str)
        self.assertRaises(ImproperlyConfigured, self.pool.register, object)

    def test_register_order(self):
        self.pool.register(TestToolbar)
        self.pool.register(CMSToolbar)

        test_toolbar = SortedDict()
        test_toolbar["cms.tests.toolbar_pool.TestToolbar"] = TestToolbar
        test_toolbar["cms.toolbar_base.CMSToolbar"] = CMSToolbar
        self.assertEqual(list(test_toolbar.keys()), list(self.pool.toolbars.keys()))

    def test_unregister(self):
        self.pool.register(TestToolbar)
        self.pool.unregister(TestToolbar)
        self.assertEqual(self.pool.toolbars, {})

        self.assertRaises(ToolbarNotRegistered, self.pool.unregister, TestToolbar)

    def test_settings(self):
        toolbars = toolbar_pool.toolbars
        toolbar_pool.clear()
        with self.settings(CMS_TOOLBARS=["cms.cms_toolbar.BasicToolbar", "cms.cms_toolbar.PlaceholderToolbar"]):
            toolbar_pool.register(TestToolbar)
            self.assertEqual(len(list(self.pool.get_toolbars().keys())), 2)
            api.create_page("home", "simple.html", "en", published=True)
            with self.login_user_context(self.get_superuser()):
                response = self.client.get("/en/?%s" % get_cms_setting("CMS_TOOLBAR_URL__EDIT_ON"))
                self.assertEqual(response.status_code, 200)
        toolbar_pool.toolbars = toolbars

    def test_watch_models(self):
        toolbar_pool.discover_toolbars()
        self.assertEqual(type(toolbar_pool.get_watch_models()), list)
Ejemplo n.º 4
0
 def test_settings(self):
     pool = ToolbarPool()
     toolbars = toolbar_pool.toolbars
     toolbar_pool.clear()
     with self.settings(CMS_TOOLBARS=[
             'cms.cms_toolbars.BasicToolbar',
             'cms.cms_toolbars.PlaceholderToolbar'
     ]):
         toolbar_pool.register(TestToolbar)
         self.assertEqual(len(list(pool.get_toolbars().keys())), 2)
         api.create_page("home", "simple.html", "en", published=True)
         with self.login_user_context(self.get_superuser()):
             response = self.client.get(
                 "/en/?%s" % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'))
             self.assertEqual(response.status_code, 200)
     toolbar_pool.toolbars = toolbars
Ejemplo n.º 5
0
class ToolbarPoolTests(CMSTestCase):

    def setUp(self):
        self.pool = ToolbarPool()

    def test_register(self):
        self.pool.register(TestToolbar)
        self.pool.register(CMSToolbar)
        self.assertEqual(self.pool.toolbars, {
            'cms.toolbar_base.CMSToolbar': CMSToolbar,
            'cms.tests.toolbar_pool.TestToolbar': TestToolbar})

        self.assertRaises(ToolbarAlreadyRegistered,
                          self.pool.register, TestToolbar)

    def test_register_type(self):
        self.assertRaises(ImproperlyConfigured, self.pool.register, str)
        self.assertRaises(ImproperlyConfigured, self.pool.register, object)

    def test_register_order(self):
        self.pool.register(TestToolbar)
        self.pool.register(CMSToolbar)

        test_toolbar = SortedDict()
        test_toolbar['cms.tests.toolbar_pool.TestToolbar'] = TestToolbar
        test_toolbar['cms.toolbar_base.CMSToolbar'] = CMSToolbar
        self.assertEqual(list(test_toolbar.keys()), list(self.pool.toolbars.keys()))

    def test_unregister(self):
        self.pool.register(TestToolbar)
        self.pool.unregister(TestToolbar)
        self.assertEqual(self.pool.toolbars, {})

        self.assertRaises(ToolbarNotRegistered,
                          self.pool.unregister, TestToolbar)

    def test_settings(self):
        toolbars = toolbar_pool.toolbars
        toolbar_pool.clear()
        with SettingsOverride(CMS_TOOLBARS=['cms.cms_toolbar.BasicToolbar', 'cms.cms_toolbar.PlaceholderToolbar']):
            toolbar_pool.register(TestToolbar)
            self.assertEqual(len(list(self.pool.get_toolbars().keys())), 2)
            api.create_page("home", "simple.html", "en", published=True)
            with self.login_user_context(self.get_superuser()):
                response = self.client.get("/en/?edit")
                self.assertEqual(response.status_code, 200)
        toolbar_pool.toolbars = toolbars
Ejemplo n.º 6
0
    def test_settings(self):
        pool = ToolbarPool()
        toolbars = toolbar_pool.toolbars
        toolbar_pool.clear()
        with self.settings(CMS_TOOLBARS=[
                'cms.cms_toolbars.BasicToolbar',
                'cms.cms_toolbars.PlaceholderToolbar'
        ]):
            toolbar_pool.register(TestToolbar)
            self.assertEqual(len(list(pool.get_toolbars().keys())), 2)
            page = api.create_page("home", "simple.html", "en", published=True)
            page_edit_url_on = self.get_edit_on_url(page.get_absolute_url())

            with self.login_user_context(self.get_superuser()):
                response = self.client.get(page_edit_url_on)
                self.assertEqual(response.status_code, 200)
        toolbar_pool.toolbars = toolbars