コード例 #1
0
    def testAttachFileResolveExistingFile(self):
        folder = self.setUpFolder(mock=tests.MOCK_ALWAYS_REAL)
        file = folder.file('Attachment.abc')
        file.write('Test ABC\n')

        attach_folder = self.notebook.get_attachments_dir(self.page)
        conflict_file = attach_folder.file('Attachment.abc')
        conflict_file.write('Conflict\n')

        def attach_file(dialog):
            dialog.set_file(file)
            dialog.assert_response_ok()

        def resolve_conflict(dialog):
            dialog.set_input(name='NewName.abc')
            dialog.assert_response_ok()

        with tests.DialogContext(attach_file, resolve_conflict):
            self.uiactions.attach_file()

        attach_file = attach_folder.file('NewName.abc')
        self.assertTrue(attach_file.exists())
        self.assertEqual(attach_file.read(), file.read())

        self.assertEqual(conflict_file.read(), 'Conflict\n')
コード例 #2
0
    def testDeletePageWithTrash(self):
        self.assertTrue(self.page.exists())

        with tests.DialogContext():  # fails if dialog shown
            self.uiactions.delete_page()

        self.assertFalse(self.page.exists())
コード例 #3
0
    def testEditPageSource(self):
        from zim.gui.widgets import MessageDialog
        from zim.newfs import LocalFile
        from zim.gui.applications import ApplicationManager

        oldtext = self.page.dump('plain')  # trick page into caching content
        signals = tests.SignalLogger(self.page)

        def edit_page(cmd):
            file = LocalFile(cmd[-1])
            self.assertEqual(file, self.page.source_file)
            file.write('New text\n')

        manager = ApplicationManager()
        entry = manager.create('text/plain', 'test', 'test')
        manager.set_default_application('text/plain', entry)

        with tests.ApplicationContext(edit_page):
            with tests.DialogContext(MessageDialog):
                self.uiactions.edit_page_source()

        newtext = self.page.dump('plain')
        self.assertEqual(signals['storage-changed'],
                         [(True, )])  # boolean for external change
        self.assertNotEqual(oldtext, newtext)
コード例 #4
0
    def testShowRecentChangesDialog(self):
        def use_recent_changes(dialog):
            # Check view
            model = dialog.treeview.get_model()
            pages = set(r[0] for r in model)
            self.assertEqual(pages, {'Test', 'ExistingPage'})

            # TODO: how can we check rendering of date column ?

            # Check live update
            page = self.notebook.get_page(Path('NewPage'))
            page.parse('wiki', 'TEst 123')
            self.notebook.store_page(page)

            pages = set(r[0] for r in model)
            self.assertEqual(pages, {'NewPage', 'Test', 'ExistingPage'})

            # Check opening a page
            col = dialog.treeview.get_column(0)
            dialog.treeview.row_activated(Gtk.TreePath((0, )), col)

        with tests.DialogContext(use_recent_changes):
            self.uiactions.show_recent_changes()

        self.assertEqual(self.navigation.opened, Path('NewPage'))
コード例 #5
0
ファイル: tableeditor.py プロジェクト: hjq300/zim-wiki
	def runTest(self):
		window = tests.MockObject()
		window.pageview = setUpPageView()
		window.ui = tests.MockObject()
		window.ui.uimanager = tests.MockObject()
		window.ui.uistate = ConfigDict()
		window.ui.mainwindow = window # XXX

		plugin = TableEditorPlugin()
		extension = MainWindowExtension(plugin, window)

		with tests.DialogContext(self.checkInsertTableDialog):
			extension.insert_table()

		tree = window.pageview.get_parsetree()
		#~ print tree.tostring()
		obj = tree.find('table')

		self.assertTrue(obj.attrib['aligns'] == 'left')
		self.assertTrue(obj.attrib['wraps'] == '0')

		# Parses tree to a table object
		tabledata = tree.tostring().replace("<?xml version='1.0' encoding='utf-8'?>", '')\
			.replace('<zim-tree>', '').replace('</zim-tree>', '')\
			.replace('<td> </td>', '<td>text</td>')

		table = plugin.create_table({'type': 'table'}, ElementTree.fromstring(tabledata))

		self.assertTrue(isinstance(table, TableViewObject))
