Example #1
0
 def test_clipboard_empty(self, client):
     toolbar = Toolbar(Node.root(), superuser_request("/"), "view")
     clipboard = toolbar.clipboard()
     assert clipboard['count'] == 0
     assert not clipboard['copy']
     assert not clipboard['cut']
     assert clipboard['items'] == []
Example #2
0
    def test_button_state_all(self, client, root, toolbar_registry):
        """ A toolbar action with states=() always shows """
        Type1Type.create(node=root).save()
        toolbar = Toolbar(root, superuser_request("/"), "edit")

        toolbar_registry.register(mock.Mock(type="button", states=()))
        assert len(toolbar.button_actions()) == 1
Example #3
0
    def test_restriction_type(self, client):
        """
            A single childtype allowed
        """
        registry = self.registry

        class DummyNode(object):
            def content(self):
                class DummyContent(object):
                    meta_type = 'dummycontent'

                    @classmethod
                    def get_name(cls):
                        return "test." + cls.meta_type

                class DummyType(Spoke):
                    model = DummyContent
                    children = (Type1Type,)

                    @classmethod
                    def name(self):
                        return DummyContent.get_name()

                registry.register(DummyType)

                return DummyContent()

        toolbar = Toolbar(DummyNode(), superuser_request("/"), "view")
        children = toolbar.children()
        assert len(children) == 1
        assert children[0]['name'] == Type1Type.name()
        assert children[0]['title'] == Type1Type.title
        assert children[0]['icon_path'] == Type1Type.full_type_icon_path()
Example #4
0
    def test_translations_create(self, client):
        root = Node.root()

        n = root.add(langslugs=dict(en="en", nl="nl", fr="fr"))
        t_nl = Type1(node=n, language="nl", title="NL").save()
        t_en = Type1(node=n, language="en", title="EN").save()


        request = create_request("GET", "/create", data=dict(type="sometype"))

        translation.activate("en")
        toolbar = Toolbar(n, request, "create")
        translations = toolbar.translations()

        assert translations['active']['id'] == 'en'

        import urllib2

        ## Do some matching magic using endswith to work around language / base prefixing.
        ## We're mosly interested in create/view/edit actions anyway
        assert len(translations['translated']) == 0
        assert len(translations['untranslated']) == 3  ## all languages incl 'any', active lang excluded

        for ut in translations['untranslated']:
            l = ut['id']
            assert l in ('nl', 'fr', 'en', 'any')
            assert ut['action_url'].endswith('switch_admin_language?path='+n.tree_path + '&switchto=' + l + '&rest=' + urllib2.quote('create?type=sometype'))
Example #5
0
    def test_restriction_none(self, client):
        """
            No children at all allowed
        """
        registry = self.registry

        class DummyNode(object):
            def content(self):
                class DummyContent(object):
                    meta_type = 'dummycontent'

                    @classmethod
                    def get_name(cls):
                        return "test." + cls.meta_type

                class DummyType(Spoke):
                    model = DummyContent
                    children = ()

                    @classmethod
                    def name(self):
                        return DummyContent.get_name()

                registry.register(DummyType)

                return DummyContent()

        toolbar = Toolbar(DummyNode(), superuser_request("/"), "view")
        assert toolbar.children() == []
        assert not toolbar.show_create()
Example #6
0
    def test_primary(self, client):
        """ a type with primary should behave differently """


        class DummyNode(object):
            def content(self):
                class DummyType(Spoke):
                    model = DummyContent
                    children = (Type1Type, Type2Type)
                    primary = Type1Type
                    add_to_index = False

                    @classmethod
                    def name(cls):
                        return cls.model.get_name()

                type_registry.register(DummyType)

                return DummyContent()

        toolbar = Toolbar(DummyNode(), superuser_request("/"), "view")
        children = toolbar.children()
        assert len(children) == 1
        assert children[0]['name'] == Type2Type.name()
        assert children[0]['title'] == Type2Type.title
        assert children[0]['icon_path'] == Type2Type.full_type_icon_path()

        primary = toolbar.primary()
        assert primary
        assert primary['name'] == Type1Type.name()
        assert primary['title'] == Type1Type.title
        assert primary['icon_path'] == Type1Type.full_type_icon_path()
