Exemple #1
0
    def execute(cls, options):
        options = cls.handle_options(options)

        try:
            if options.extract:
                MySQLExtractor(options).extract()
            if options.load:
                MediawikiLoader(options).load()
        finally:
            if not options.keep_dumps:
                shutil.rmtree(options.dump_dir)
Exemple #2
0
    def setUp(self):
        setup_basic_test()
        self.options = mock.Mock()
        # need test project with installed wiki app
        self.options.nbhd = 'Adobe'
        self.options.project = '--init--'

        nbhd = M.Neighborhood.query.get(name=self.options.nbhd)
        h.set_context(self.options.project, 'wiki', neighborhood=nbhd)

        # monkey-patch MediawikiLoader for test
        def pages(self):
            yield 1
            yield 2

        def history(self, page_dir):
            data = {
                1: [
                    {
                        'title': 'Test title',
                        'text': "'''bold''' ''italics''",
                        'page_id': 1,
                        'timestamp': '20120808000001',
                        'username': '******'
                    },
                    {
                        'title': 'Test title',
                        'text': "'''bold'''",
                        'page_id': 1,
                        'timestamp': '20120809000001',
                        'username': '******'
                    },
                ],
                2: [
                    {
                        'title': 'Main',
                        'text': "Main text rev 1",
                        'page_id': 2,
                        'timestamp': '20120808000001',
                        'username': '******'
                    },
                    {
                        'title': 'Main',
                        'text': "Main text rev 2",
                        'page_id': 2,
                        'timestamp': '20120809000001',
                        'username': '******'
                    },
                ],
            }
            for page in data[page_dir]:
                yield page

        def talk(self, page_dir):
            data = {
                1: {
                    'text': "''Talk page'' for page 1.",
                    'username': '******',
                    'timestamp': '20120809000001'
                },
                2: {
                    'text': "''Talk page'' for page 2.",
                    'username': '******',
                    'timestamp': '20120809000001'
                },
            }
            return data[page_dir]

        def attachments(self, *args, **kwargs):
            # make 'empty' iterator
            if False:
                yield

        MediawikiLoader._pages = pages
        MediawikiLoader._history = history
        MediawikiLoader._talk = talk
        MediawikiLoader._attachments = attachments
        self.loader = MediawikiLoader(self.options)
