def test_publish_subset(self): builder = ConfluenceBuilder(self.app) builder.config.source_suffix = { '.rst': 'restructuredtext', } builder.config.confluence_publish_subset = 'doc' # expect list-like with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) builder.config.confluence_publish_subset = [True, False] with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) builder.config.confluence_publish_subset = ['admonitions.rst'] with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) builder.config.confluence_publish_subset = ['admonitions'] try: builder.init(suppress_conf_check=True) except ConfluenceConfigurationError: self.fail('configuration exception raised with valid subset') # explicitly force unicode strings to help verify python 2.x series # dealing with unicode strings inside the document subset builder.config.confluence_publish_subset = [u'admonitions'] try: builder.init(suppress_conf_check=True) except ConfluenceConfigurationError: self.fail('configuration exception raised with unicode subset')
def test_manual_publish(self): self.app.config['confluence_publish'] = True builder = ConfluenceBuilder(self.app) builder.init() for docname in self.docnames: builder.info("\033[01mpublishing '%s'...\033[0m" % docname) output_filename = os.path.join(self.out, docname + '.conf') with open(output_filename, 'r') as output_file: output = output_file.read() builder.publish_doc(docname, output) builder.finish()
def test_invalid_ca_cert(self): builder = ConfluenceBuilder(self.app) ca_cert = os.path.join(self.test_dir, 'certs', 'non_existant.crt') builder.config.confluence_publish = True builder.config.confluence_ca_cert = ca_cert builder.config.confluence_server_url = "some_url" builder.config.confluence_space_name = "some_space_name" with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) builder.config.confluence_publish = False builder.config.confluence_ca_cert = None builder.config.confluence_server_url = None builder.config.confluence_space_name = None
def test_invalid_ca_cert(self): builder = ConfluenceBuilder(self.app) ca_cert = os.path.join(self.test_dir, 'certs', 'non_existant.crt') builder.config.confluence_publish = True builder.config.confluence_ca_cert = ca_cert builder.config.confluence_server_url = "some_url" builder.config.confluence_space_name = "some_space_name" with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) builder.config.confluence_publish = False builder.config.confluence_ca_cert = None builder.config.confluence_server_url = None builder.config.confluence_space_name = None
def test_missing_templates(self): builder = ConfluenceBuilder(self.app) template_dir = os.path.join(self.test_dir, 'templates') tpl = os.path.join(template_dir, 'sample-header-x.tpl') builder.config.confluence_header_file = tpl with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) tpl = os.path.join(template_dir, 'sample-header.tpl') builder.config.confluence_header_file = tpl try: builder.init(suppress_conf_check=True) except ConfluenceConfigurationError: self.fail("configuration exception raised with valid header") builder.config.confluence_header_file = None tpl = os.path.join(template_dir, 'sample-footer-x.tpl') builder.config.confluence_header_file = tpl with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) tpl = os.path.join(template_dir, 'sample-footer.tpl') builder.config.confluence_header_file = tpl try: builder.init(suppress_conf_check=True) except ConfluenceConfigurationError: self.fail("configuration exception raised with valid footer") builder.config.confluence_footer_file = None
def test_too_many_client_certs(self): builder = ConfluenceBuilder(self.app) this_file = os.path.realpath(__file__) cert = (this_file, this_file, this_file) builder.config.confluence_publish = True builder.config.confluence_client_cert = cert builder.config.confluence_server_url = "some_url" builder.config.confluence_space_name = "some_space_name" with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) builder.config.confluence_publish = False builder.config.confluence_client_cert = None builder.config.confluence_server_url = None builder.config.confluence_space_name = None
def test_manual_publish(self): self.app.config['confluence_publish'] = True builder = ConfluenceBuilder(self.app) builder.init() for docname in self.docnames: if self.single_docname and self.single_docname != docname: continue ConfluenceLogger.info("\033[01mpublishing '%s'...\033[0m" % docname) output_filename = os.path.join(self.out, docname + '.conf') with io.open(output_filename, encoding='utf8') as output_file: output = output_file.read() builder.publish_doc(docname, output) builder.finish()
def test_too_many_client_certs(self): builder = ConfluenceBuilder(self.app) this_file = os.path.realpath(__file__) cert = (this_file, this_file, this_file) builder.config.confluence_publish = True builder.config.confluence_client_cert = cert builder.config.confluence_server_url = "some_url" builder.config.confluence_space_name = "some_space_name" with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) builder.config.confluence_publish = False builder.config.confluence_client_cert = None builder.config.confluence_server_url = None builder.config.confluence_space_name = None
def test_format_client_cert(self): builder = ConfluenceBuilder(self.app) this_file = os.path.realpath(__file__) builder.config.confluence_publish = True ca_cert = os.path.join(self.test_dir, 'certs', 'non_existant.crt') builder.config.confluence_client_cert = this_file builder.config.confluence_server_url = "http://somehost/" builder.config.confluence_space_name = "some_space_name" builder.config.confluence_ca_cert = ca_cert with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) self.assertEqual(len(builder.config.confluence_client_cert), 2) self.assertEqual(builder.config.confluence_client_cert, (this_file, None)) builder.config.confluence_publish = False builder.config.confluence_client_cert = None builder.config.confluence_ca_cert = None builder.config.confluence_server_url = None builder.config.confluence_space_name = None
def test_format_client_cert(self): builder = ConfluenceBuilder(self.app) this_file = os.path.realpath(__file__) builder.config.confluence_publish = True ca_cert = os.path.join(self.test_dir, 'certs', 'non_existant.crt') builder.config.confluence_client_cert = this_file builder.config.confluence_server_url = "http://somehost/" builder.config.confluence_space_name = "some_space_name" builder.config.confluence_ca_cert = ca_cert with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) self.assertEqual(len(builder.config.confluence_client_cert), 2) self.assertEqual(builder.config.confluence_client_cert, (this_file, None)) builder.config.confluence_publish = False builder.config.confluence_client_cert = None builder.config.confluence_ca_cert = None builder.config.confluence_server_url = None builder.config.confluence_space_name = None
def _try_config(self, config=None, edefs=None, dataset=None): config = config if config else self.minimal_config dataset = dataset if dataset else self.dataset with prepare_sphinx(dataset, config=config, extra_config=edefs) as app: builder = ConfluenceBuilder(app) class MockedPublisher: def init(self, config, cloud=None): pass def connect(self): pass def disconnect(self): pass builder.publisher = MockedPublisher() for k, v in self.config.items(): setattr(builder.config, k, v) builder.init()
def test_publish_subset(self): with self._build_app() as app: builder = ConfluenceBuilder(app) builder.config.source_suffix = { '.rst': 'restructuredtext', } builder.config.confluence_publish_subset = 'doc' # expect list-like with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) builder.config.confluence_publish_subset = [True, False] with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) builder.config.confluence_publish_subset = ['admonitions.rst'] with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) builder.config.confluence_publish_subset = ['admonitions'] try: builder.init(suppress_conf_check=True) except ConfluenceConfigurationError: self.fail('configuration exception raised with valid subset')
def test_publish_subset(self): with self._build_app() as app: builder = ConfluenceBuilder(app) builder.config.source_suffix = { '.rst': 'restructuredtext', } builder.config.confluence_publish_subset = 'doc' # expect list-like with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) builder.config.confluence_publish_subset = [True, False] with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) builder.config.confluence_publish_subset = ['admonitions.rst'] with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) builder.config.confluence_publish_subset = ['admonitions'] try: builder.init(suppress_conf_check=True) except ConfluenceConfigurationError: self.fail('configuration exception raised with valid subset')
def test_publish(self): builder = ConfluenceBuilder(self.app) builder.config.confluence_publish = True with self.assertRaises(ConfluenceConfigurationError): builder.init()
def test_emptyconfig(self): builder = ConfluenceBuilder(self.app) try: builder.init(suppress_conf_check=True) except ConfluenceConfigurationError: self.fail("configuration exception raised with valid config")
def test_publish_config(self): builder = ConfluenceBuilder(self.app) builder.config.confluence_publish = True with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True)
def test_emptyconfig(self): builder = ConfluenceBuilder(self.app) try: builder.init(suppress_conf_check=True) except ConfluenceConfigurationError: self.fail("configuration exception raised with valid config")
def test_missing_templates(self): builder = ConfluenceBuilder(self.app) template_dir = os.path.join(self.test_dir, 'templates') tpl = os.path.join(template_dir, 'sample-header-x.tpl') builder.config.confluence_header_file = tpl with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) tpl = os.path.join(template_dir, 'sample-header.tpl') builder.config.confluence_header_file = tpl try: builder.init(suppress_conf_check=True) except ConfluenceConfigurationError: self.fail("configuration exception raised with valid header") builder.config.confluence_header_file = '../templates/sample-header.tpl' try: builder.init(suppress_conf_check=True) except ConfluenceConfigurationError: self.fail("configuration exception raised with valid header") builder.config.confluence_header_file = None tpl = os.path.join(template_dir, 'sample-footer-x.tpl') builder.config.confluence_footer_file = tpl with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) tpl = os.path.join(template_dir, 'sample-footer.tpl') builder.config.confluence_footer_file = tpl try: builder.init(suppress_conf_check=True) except ConfluenceConfigurationError: self.fail("configuration exception raised with valid footer") builder.config.confluence_footer_file = '../templates/sample-footer.tpl' try: builder.init(suppress_conf_check=True) except ConfluenceConfigurationError: self.fail("configuration exception raised with valid header") builder.config.confluence_footer_file = None
def test_publish_lists(self): builder = ConfluenceBuilder(self.app) config = builder.config config.source_suffix = { '.rst': 'restructuredtext', } assets_dir = os.path.join(self.test_dir, 'assets') invalid_list = os.path.join(assets_dir, 'sample-invalid-publish-list') missing_list = os.path.join(assets_dir, 'sample-missing-publish-list') valid_list = os.path.join(assets_dir, 'sample-valid-publish-list') options = [ 'confluence_publish_allowlist', 'confluence_publish_denylist', ] for option in options: # empty value (string; ignore state) setattr(config, option, '') try: builder.init(suppress_conf_check=True) except ConfluenceConfigurationError: self.fail('configuration exception raised with ' 'empty (string) list: ' + option) # empty value (list; ignore state) setattr(config, option, []) try: builder.init(suppress_conf_check=True) except ConfluenceConfigurationError: self.fail('configuration exception raised with ' 'empty (list) list: ' + option) # document list with valid entries setattr(config, option, ['admonitions']) try: builder.init(suppress_conf_check=True) except ConfluenceConfigurationError: self.fail('configuration exception raised with ' 'valid document list: ' + option) # explicitly force unicode strings to help verify python 2.x series # dealing with unicode strings inside the document subset setattr(config, option, [u'admonitions']) try: builder.init(suppress_conf_check=True) except ConfluenceConfigurationError: self.fail('configuration exception raised with ' 'valid document (unicode) list: ' + option) # file with a valid document list self.assertTrue(os.path.isfile(valid_list)) setattr(config, option, valid_list) try: builder.init(suppress_conf_check=True) except ConfluenceConfigurationError: self.fail('configuration exception raised with ' 'valid document file list: ' + option) # invalid content setattr(config, option, True) with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) # list with invalid content setattr(config, option, [True, False]) with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) # missing document setattr(config, option, ['missing']) with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) # use of file extension setattr(config, option, ['admonitions.rst']) with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) # file with invalid document list self.assertTrue(os.path.isfile(invalid_list)) setattr(config, option, invalid_list) with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) # missing file self.assertFalse(os.path.isfile(missing_list)) setattr(config, option, missing_list) with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True) # clear back to the default state setattr(config, option, None)
def test_publish_config(self): builder = ConfluenceBuilder(self.app) builder.config.confluence_publish = True with self.assertRaises(ConfluenceConfigurationError): builder.init(suppress_conf_check=True)