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()
 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()
 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())
 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())
 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())
    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())
    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()
    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()