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