コード例 #6
0
    def testTrashPage(self):
        self.assertTrue(self.page.exists())

        with tests.DialogContext(TrashPageDialog):
            self.uiactions.delete_page()

        self.assertFalse(self.page.exists())
コード例 #7
0
    def testExceptionHandlerWithGtk(self):
        def error_dialog_with_trace(dialog):
            self.assertIsInstance(dialog, ErrorDialog)
            self.assertTrue(dialog.showing_trace)

        def error_dialog_without_trace(dialog):
            self.assertIsInstance(dialog, ErrorDialog)
            self.assertFalse(dialog.showing_trace)

        zim.errors.set_use_gtk(True)
        try:
            self.assertTrue(zim.errors.use_gtk_errordialog)
            with tests.DialogContext(
                    error_dialog_with_trace,
                    error_dialog_with_trace,
                    error_dialog_without_trace,
                    error_dialog_without_trace,
            ):
                with tests.LoggingFilter(logger='zim.gui',
                                         message='Running ErrorDialog'):
                    self.testExceptionHandler()
        except:
            zim.errors.set_use_gtk(False)
            raise
        else:
            zim.errors.set_use_gtk(False)
            self.assertFalse(zim.errors.use_gtk_errordialog)
コード例 #8
0
    def testEditCustomTool(self):
        config = ConfigManager()
        manager = CustomToolManager(config)
        mytool = {
            'Name': 'Edit',
            'Comment': 'Test Edit',
            'X-Zim-ExecTool': 'edit %f',
        }
        manager.create(**mytool)
        self.assertIsNotNone(manager.get_tool('Edit'))

        def edit_tool(dialog):
            dialog.set_input(Comment='Editted Comment')
            dialog.assert_response_ok()

        dialog = CustomToolManagerDialog(None, config)
        #model = dialog.listview.get_model()
        #self.assertIn('Edit', [r[CustomToolList.NAME_COL] for r in model])
        with tests.DialogContext(edit_tool):
            dialog.listview.select_by_name('Edit')
            dialog.on_edit()
            dialog.assert_response_ok()

        tool = manager.get_tool('Edit')
        self.assertEqual(tool.comment, 'Editted Comment')
コード例 #9
0
    def testAddCustomTool(self):
        config = ConfigManager()
        manager = CustomToolManager(config)
        mytool = {
            'Name': 'Add',
            'Comment': 'Test Add',
            'X-Zim-ExecTool': 'add %f',
            'X-Zim-ReadOnly': False,
            'X-Zim-ShowInToolBar': False,
            'X-Zim-ReplaceSelection': False,
        }

        self.assertIsNone(manager.get_tool('Add'))

        def add_tool(dialog):
            dialog.set_input(**mytool)
            dialog.assert_response_ok()

        dialog = CustomToolManagerDialog(None, config)
        with tests.DialogContext(add_tool):
            dialog.on_add()
            dialog.assert_response_ok()

        # XXX listview intialization fails in test ???
        #model = dialog.listview.get_model()
        #self.assertIn('Add', [r[CustomToolList.NAME_COL] for r in model])

        tool = manager.get_tool('Add')
        self.assertIsNotNone(tool)
        for key, value in list(mytool.items()):
            self.assertEqual(tool['Desktop Entry'][key], value)
コード例 #10
0
    def runTest(self):
        from zim.gui.mainwindow import MainWindow

        ## Without argument should prompt
        def testAddNotebookDialog(dialog):
            self.assertIn(dialog.__class__.__name__,
                          ('AddNotebookDialog', 'NotebookDialog'))

        cmd = GuiCommand('gui')
        with tests.DialogContext(testAddNotebookDialog):
            cmd.run(
            )  # Exits without running due to no notebook given in dialog

        ### Try again with argument
        folder = self.setUpFolder(mock=tests.MOCK_ALWAYS_REAL)
        folder.touch()

        cmd = GuiCommand('gui')
        cmd.parse_options(folder.path)
        with tests.WindowContext(MainWindow):
            with tests.LoggingFilter('zim', 'Exception while loading plugin:'):
                window = cmd.run()
                self.addCleanup(window.destroy)

        self.assertEqual(window.__class__.__name__, 'MainWindow')
        self.assertEqual(window.notebook.uri, folder.uri)
        self.assertGreaterEqual(
            len(ConfigManager.preferences['General']['plugins']), 3)
        self.assertGreaterEqual(len(window.pageview.__zim_extension_objects__),
                                3)

        with tests.WindowContext(MainWindow):
            window2 = cmd.run()
        self.assertIs(window2, window)
