'Ensure build_json_data uses rendered HTML when available to extract
sections generated by KumaScript (bug 982174)'

def test_bug_982174(self):

    r = revision(title='Document    with    sections', slug='document-with-sections', is_approved=True, save=True)
    d = r.document
    d.html = "\n                                                <h2>Section    1</h2>\n                                                <p>Foo</p>\n                                                {{    h2_macro('Section    2')    }}\n                                                <p>Bar</p>\n                                                <h2>Section    3</h2>\n                                                <p>Foo</p>\n                                "
    d.save()
    json_data = d.build_json_data()
    expected_sections = [{'id': 'Section_1', 'title': 'Section    1'}, {'id': 'Section_3', 'title': 'Section    3'}]
    eq_(expected_sections, json_data['sections'])
    d.rendered_html = '\n                                                <h2>Section    1</h2>\n                                                <p>Foo</p>\n                                                <h2>Section    2</h2>\n                                                <p>Bar</p>\n                                                <h2>Section    3</h2>\n                                                <p>Foo</p>\n                                '
    d.save()
    json_data = d.build_json_data()
    expected_sections = [{'id': 'Section_1', 'title': 'Section    1'}, {'id': 'Section_2', 'title': 'Section    2'}, {'id': 'Section_3', 'title': 'Section    3'}]
    eq_(expected_sections, json_data['sections'])
