def process_raw_upload(target_sandbox):
    test_dir = os.path.dirname(os.path.realpath(__file__))
    base_dir = os.path.join(test_dir, os.pardir)
    sandbox_dir = os.path.join(base_dir, target_sandbox)
    raw_file = os.path.join(sandbox_dir, 'raw.conf')

    if not os.path.exists(raw_file):
        print('[sandbox] missing file', raw_file)
        return

    doc_dir = prepare_dirs('sandbox-raw')
    with prepare_sphinx(sandbox_dir, out_dir=doc_dir, relax=True) as app:
        publisher = ConfluencePublisher()
        publisher.init(app.config)
        publisher.connect()

        while True:
            data = {
                'labels': [],
            }

            with io.open(raw_file, 'r', encoding='utf-8') as f:
                data['content'] = f.read()

            print('[sandbox] publishing page...')
            try:
                publisher.store_page('raw', data)
            except ConfluenceBadApiError as ex:
                print('[sandbox] failed to publish content:', ex)

            print('[sandbox] any key to retry; q to quit')
            if input().lower() == 'q':
                break
Esempio n. 2
0
    def test_translator_docname_and_docparent(self):
        mock_ds = os.path.join(self.test_dir, 'datasets', 'common')
        mock_docpath = os.path.join(mock_ds, 'foo', 'bar', 'baz.rst')
        doc = DummyDocument(mock_docpath)

        # prepare a dummy application; no need to actually build
        with prepare_sphinx(mock_ds, config=self.config) as app:
            translator = ConfluenceBaseTranslator(doc, app.builder)

        self.assertEqual(translator.docname, 'foo/bar/baz')
        self.assertEqual(translator.docparent, 'foo/bar/')
    def prepare(self, *args, **kwargs):
        """
        helper to invoke `prepare_sphinx` with decorator configured options

        Args:
            *args: argument values to forward
            **kwargs: kw-argument values to forward
        """

        new_kwargs = dict(kwargs)
        new_kwargs.setdefault('builder', self.builder)
        new_kwargs.setdefault('config', self.config)

        return prepare_sphinx(*args, **new_kwargs)
Esempio n. 4
0
    def test_confluence_metadata_directive(self):
        with prepare_sphinx(self.dataset, config=self.config) as app:
            app.build(filenames=self.filenames)
            builder_metadata = app.builder.metadata

            self.assertTrue(builder_metadata)
            self.assertTrue('metadata' in builder_metadata)
            doc_labels = builder_metadata['metadata']

            self.assertTrue(doc_labels)
            self.assertTrue('labels' in doc_labels)

            labels = doc_labels['labels']
            self.assertEqual(len(labels), 2)
            self.assertTrue('tag-a' in labels)
            self.assertTrue('tag-c' in labels)
Esempio n. 5
0
    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()