Example #7
0
 def test_single_child_single(self):
     """ only valid case where there's "a single" child """
     c1 = mock.Mock()
     with mock.patch("wheelcms_axle.toolbar.Toolbar.type",
                     return_value=mock.Mock(children=(c1,))):
         t = Toolbar(mock.Mock(), mock.Mock(), "view")
         assert t.single_child() is c1
Example #8
0
    def test_no_implicit_unattached(self, client):
        """ An unattached node cannot restrict its children but
            should still not allow creation of non-implicit_add
            types """

        class DummyContent(object):
            meta_type = 'dummycontent'

            @classmethod
            def get_name(cls):
                return "test." + cls.meta_type

        class DummyType(Spoke):
            model = DummyContent
            children = ()
            implicit_add = False

            @classmethod
            def title(cls):
                return ''

        self.registry.register(DummyType)


        node = Node.root()
        toolbar = Toolbar(node, superuser_request("/"), "view")
        for c in toolbar.children():
            assert c['name'] != DummyType.name()
Example #9
0
    def test_button_state_mismatch(self, client, root, toolbar_registry):
        """ If an explicit state is given, it must match with toolbar status
        """
        Type1Type.create(node=root).save()
        toolbar = Toolbar(root, superuser_request("/"), "edit")

        toolbar_registry.register(mock.Mock(type="button", states=("view",)))
        assert len(toolbar.button_actions()) == 0
Example #10
0
    def test_nosu_no_settings(self, client):
        user, _ = User.objects.get_or_create(username="******")
        request = create_request("GET", "/")
        request.user = user

        node = Node.root()
        toolbar = Toolbar(node, request, "view")
        assert not toolbar.show_settings()
Example #11
0
    def test_no_button_actions(self, client, root, toolbar_registry):
        """
            A node with content without restrictions
        """
        Type1Type.create(node=root).save()
        toolbar = Toolbar(root, superuser_request("/"), "view")

        assert len(toolbar.button_actions()) == 0
Example #12
0
 def test_update_mode_buttons(self, client):
     """ verify that certain buttons are not shown in update mode """
     node = Node.root()
     content = Type1(node=node)
     content.save()
     toolbar = Toolbar(node, superuser_request("/"), "update")
     assert not toolbar.show_create()
     assert not toolbar.show_update()
Example #13
0
    def test_single_child_multi(self):
        """ multiple allowed children means there's not "a single" child """
        c1 = mock.Mock()
        c2 = mock.Mock()

        with mock.patch("wheelcms_axle.toolbar.Toolbar.type",
                        return_value=mock.Mock(children=(c1, c2))):
            t = Toolbar(mock.Mock(), mock.Mock(), "view")
            assert t.single_child() is None
Example #14
0
 def test_unconnected(self, client):
     """
         Test behaviour on unconnected node - allow
         creation of all types of sub content
     """
     root = Node.root()
     toolbar = Toolbar(root, superuser_request("/"), "view")
     assert toolbar.show_create()
     assert self.allchildren(toolbar.children())
Example #15
0
 def test_connected_no_restrictions(self, client):
     """
         A node with content without restrictions
     """
     root = Node.root()
     content = Type1(node=root)
     content.save()
     toolbar = Toolbar(root, superuser_request("/"), "view")
     assert toolbar.show_create()
     assert self.allchildren(toolbar.children())
Example #16
0
 def test_unconnected(self, mocked_registry):
     """
         Test behaviour on unconnected node - allow
         creation of all types of sub content
     """
     with mock.patch("wheelcms_axle.toolbar.Toolbar.type",
                     return_value=None):
         t = Toolbar(mock.Mock(), mock.Mock(), "view")
         assert t.show_create()
         assert self.allchildren(t.children())
Example #17
0
    def test_connected_no_restrictions(self, mocked_registry):
        """
            A node with content without restrictions
        """
        class T(mock.Mock):
            primary = children = None
            def allowed_spokes(self):
                return type_registry.values()

        with mock.patch("wheelcms_axle.toolbar.Toolbar.type",
                        return_value=T):
            t = Toolbar(mock.Mock(), mock.Mock(), "view")
            assert t.show_create()
            assert self.allchildren(t.children())
