def test_single_child_notvisible(self, client, root, anon_request): """ single inaccessible child """ Type1Type.create(navigation=True, node=root.add("c1")).save() with mock.patch("wheelcms_axle.auth.has_access", return_value=False): res = navigation_items(anon_request, root) assert len(res['toplevel']) == 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
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_attached_empty_root(self, client, root, anon_request): """ content on root, no children """ Type1Type.create(node=root).save() res = navigation_items(anon_request, root) assert 'toplevel' in res assert res['toplevel'] == []
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_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
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
def test_second_level_visible(self, client, root, anon_request): """ child with subcontent, accessible """ n1 = root.add("c1") n1_child = n1.add("c2") Type1Type.create(navigation=True, node=n1).save() c2 = Type1Type.create(navigation=True, node=n1_child).save() with mock.patch("wheelcms_axle.auth.has_access", return_value=True): res = navigation_items(anon_request, root) assert len(res['toplevel']) == 1 assert len(res['toplevel'][0]['sub']) == 1 assert res['toplevel'][0]['sub'][0]['url'] == \ c2.instance.get_absolute_url()
def test_form_choices(self): """ the form should get its choices from the workflow """ form = Type1Type.form(parent=Node.root()) wfclass = core.workflow[Type1Type] assert form.workflow_choices() == wfclass.states assert form.workflow_default() == wfclass.default
def test_single_child_visible(self, client, root, anon_request): """ single accessible child """ c = Type1Type.create(navigation=True, node=root.add("c1")).save() with mock.patch("wheelcms_axle.auth.has_access", return_value=True): res = navigation_items(anon_request, root) assert len(res['toplevel']) == 1 assert res['toplevel'][0]['url'] == c.instance.get_absolute_url()
def test_second_level_invisible(self, client, root, anon_request): """ toplevel accessible, sublevel not """ n1 = root.add("c1") n1_child = n1.add("c2") Type1Type.create(navigation=True, node=n1).save() c2 = Type1Type.create(navigation=True, node=n1_child).save() def mocked_has_access(request, type, spoke, perm): if spoke == c2: return False return True with mock.patch("wheelcms_axle.auth.has_access", mocked_has_access): res = navigation_items(anon_request, root) assert len(res['toplevel']) == 1 assert len(res['toplevel'][0]['sub']) == 0
def test_no_handler_no_change(self, client): """ if the state remains unchanged, the handler should not be invoked """ with mock_receiver(state_changed) as receiver: t = Type1Type.create(title="hello", state="initial").save() t.instance.state="initial" t.save() assert receiver.call_count == 0
def test_handler_after_change(self, client): """ if state changes, the handler should be invoked """ with mock_receiver(state_changed) as receiver: t = Type1Type.create(title="hello", state="initial").save() t.instance.state="changed" t.save() assert receiver.call_count == 1 args, kwargs = receiver.call_args assert kwargs.get('oldstate') == 'initial' assert kwargs.get('newstate') == 'changed' assert kwargs.get('sender') == t.instance
def setup_handler(self, user=None, method="GET", with_instance=False, state="private"): """ setup the mainhandler """ root = Node.root() if with_instance: cont = Type1Type.create(node=root, state=state).save() cont.assign_perms() request = create_request(method, "/", data={'type':Type1.get_name()}) if self.provide_user(): request.user = self.provide_user() handler = MainHandler() handler.init_from_request(request) handler.instance = root return handler
def test_active(self, client, root, anon_request): """ Correct item should be 'active' if accessed through a childnode of it """ n1 = root.add("c1") n2 = root.add("c2") n1_child = n1.add("c1_c") n2_child = n2.add("c2_c") Type1Type.create(navigation=True, node=n1).save() Type1Type.create(navigation=True, node=n1_child).save() Type1Type.create(navigation=True, node=n2).save() Type1Type.create(navigation=True, node=n2_child).save() with mock.patch("wheelcms_axle.auth.has_access", return_value=True): res = navigation_items(anon_request, n2_child) assert len(res['toplevel']) == 2 assert not res['toplevel'][0]['active'] assert res['toplevel'][1]['active']
def test_init_not_change_emptystate(self, client): """ Initialization/creation is not a state change """ with mock_receiver(state_changed) as receiver: Type1Type.create(title="hello").save() assert receiver.call_count == 0
def test_form_choices_instance(self, client): """ and it's value should be taken from the instance """ data = Type1(state="published") data.save() form = Type1Type.form(parent=Node.root(), instance=data) assert form['state'].value() == "published"