コード例 #11
0
    def testOpenAnotherNotebook(self):
        from zim.gui.notebookdialog import NotebookDialog

        def check_dialog_shown(dialog):
            assert isinstance(dialog, NotebookDialog)

        with tests.DialogContext(check_dialog_shown):
            self.uiactions.show_open_notebook()
コード例 #12
0
    def testOpenNewWindow(self):
        self.uiactions.widget = setUpMainWindow(self.notebook)

        def pagewindow(window):
            window.pageview.page == self.page

        with tests.DialogContext(pagewindow):
            self.uiactions.open_new_window()
コード例 #13
0
    def testShowExport(self):
        from zim.gui.exportdialog import ExportDialog

        def check_dialog_shown(dialog):
            assert isinstance(dialog, ExportDialog)

        with tests.DialogContext(check_dialog_shown):
            self.uiactions.show_export()
コード例 #14
0
    def testDeletePage(self):
        self.notebook.config['Notebook']['disable_trash'] = True
        self.assertTrue(self.page.exists())

        with tests.DialogContext(DeletePageDialog):
            self.uiactions.delete_page()

        self.assertFalse(self.page.exists())
コード例 #15
0
    def testShowPreferencesDialog(self):
        from zim.gui.preferencesdialog import PreferencesDialog
        from zim.plugins import PluginManager

        self.uiactions.widget = Gtk.Window()

        with tests.DialogContext(PreferencesDialog):
            self.uiactions.show_preferences()
コード例 #16
0
    def testOpenDocumentRootNotDefined(self):
        from zim.gui.widgets import ErrorDialog

        self.assertIsNone(self.notebook.document_root)

        with tests.LoggingFilter('zim', 'No document root defined'):
            with tests.ApplicationContext():
                with tests.DialogContext(ErrorDialog):
                    self.uiactions.open_document_root()
コード例 #17
0
    def testCreateNewPageFailsForExistingPage(self):
        from zim.notebook import PageExistsError

        def open_new_page(dialog):
            dialog.set_input(page='ExistingPage')
            self.assertRaises(PageExistsError, dialog.assert_response_ok)

        with tests.DialogContext(open_new_page):
            self.uiactions.new_page()
コード例 #18
0
    def testRenamePageFailsForExistingPage(self):
        from zim.notebook import PageExistsError

        def renamepage(dialog):
            dialog.set_input(name='ExistingPage')
            self.assertRaises(PageExistsError, dialog.do_response_ok)

        with tests.DialogContext(renamepage):
            self.uiactions.move_page()
コード例 #19
0
    def testRenamePageSameNameInvalidInput(self):
        self.assertEqual(self.page.basename, 'Test')

        def renamepage(dialog):
            dialog.set_input(name='Test')
            self.assertFalse(dialog.do_response_ok())

        with tests.DialogContext(renamepage):
            self.uiactions.move_page()
コード例 #20
0
    def testRenamePageNonExistingPageFails(self):
        from zim.notebook import PageNotFoundError
        page = self.notebook.get_page(Path('NonExistingPage'))

        def renamepage(dialog):
            dialog.set_input(name='NewName')
            self.assertRaises(PageNotFoundError, dialog.do_response_ok)

        with tests.DialogContext(renamepage):
            self.uiactions.rename_page(page)