Exemple #3
0
class TestMediawikiLoader(object):
    def setUp(self):
        setup_basic_test()
        self.options = mock.Mock()
        # need test project with installed wiki app
        self.options.nbhd = 'Adobe'
        self.options.project = '--init--'

        nbhd = M.Neighborhood.query.get(name=self.options.nbhd)
        h.set_context(self.options.project, 'wiki', neighborhood=nbhd)

        # monkey-patch MediawikiLoader for test
        def pages(self):
            yield 1
            yield 2

        def history(self, page_dir):
            data = {
                1: [
                    {
                        'title': 'Test title',
                        'text': "'''bold''' ''italics''",
                        'page_id': 1,
                        'timestamp': '20120808000001',
                        'username': '******'
                    },
                    {
                        'title': 'Test title',
                        'text': "'''bold'''",
                        'page_id': 1,
                        'timestamp': '20120809000001',
                        'username': '******'
                    },
                ],
                2: [
                    {
                        'title': 'Main',
                        'text': "Main text rev 1",
                        'page_id': 2,
                        'timestamp': '20120808000001',
                        'username': '******'
                    },
                    {
                        'title': 'Main',
                        'text': "Main text rev 2",
                        'page_id': 2,
                        'timestamp': '20120809000001',
                        'username': '******'
                    },
                ],
            }
            for page in data[page_dir]:
                yield page

        def talk(self, page_dir):
            data = {
                1: {
                    'text': "''Talk page'' for page 1.",
                    'username': '******',
                    'timestamp': '20120809000001'
                },
                2: {
                    'text': "''Talk page'' for page 2.",
                    'username': '******',
                    'timestamp': '20120809000001'
                },
            }
            return data[page_dir]

        def attachments(self, *args, **kwargs):
            # make 'empty' iterator
            if False:
                yield

        MediawikiLoader._pages = pages
        MediawikiLoader._history = history
        MediawikiLoader._talk = talk
        MediawikiLoader._attachments = attachments
        self.loader = MediawikiLoader(self.options)

    def get_page(self, title):
        return WM.Page.query.get(app_config_id=context.app.config._id,
                                 title=title)

    def get_post(self, title):
        page = self.get_page(title)
        thread = M.Thread.query.get(ref_id=page.index_id())
        return M.Post.query.get(discussion_id=thread.discussion_id,
                                thread_id=thread._id)

    @skipif(module_not_available('mediawiki'))
    @mock.patch('allura.model.discuss.g.director')
    def test_load_pages(self, director):
        """Test that pages, edit history and talk loaded properly"""
        self.loader.load_pages()
        page = self.get_page('Test title')

        assert page.mod_date == datetime.strptime('20120809000001',
                                                  self.loader.TIMESTAMP_FMT)
        assert page.authors()[0].username == 'test-user'
        assert '**bold**' in page.text
        # _italics should be only in the first revision of page
        assert '_italics_' not in page

        page = page.get_version(1)
        assert '**bold** _italics_' in page.text
        assert page.mod_date == datetime.strptime('20120808000001',
                                                  self.loader.TIMESTAMP_FMT)
        assert page.authors()[0].username == 'test-user'

        page = self.get_page('Main')
        assert page.mod_date == datetime.strptime('20120809000001',
                                                  self.loader.TIMESTAMP_FMT)
        assert page.authors()[0].username == '*anonymous'
        assert 'Main text rev 2' in page.text

        page = page.get_version(1)
        assert page.mod_date == datetime.strptime('20120808000001',
                                                  self.loader.TIMESTAMP_FMT)
        assert page.authors()[0].username == '*anonymous'
        assert 'Main text rev 1' in page.text

        # Check that talk pages loaded
        post = self.get_post('Test title')
        assert post.timestamp == datetime.strptime('20120809000001',
                                                   self.loader.TIMESTAMP_FMT)
        assert post.author().username == 'test-user'
        assert '_Talk page_ for page 1.' in post.text

        post = self.get_post('Main')
        assert post.timestamp == datetime.strptime('20120809000001',
                                                   self.loader.TIMESTAMP_FMT)
        assert post.author().username == '*anonymous'
        assert '_Talk page_ for page 2.' in post.text
    def setUp(self):
        setup_basic_test()
        self.options = mock.Mock()
        # need test project with installed wiki app
        self.options.nbhd = 'Adobe'
        self.options.project = '--init--'

        nbhd = M.Neighborhood.query.get(name=self.options.nbhd)
        h.set_context(self.options.project, 'wiki', neighborhood=nbhd)

        # monkey-patch MediawikiLoader for test
        def pages(self):
            yield 1
            yield 2

        def history(self, page_dir):
            data = {
                1: [
                    {
                        'title': 'Test title',
                        'text': "'''bold''' ''italics''",
                        'page_id': 1,
                        'timestamp': '20120808000001',
                        'username': '******'
                    },
                    {
                        'title': 'Test title',
                        'text': "'''bold'''",
                        'page_id': 1,
                        'timestamp': '20120809000001',
                        'username': '******'
                    },
                ],
                2: [
                    {
                        'title': 'Main',
                        'text': "Main text rev 1",
                        'page_id': 2,
                        'timestamp': '20120808000001',
                        'username': '******'
                    },
                    {
                        'title': 'Main',
                        'text': "Main text rev 2",
                        'page_id': 2,
                        'timestamp': '20120809000001',
                        'username': '******'
                    },

                ],
            }
            for page in data[page_dir]:
                yield page

        def talk(self, page_dir):
            data = {
                1: {
                    'text': "''Talk page'' for page 1.",
                    'username': '******',
                    'timestamp': '20120809000001'
                },
                2: {
                    'text': "''Talk page'' for page 2.",
                    'username': '******',
                    'timestamp': '20120809000001'
                },
            }
            return data[page_dir]

        def attachments(self, *args, **kwargs):
            # make 'empty' iterator
            if False:
                yield

        MediawikiLoader._pages = pages
        MediawikiLoader._history = history
        MediawikiLoader._talk = talk
        MediawikiLoader._attachments = attachments
        self.loader = MediawikiLoader(self.options)
