'bug 875349'

def test_children_view(self):

    test_content = '<p>Test    <a    href="http://example.com">Summary</a></p>'
    def _make_doc(title, slug, parent=None, is_redir=False):
        doc = document(title=title, slug=slug, save=True, is_redirect=is_redir)
        if is_redir:
            content = 'REDIRECT    <a    class="redirect"    href="/en-US/blah">Blah</a>'
        else:
            content = test_content
            revision(document=doc, content=test_content, summary=get_seo_description(test_content, strip_markup=False), save=True)
        doc.html = content
        if parent:
            doc.parent_topic = parent
        doc.save()
        return doc
    root_doc = _make_doc('Root', 'Root')
    child_doc_1 = _make_doc('Child    1', 'Root/Child_1', root_doc)
    _make_doc('Grandchild    1', 'Root/Child_1/Grandchild_1', child_doc_1)
    grandchild_doc_2 = _make_doc('Grandchild    2', 'Root/Child_1/Grandchild_2', child_doc_1)
    _make_doc('Great    Grandchild    1', 'Root/Child_1/Grandchild_2/Great_Grand_Child_1', grandchild_doc_2)
    _make_doc('Child    2', 'Root/Child_2', root_doc)
    _make_doc('Child    3', 'Root/Child_3', root_doc, True)
    Switch.objects.create(name='application_ACAO', active=True)
    for expand in (True, False):
        url = reverse('wiki.children', args=['Root'], locale=settings.WIKI_DEFAULT_LANGUAGE)
        if expand:
            url = ('%s?expand' % url)
        resp = self.client.get(url)
        ok_(('Access-Control-Allow-Origin' in resp))
        eq_('*', resp['Access-Control-Allow-Origin'])
        json_obj = json.loads(resp.content)
        eq_(json_obj['slug'], 'Root')
        if (not expand):
            ok_(('summary' not in json_obj))
        else:
            eq_(json_obj['summary'], 'Test    <a    href="http://example.com">Summary</a>')
            ok_(('tags' in json_obj))
            ok_(('review_tags' in json_obj))
        eq_(len(json_obj['subpages']), 2)
        eq_(len(json_obj['subpages'][0]['subpages']), 2)
        eq_(json_obj['subpages'][0]['subpages'][1]['title'], 'Grandchild    2')
    def _depth_test(depth, aught):
        url = ((reverse('wiki.children', args=['Root'], locale=settings.WIKI_DEFAULT_LANGUAGE) + '?depth=') + str(depth))
        resp = self.client.get(url)
        json_obj = json.loads(resp.content)
        eq_(len(json_obj['subpages'][0]['subpages'][1]['subpages']), aught)
    _depth_test(2, 0)
    _depth_test(3, 1)
    _depth_test(6, 1)
    sort_root_doc = _make_doc('Sort    Root', 'Sort_Root')
    _make_doc('B    Child', 'Sort_Root/B_Child', sort_root_doc)
    _make_doc('A    Child', 'Sort_Root/A_Child', sort_root_doc)
    resp = self.client.get(reverse('wiki.children', args=['Sort_Root'], locale=settings.WIKI_DEFAULT_LANGUAGE))
    json_obj = json.loads(resp.content)
    eq_(json_obj['subpages'][0]['title'], 'A    Child')
    no_doc_url = reverse('wiki.children', args=['nonexistentDocument'], locale=settings.WIKI_DEFAULT_LANGUAGE)
    resp = self.client.get(no_doc_url)
    result = json.loads(resp.content)
    eq_(result, {'error': 'Document    does    not    exist.'})
    _make_doc('Old    Name', 'Old    Name', is_redir=True)
    redirect_doc_url = reverse('wiki.children', args=['Old    Name'], locale=settings.WIKI_DEFAULT_LANGUAGE)
    resp = self.client.get(redirect_doc_url)
    result = json.loads(resp.content)
    eq_(result, {'error': 'Document    has    moved.'})
