'Moving a tree of documents does the correct thing'

@pytest.mark.move
def test_move_tree(self):

    top = revision(title='Top-level    parent    for    tree    moves', slug='first-level/parent', is_approved=True, save=True)
    old_top_id = top.id
    top_doc = top.document
    child1 = revision(title='First    child    of    tree-move    parent', slug='first-level/second-level/child1', is_approved=True, save=True)
    old_child1_id = child1.id
    child1_doc = child1.document
    child1_doc.parent_topic = top_doc
    child1_doc.save()
    child2 = revision(title='Second    child    of    tree-move    parent', slug='first-level/second-level/child2', is_approved=True, save=True)
    old_child2_id = child2.id
    child2_doc = child2.document
    child2_doc.parent_topic = top_doc
    child2.save()
    grandchild = revision(title='Child    of    second    child    of    tree-move    parent', slug='first-level/second-level/third-level/grandchild', is_approved=True, save=True)
    old_grandchild_id = grandchild.id
    grandchild_doc = grandchild.document
    grandchild_doc.parent_topic = child2_doc
    grandchild_doc.save()
    revision(title='New    Top-level    bucket    for    tree    moves', slug='new-prefix', is_approved=True, save=True)
    revision(title='New    first-level    parent    for    tree    moves', slug='new-prefix/first-level', is_approved=True, save=True)
    top_doc._move_tree('new-prefix/first-level/parent')
    moved_top = Document.objects.get(pk=top_doc.id)
    eq_('new-prefix/first-level/parent', moved_top.current_revision.slug)
    ok_((old_top_id != moved_top.current_revision.id))
    ok_((moved_top.current_revision.slug in Document.objects.get(slug='first-level/parent').get_redirect_url()))
    moved_child1 = Document.objects.get(pk=child1_doc.id)
    eq_('new-prefix/first-level/parent/child1', moved_child1.current_revision.slug)
    ok_((old_child1_id != moved_child1.current_revision.id))
    ok_((moved_child1.current_revision.slug in Document.objects.get(slug='first-level/second-level/child1').get_redirect_url()))
    moved_child2 = Document.objects.get(pk=child2_doc.id)
    eq_('new-prefix/first-level/parent/child2', moved_child2.current_revision.slug)
    ok_((old_child2_id != moved_child2.current_revision.id))
    ok_((moved_child2.current_revision.slug in Document.objects.get(slug='first-level/second-level/child2').get_redirect_url()))
    moved_grandchild = Document.objects.get(pk=grandchild_doc.id)
    eq_('new-prefix/first-level/parent/child2/grandchild', moved_grandchild.current_revision.slug)
    ok_((old_grandchild_id != moved_grandchild.current_revision.id))
    ok_((moved_grandchild.current_revision.slug in Document.objects.get(slug='first-level/second-level/third-level/grandchild').get_redirect_url()))
