|
| 1 | +# SPDX-License-Identifier: BSD-2-Clause |
| 2 | +# Copyright Sphinx Confluence Builder Contributors (AUTHORS) |
| 3 | + |
| 4 | +from bs4 import BeautifulSoup |
| 5 | +from bs4 import CData |
| 6 | +from tests.lib.parse import parse |
| 7 | +from tests.lib.testcase import ConfluenceTestCase |
| 8 | +from tests.lib.testcase import setup_builder |
| 9 | + |
| 10 | + |
| 11 | +class TestConfluenceHtml(ConfluenceTestCase): |
| 12 | + @classmethod |
| 13 | + def setUpClass(cls): |
| 14 | + super().setUpClass() |
| 15 | + |
| 16 | + cls.dataset = cls.datasets / 'html' |
| 17 | + |
| 18 | + @setup_builder('confluence') |
| 19 | + def test_storage_confluence_html_custom_macro(self): |
| 20 | + config = dict(self.config) |
| 21 | + config['confluence_html_macro'] = 'custom-html' |
| 22 | + out_dir = self.build(self.dataset, config=config) |
| 23 | + |
| 24 | + with parse('index', out_dir) as data: |
| 25 | + html_macro = data.find('ac:structured-macro', |
| 26 | + {'ac:name': 'custom-html'}) |
| 27 | + self.assertIsNotNone(html_macro) |
| 28 | + |
| 29 | + plain_body = html_macro.find('ac:plain-text-body') |
| 30 | + self.assertIsNotNone(plain_body) |
| 31 | + |
| 32 | + html_macro_cdata = next(plain_body.children, None) |
| 33 | + self.assertIsNotNone(html_macro_cdata) |
| 34 | + self.assertTrue(isinstance(html_macro_cdata, CData)) |
| 35 | + |
| 36 | + html_macro_data = BeautifulSoup(html_macro_cdata, 'html.parser') |
| 37 | + |
| 38 | + strong_element = html_macro_data.find('strong') |
| 39 | + self.assertIsNotNone(strong_element) |
| 40 | + text_contents = strong_element.text.strip() |
| 41 | + self.assertIsNotNone(text_contents) |
| 42 | + self.assertTrue('strong text' in text_contents) |
| 43 | + |
| 44 | + @setup_builder('confluence') |
| 45 | + def test_storage_confluence_html_default(self): |
| 46 | + out_dir = self.build(self.dataset) |
| 47 | + |
| 48 | + with parse('index', out_dir) as data: |
| 49 | + html_macro = data.find('ac:structured-macro', {'ac:name': 'html'}) |
| 50 | + self.assertIsNotNone(html_macro) |
| 51 | + |
| 52 | + plain_body = html_macro.find('ac:plain-text-body') |
| 53 | + self.assertIsNotNone(plain_body) |
| 54 | + |
| 55 | + html_macro_cdata = next(plain_body.children, None) |
| 56 | + self.assertIsNotNone(html_macro_cdata) |
| 57 | + self.assertTrue(isinstance(html_macro_cdata, CData)) |
| 58 | + |
| 59 | + html_macro_data = BeautifulSoup(html_macro_cdata, 'html.parser') |
| 60 | + |
| 61 | + strong_element = html_macro_data.find('strong') |
| 62 | + self.assertIsNotNone(strong_element) |
| 63 | + text_contents = strong_element.text.strip() |
| 64 | + self.assertIsNotNone(text_contents) |
| 65 | + self.assertTrue('strong text' in text_contents) |
0 commit comments