class TestMediawikiLoader(object):

    def setUp(self):
        setup_basic_test()
        self.options = mock.Mock()
        # need test project with installed wiki app
        self.options.nbhd = 'Adobe'
        self.options.project = '--init--'

        nbhd = M.Neighborhood.query.get(name=self.options.nbhd)
        h.set_context(self.options.project, 'wiki', neighborhood=nbhd)

        # monkey-patch MediawikiLoader for test
        def pages(self):
            yield 1
            yield 2

        def history(self, page_dir):
            data = {
                1: [
                    {
                        'title': 'Test title',
                        'text': "'''bold''' ''italics''",
                        'page_id': 1,
                        'timestamp': '20120808000001',
                        'username': '******'
                    },
                    {
                        'title': 'Test title',
                        'text': "'''bold'''",
                        'page_id': 1,
                        'timestamp': '20120809000001',
                        'username': '******'
                    },
                ],
                2: [
                    {
                        'title': 'Main',
                        'text': "Main text rev 1",
                        'page_id': 2,
                        'timestamp': '20120808000001',
                        'username': '******'
                    },
                    {
                        'title': 'Main',
                        'text': "Main text rev 2",
                        'page_id': 2,
                        'timestamp': '20120809000001',
                        'username': '******'
                    },

                ],
            }
            for page in data[page_dir]:
                yield page

        def talk(self, page_dir):
            data = {
                1: {
                    'text': "''Talk page'' for page 1.",
                    'username': '******',
                    'timestamp': '20120809000001'
                },
                2: {
                    'text': "''Talk page'' for page 2.",
                    'username': '******',
                    'timestamp': '20120809000001'
                },
            }
            return data[page_dir]

        def attachments(self, *args, **kwargs):
            # make 'empty' iterator
            if False:
                yield

        MediawikiLoader._pages = pages
        MediawikiLoader._history = history
        MediawikiLoader._talk = talk
        MediawikiLoader._attachments = attachments
        self.loader = MediawikiLoader(self.options)

    def get_page(self, title):
        return WM.Page.query.get(app_config_id=context.app.config._id,
                                 title=title)

    def get_post(self, title):
        page = self.get_page(title)
        thread = M.Thread.query.get(ref_id=page.index_id())
        return M.Post.query.get(discussion_id=thread.discussion_id,
                                thread_id=thread._id)

    @skipif(module_not_available('mediawiki'))
    @mock.patch('allura.model.discuss.g.director')
    def test_load_pages(self, director):
        """Test that pages, edit history and talk loaded properly"""
        self.loader.load_pages()
        page = self.get_page('Test title')

        assert page.mod_date == datetime.strptime('20120809000001',
                                                  self.loader.TIMESTAMP_FMT)
        assert page.authors()[0].username == 'test-user'
        assert '**bold**' in page.text
        # _italics should be only in the first revision of page
        assert '_italics_' not in page

        page = page.get_version(1)
        assert '**bold** _italics_' in page.text
        assert page.mod_date == datetime.strptime('20120808000001',
                                                  self.loader.TIMESTAMP_FMT)
        assert page.authors()[0].username == 'test-user'

        page = self.get_page('Main')
        assert page.mod_date == datetime.strptime('20120809000001',
                                                  self.loader.TIMESTAMP_FMT)
        assert page.authors()[0].username == '*anonymous'
        assert 'Main text rev 2' in page.text

        page = page.get_version(1)
        assert page.mod_date == datetime.strptime('20120808000001',
                                                  self.loader.TIMESTAMP_FMT)
        assert page.authors()[0].username == '*anonymous'
        assert 'Main text rev 1' in page.text

        # Check that talk pages loaded
        post = self.get_post('Test title')
        assert post.timestamp == datetime.strptime('20120809000001',
                                                   self.loader.TIMESTAMP_FMT)
        assert post.author().username == 'test-user'
        assert '_Talk page_ for page 1.' in post.text

        post = self.get_post('Main')
        assert post.timestamp == datetime.strptime('20120809000001',
                                                   self.loader.TIMESTAMP_FMT)
        assert post.author().username == '*anonymous'
        assert '_Talk page_ for page 2.' in post.text