コード例 #21
0
    def testOpenAttachmentsFolderExisting(self):
        folder = self.notebook.get_attachments_dir(self.page)
        folder.touch()

        def open_folder(cmd):
            self.assertEqual(cmd[-1], folder.path)

        with tests.ApplicationContext(open_folder):
            with tests.DialogContext():
                self.uiactions.open_attachments_folder()
コード例 #22
0
    def testMovePageNonExistingPageFails(self):
        from zim.notebook import PageNotFoundError
        page = self.notebook.get_page(Path('NonExistingPage'))

        def movepage(dialog):
            dialog.set_input(parent='NewParent')
            self.assertRaises(PageNotFoundError, dialog.do_response_ok)

        with tests.DialogContext(movepage):
            self.uiactions.move_page(page)
コード例 #23
0
    def testDeletePageWithTrashUpdateLinks(self):
        referrer = self.notebook.get_page(Path('Referrer'))
        referrer.parse('wiki', 'Test [[Test]]\n')
        self.notebook.store_page(referrer)

        with tests.DialogContext():  # fails if dialog shown
            self.uiactions.delete_page()

        self.assertFalse(self.page.exists())
        self.assertEqual(referrer.dump('wiki'), ['Test Test\n'])
コード例 #24
0
    def testDeletePageWithoutTrashCancel(self):
        self.notebook.config['Notebook']['disable_trash'] = True

        def do_delete(dialog):
            dialog.do_response_cancel()

        with tests.DialogContext(do_delete):
            self.uiactions.delete_page()

        self.assertTrue(self.page.exists())
コード例 #25
0
    def testTrashPageCancel(self):
        self.assertTrue(self.page.exists())

        def cancel_delete(dialog):
            assert isinstance(dialog, TrashPageDialog)
            dialog.do_response_cancel()

        with tests.DialogContext(cancel_delete):
            self.uiactions.delete_page()

        self.assertTrue(self.page.exists())
コード例 #26
0
    def testMovePageSameParentInvalidInput(self):
        page = self.notebook.get_page(Path('SomeParent:MyPage'))
        page.parse('wiki', 'test 123\n')
        self.notebook.store_page(page)

        def movepage(dialog):
            dialog.set_input(parent='SomeParent')
            self.assertFalse(dialog.do_response_ok())

        with tests.DialogContext(movepage):
            self.uiactions.move_page(page)
コード例 #27
0
ファイル: tableeditor.py プロジェクト: hjq300/zim-wiki
	def testChangeTable(self):
		attrib = {'aligns': 'normal,normal', 'wraps': '0,0'}
		header = ['h1', 'h2']
		rows = [['t1', 't2'],]
		obj = TableViewObject(attrib, header, rows, {})
		widget = obj.get_widget()

		with tests.DialogContext(self.checkUpdateTableDialog):
			widget.on_change_columns(None)

		self.assertTrue(isinstance(widget.treeview, gtk.TreeView))
コード例 #28
0
    def testOpenNewWindowWithPage(self):
        self.uiactions.widget = setUpMainWindow(self.notebook)

        page = self.notebook.get_page(Path('OtherPage'))
        self.assertNotEqual(page, self.page)

        def pagewindow(window):
            window.pageview.page == page

        with tests.DialogContext(pagewindow):
            self.uiactions.open_new_window(page)
コード例 #29
0
ファイル: uiactions.py プロジェクト: gygy/zim-desktop-wiki
	def testOpenDocumentRoot(self):
		from zim.gui.widgets import ErrorDialog
		self.notebook.document_root = self.setUpFolder(mock=tests.MOCK_ALWAYS_REAL)
		self.notebook.document_root.touch()

		def open_folder(cmd):
			self.assertEqual(cmd[-1], self.notebook.document_root.path)

		with tests.ApplicationContext(open_folder):
			with tests.DialogContext():
				self.uiactions.open_document_root()
コード例 #30
0
        def testAddNotebook(dialog):
            self.assertTrue(isinstance(dialog, NotebookDialog))

            with tests.DialogContext(doAddNotebook):
                dialog.do_add_notebook()

            dialog.combobox.set_active(0)

            selection = dialog.treeview.get_selection()
            selection.select_path((1, ))  # select newly added notebook
            dialog.assert_response_ok()