Example #18
0
    def test_show_translate(self, client):
        root = Node.root()

        n = root.add(langslugs=dict(en="en", nl="nl", fr="fr"))
        t_nl = Type1(node=n, language="nl", title="NL").save()
        translation.activate("en")
        request = create_request("GET", "/")
        toolbar = Toolbar(n, request, "view")

        assert toolbar.show_translate()
        assert not toolbar.show_update()
        translation.activate("nl")
        assert not toolbar.show_translate()
        assert toolbar.show_update()
Example #19
0
    def test_clipboard_copy(self, client):
        root = Node.root()

        t1 = Type1(node=root.add("t1"), title="t1").save()
        t2 = Type1(node=root.add("t2"), title="t2").save()

        request = create_request("GET", "/")
        request.session['clipboard_copy'] = [t2.node.tree_path, t1.node.tree_path]

        toolbar = Toolbar(Node.root(), request, "view")
        clipboard = toolbar.clipboard()
        assert clipboard['count'] == 2
        assert clipboard['copy']
        assert not clipboard['cut']
        assert set(clipboard['items']) == set((t1, t2))
Example #20
0
    def test_restriction_type(self):
        """
            A single childtype allowed
        """
        c = mock.Mock()
        class T(mock.Mock):
            primary = None
            children = (c,)
            def allowed_spokes(self):
                return (c,)

        with mock.patch("wheelcms_axle.toolbar.Toolbar.type",
                        return_value=T):
            t = Toolbar(mock.Mock(), mock.Mock(), "view")
            assert t.show_create()
            children = t.children()
            assert len(children) == 1
            assert children[0]['name'] == c.name()
            assert children[0]['title'] == c.title
            assert children[0]['icon_path'] == c.full_type_icon_path()
Example #21
0
    def test_translations_list(self, client):
        root = Node.root()

        n = root.add(langslugs=dict(en="en", nl="nl", fr="fr"))
        t_nl = Type1(node=n, language="nl", title="NL").save()
        t_en = Type1(node=n, language="en", title="EN").save()


        request = create_request("GET", "/")

        translation.activate("en")
        toolbar = Toolbar(n, request, "list")
        translations = toolbar.translations()

        assert translations['active']['id'] == 'en'

        ## Do some matching magic using endswith to work around language / base prefixing.
        ## We're mosly interested in create/view/edit actions anyway
        assert translations['translated'][0]['id'] == "nl"
        assert translations['translated'][0]['action_url'].endswith('switch_admin_language?path='+n.tree_path + '&switchto=nl&rest=list')
        assert translations['untranslated'][0]['id'] == 'fr'
        assert translations['untranslated'][0]['action_url'].endswith('switch_admin_language?path='+n.tree_path + '&switchto=fr&rest=list')
Example #22
0
    def test_restriction_none(self, client):
        """
            No children at all allowed
        """
        class DummyNode(object):
            def content(self):
                class DummyType(Spoke):
                    model = DummyContent
                    children = ()
                    add_to_index = False

                    @classmethod
                    def name(cls):
                        return DummyContent.get_name()

                type_registry.register(DummyType)

                return DummyContent()

        toolbar = Toolbar(DummyNode(), superuser_request("/"), "view")
        assert toolbar.children() == []
        assert not toolbar.show_create()
Example #23
0
 def test_anon_no_settings(self, client):
     node = Node.root()
     toolbar = Toolbar(node, create_request("GET", "/"), "view")
     assert not toolbar.show_settings()
Example #24
0
 def test_single_child_empty(self):
     """ No allowed children means there's not "a single" child """
     with mock.patch("wheelcms_axle.toolbar.Toolbar.type",
                     return_value=mock.Mock(children=())):
         t = Toolbar(mock.Mock(), mock.Mock(), "view")
         assert t.single_child() is None
Example #25
0
 def test_primary_unattached(self, client):
     """ an unattached node has no primary content """
     toolbar = Toolbar(Node.root(), superuser_request("/"), "view")
     assert toolbar.primary() is None