def test_preferred_language_children(self, client): root = Node.root() sub = root.add("sub") root = Node.root(language="nl") child = root.children()[0] assert child.preferred_language == "nl"
def test_remove_single_root(self, client, root): """ single, non-recursive removal """ root.add("aaa") assert Node.get("/aaa") root.remove("aaa") assert not Node.get("/aaa")
def test_public_publication(self, client): """ published with explicit publication date """ now = timezone.now() Type1(node=Node.root(), state="published", expire=None, publication=now - timedelta(hours=1)).save() public = Node.objects.public() assert public.count() == 1 assert public[0] == Node.root()
def test_create_map(self, client): root = Node.root() r = root.add(langslugs=dict(fr="fr", en="en", nl="nl")) assert Node.get("/fr", language="fr") == \ Node.get("/en", language="en") == \ Node.get("/nl", language="nl") == r
def test_public_publish(self, client): """ published without explicit expire/publication """ Type1(node=Node.root(), state="published", expire=None, publication=None).save() public = Node.objects.public() assert public.count() == 1 assert public[0] == Node.root()
def test_remove_ignore_similar(self, client): """ removing /aaa shouldn't affect /aaaa """ root = Node.root() root.add("aaa") root.add("aaaa") root.remove("aaa") assert Node.get("/aaaa")
def test_remove_single_child(self, client, root): """ single, non-recursive removal """ child = root.add("aaa") child.add("bbb") assert Node.get("/aaa/bbb") child.remove("bbb") assert not Node.get("/aaa/bbb")
def test_remove_recursive(self, client, root): """ recursive removal """ child = root.add("aaa") child.add("b1") child.add("b2") assert Node.get("/aaa/b1") root.remove("aaa") assert not Node.get("/aaa/b1") assert not Node.get("/aaa/b2")
def test_node_equality(self, client, root): sub = root.add("sub") sub_nl = Node.root(language="nl").children()[0] sub_en = Node.root(language="en").children()[0] assert sub_nl != sub_en assert sub_nl != sub sub.preferred_language = "nl" assert sub == sub_nl
def test_rename_recursive_similar(self, client): """ renaming /aaa should't affect /aaaa """ aaa = Node.root().add("aaa") aaaa = Node.root().add("aaaa") aa = Node.root().add("aa") bbb = aaaa.add("bbb") bb = aa.add("bb") aaa.rename("ccc") assert Node.objects.get(pk=bbb.pk).path == "/aaaa/bbb" assert Node.objects.get(pk=bb.pk).path == "/aa/bb"
def test_add_different_slugs(self, client): translation.activate('en') root = Node.root() child = root.add("child") child.rename("kind", language="nl") grandchild = child.add("grandchild") assert grandchild.get_path(language="nl") == "/kind/grandchild" assert grandchild.get_path(language="en") == "/child/grandchild" assert Node.get("/child/grandchild", language="nl") is None assert Node.get("/kind/grandchild", language="en") is None
def test_copy_node_position(self, client): """ a node loses its original position when copied, it should always be moved to the bottom """ root = Node.root() src = root.add("src", position=0) target = root.add("target") target_child = target.add("child", position=10) res, success, failed = target.paste(src, copy=True) assert Node.get("/target/src").position > target_child.position
def test_remove_recursive_child(self, client, root): """ recursive removal """ c1 = root.add("aaa") c2 = c1.add("bbb") c2.add("b1") c2.add("b2") assert Node.get("/aaa/bbb/b1") c1.remove("bbb") assert Node.get("/aaa") assert not Node.get("/aaa/bbb/b1") assert not Node.get("/aaa/bbb/b2")
def test_move_node(self, client, root): """ move a node and its descendants elsewhere """ src = root.add("src") src_c = src.add("child") target = root.add("target") res, success, failed = target.paste(src) assert Node.get('/target/src') == src assert Node.get('/target/src/child') == src_c assert Node.get('/src') is None assert res.path == "/target/src"
def test_copy_node_inuse(self, client): """ pasting a node to a node containing a child with the same name, e.g. pasting /foo to /target when there's already a /target/foo """ root = Node.root() src = root.add("src") src_c = src.add("child") target = root.add("target") target_src = target.add("src") res, success, failed = target.paste(src) assert res.path != "/target/src" assert Node.get(res.path + "/child")
def test_node(self, client): translation.activate('en') root = Node.root() child = root.add("child") en_child = Node.get("/child") assert en_child == child assert en_child.path == "/child" assert en_child.slug() == "child" assert en_child.get_path("en") == "/child" assert en_child.slug("en") == "child" assert en_child.get_path("nl") == "/child" assert en_child.slug("nl") == "child" assert en_child.get_path("fr") == "/child" assert en_child.slug("fr") == "child"
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))
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'] == []
def test_preferred_language_child(self, client): root = Node.root() sub = root.add("sub") sub_pref = root.child("sub", language="en") assert sub_pref.preferred_language == "en" sub_pref = root.child("sub", language="nl") assert sub_pref.preferred_language == "nl"
def test_copy_node_to_self(self, client): """ copy /foo to / """ root = Node.root() src = root.add("src") res, success, failed = root.paste(src, copy=True) assert res.path != "/src"
def test_simple(self, client): """ simple case """ root = Node.root() content = Type1(title="Hello World", state="published", node=root).save() spoke = content.spoke() feed = WheelFeed(spoke) assert content.content_ptr in feed.items()
def test_move_inside_offspring(self, client): """ A node cannot be moved to one of its offspring nodes. """ root = Node.root() src = root.add("src") target = src.add("target") py.test.raises(CantMoveToOffspring, target.paste, src)
def setup_nodes(self): """ A mix of attached/unattached nodes, all unpublished """ root = Node.root() _ = Type1(node=root.add("type1")).save() _ = Type1(node=root.add("attached")).save() i3 = root.add("unattached") _ = Type1(node=i3.add("attached-on-unattached")).save()
def test_duplicate_content(self, client): """ two content objects for the same language cannot point to the same node """ root = Node.root() child1 = root.add("n1") Type1(node=child1, language="nl").save() pytest.raises(NodeInUse, lambda: child1.set(Type1(language="nl").save()))
def test_nonroot_child(self, client): """ access a child outside the root by its name """ root = Node.root() child = root.add("child") child2 = child.add("child") # import pytest; pytest.set_trace() assert child.child('child') == child2
def test_change_slug_duplicate(self, client): """ change a slug """ aaa = Node.root().add("aaa") aaa.add("bbb") node = aaa.add("bbb2") py.test.raises(DuplicatePathException, node.rename, "bbb") assert node.slug() == "bbb2"
def test_copy_content_node_unique_sub(self, client): root = Node.root() sub = root.add("sub") Type1(title="content on sub", node=sub).save() subc1 = sub.add("c1") TypeUnique(uniek="unique content on sub/c1", node=subc1).save() subc2 = sub.add("c2") Type1(title="content on sub/c2", node=subc2).save() subunique = subc1.add("subunique") sub2, success, failed = root.paste(sub, copy=True) assert len(sub2.children()) == 1 assert Node.get(sub2.path + "/c1/subunique") is None assert len(success) == 2 assert len(failed) == 1
def test_duplicate_content_different_languages(self, client): """ two content objects for different languages can point to the same node """ root = Node.root() child1 = root.add("n1") Type1(node=child1, language="nl").save() child1.set(Type1(language="fr").save())
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'))
def test_move_node_inuse(self, client, root): """ pasting a node to a node containing a child with the same name, e.g. pasting /foo to /target when there's already a /target/foo """ src = root.add("src") src_c = src.add("child") target = root.add("target") target_src = target.add("src") # import pytest; pytest.set_trace() res, success, failed = target.paste(src) assert Node.get('/target/src') == target_src assert src.path != "/src" assert src.path != "/target/src" assert Node.get(src.path + "/child")