Example #1
0
    def testDialog(self):
        '''Test ExportDialog'''
        from zim.gui.exportdialog import ExportDialog, ExportDoneDialog

        dir = Dir(self.create_tmp_dir())

        notebook = tests.new_notebook(fakedir='/foo/bar')

        ui = tests.MockObject()
        ui.notebook = notebook
        ui.page = Path('foo')
        ui.uistate = SectionedConfigDict()

        ## Test export all pages
        dialog = ExportDialog(ui)
        dialog.set_page(0)

        page = dialog.get_page()
        page.form['selection'] = 'all'
        dialog.next_page()

        page = dialog.get_page()
        page.form['format'] = 'HTML'
        page.form['template'] = 'Print'
        dialog.next_page()

        page = dialog.get_page()
        page.form['folder'] = dir
        page.form['index'] = 'INDEX_PAGE'
        with tests.DialogContext(ExportDoneDialog):
            dialog.assert_response_ok()

        file = dir.file('Test/foo.html')
        self.assertTrue(file.exists())
        text = file.read()
        self.assertTrue('<!-- Wiki content -->' in text, 'template used')
        self.assertTrue('<h1>Foo</h1>' in text)

        #~ print dialog.uistate
        self.assertEqual(dialog.uistate, ui.uistate['ExportDialog'])
        self.assertIsInstance(dialog.uistate['output_folder'], Dir)

        ## Test export single page
        dialog = ExportDialog(ui)
        dialog.set_page(0)

        page = dialog.get_page()
        page.form['selection'] = 'page'
        page.form['page'] = 'Test:foo'
        dialog.next_page()

        page = dialog.get_page()
        page.form['format'] = 'HTML'
        page.form['template'] = 'Print'
        dialog.next_page()

        page = dialog.get_page()
        page.form['file'] = dir.file('SINGLE_FILE_EXPORT.html').path
        with tests.DialogContext(ExportDoneDialog):
            dialog.assert_response_ok()

        file = dir.file('SINGLE_FILE_EXPORT.html')
        self.assertTrue(file.exists())
        text = file.read()
        self.assertTrue('<!-- Wiki content -->' in text, 'template used')
        self.assertTrue('<h1>Foo</h1>' in text)

        #~ print dialog.uistate
        self.assertEqual(dialog.uistate, ui.uistate['ExportDialog'])
        self.assertIsInstance(dialog.uistate['output_file'], File)
        self.assertIsInstance(dialog.uistate['output_folder'],
                              Dir)  # Keep this in state as well
Example #2
0
 def show_export(self):
     '''Menu action to show an L{ExportDialog}'''
     from zim.gui.exportdialog import ExportDialog
     if self.ensure_index_uptodate():
         ExportDialog(self.widget, self.notebook, self.page).run()
Example #3
0
	def runTest(self):
		'''Test ExportDialog'''
		from zim.gui.exportdialog import ExportDialog

		dir = Dir(self.create_tmp_dir())

		notebook = tests.new_notebook(fakedir='/foo/bar')

		ui = tests.MockObject()
		ui.notebook = notebook
		ui.page = Path('foo')
		ui.mainwindow = None
		ui.uistate = ConfigDict()

		## Test export all pages
		dialog = ExportDialog(ui)
		dialog.set_page(0)

		page = dialog.get_page()
		page.form['selection'] = 'all'
		dialog.next_page()

		page = dialog.get_page()
		page.form['format'] = 'HTML'
		page.form['template'] = 'Print'
		dialog.next_page()

		page = dialog.get_page()
		page.form['folder'] = dir
		page.form['index'] = 'INDEX_PAGE'
		dialog.assert_response_ok()

		file = dir.file('Test/foo.html')
		self.assertTrue(file.exists())
		text = file.read()
		self.assertTrue('<!-- Wiki content -->' in text, 'template used')
		self.assertTrue('<h1>Foo</h1>' in text)

		#~ print dialog.uistate
		self.assertEqual(dialog.uistate, ui.uistate['ExportDialog'])
		self.assertIsInstance(dialog.uistate['output_folder'], Dir)

		## Test export single page
		dialog = ExportDialog(ui)
		dialog.set_page(0)

		page = dialog.get_page()
		page.form['selection'] = 'page'
		page.form['page'] = 'Test:foo'
		dialog.next_page()

		page = dialog.get_page()
		page.form['format'] = 'HTML'
		page.form['template'] = 'Print'
		dialog.next_page()

		page = dialog.get_page()
		page.form['file'] = dir.file('SINGLE_FILE_EXPORT.html').path
		dialog.assert_response_ok()

		file = dir.file('SINGLE_FILE_EXPORT.html')
		self.assertTrue(file.exists())
		text = file.read()
		self.assertTrue('<!-- Wiki content -->' in text, 'template used')
		self.assertTrue('<h1>Foo</h1>' in text)

		#~ print dialog.uistate
		self.assertEqual(dialog.uistate, ui.uistate['ExportDialog'])
		self.assertIsInstance(dialog.uistate['output_file'], File)
		self.assertIsInstance(dialog.uistate['output_folder'], Dir) # Keep this in state as well
Example #4
0
    def testDialog(self):
        '''Test ExportDialog'''
        from zim.gui.exportdialog import ExportDialog, ExportDoneDialog

        dir = Dir(self.create_tmp_dir())
        notebook = self.setUpNotebook(content={
            'foo': 'test 123\n',
            'bar': 'test 123\n'
        })

        window = Gtk.Window()
        window.notebook = notebook

        ## Test export all pages
        dialog = ExportDialog(window, notebook, Path('foo'))
        dialog.set_page(0)

        page = dialog.get_page()
        page.form['selection'] = 'all'
        dialog.next_page()

        page = dialog.get_page()
        page.form['format'] = 'HTML'
        page.form['template'] = 'Print'
        dialog.next_page()

        page = dialog.get_page()
        page.form['folder'] = dir
        page.form['index'] = 'INDEX_PAGE'
        with tests.DialogContext(ExportDoneDialog):
            dialog.assert_response_ok()

        file = dir.file('foo.html')
        self.assertTrue(file.exists())
        text = file.read()
        self.assertTrue('<!-- Wiki content -->' in text, 'template used')

        #~ print dialog.uistate
        self.assertEqual(dialog.uistate, window.notebook.state['ExportDialog'])
        self.assertIsInstance(dialog.uistate['output_folder'], Dir)

        ## Test export single page
        dialog = ExportDialog(window, notebook, Path('foo'))
        dialog.set_page(0)

        page = dialog.get_page()
        page.form['selection'] = 'page'
        page.form['page'] = 'foo'
        dialog.next_page()

        page = dialog.get_page()
        page.form['format'] = 'HTML'
        page.form['template'] = 'Print'
        dialog.next_page()

        page = dialog.get_page()
        page.form['file'] = dir.file('SINGLE_FILE_EXPORT.html').path
        with tests.DialogContext(ExportDoneDialog):
            dialog.assert_response_ok()

        file = dir.file('SINGLE_FILE_EXPORT.html')
        self.assertTrue(file.exists())
        text = file.read()
        self.assertTrue('<!-- Wiki content -->' in text, 'template used')

        #~ print dialog.uistate
        self.assertEqual(dialog.uistate, window.notebook.state['ExportDialog'])
        self.assertIsInstance(dialog.uistate['output_file'], OldFile)
        self.assertIsInstance(dialog.uistate['output_folder'],
                              OldDir)  # Keep this in state as well