def testOpenNotebookFolder(self): def open_folder(cmd): self.assertEqual(strip_file_url_prefix(cmd[-1]), self.notebook.folder.path) with tests.ApplicationContext(open_folder): self.uiactions.open_notebook_folder()
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)
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()
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()
def testBrowseTemplates(self): dialog = TemplateEditorDialog(None) def open_folder(args): got = LocalFolder(args[-1]) want = LocalFolder(XDG_DATA_HOME.subdir('zim/templates').path) self.assertEqual(got, want) with tests.ApplicationContext(open_folder): dialog.on_browse()
def testViewTemplate(self): dialog = TemplateEditorDialog(None) select_by_name(dialog.view, 'foo_test') def open_file(args): got = LocalFile(args[-1]) want = LocalFile(XDG_DATA_HOME.file('zim/templates/html/foo_test.html').path) self.assertEqual(got, want) with tests.ApplicationContext(open_file): dialog.on_view()
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()
def testOpenAttachmentsFolderNonExisting(self): folder = self.notebook.get_attachments_dir(self.page) self.assertFalse(folder.exists()) def create_folder(dialog): dialog.answer_yes() def open_folder(cmd): self.assertEqual(cmd[-1], folder.path) with tests.ApplicationContext(open_folder): with tests.DialogContext(create_folder): self.uiactions.open_attachments_folder()
def testExecuteCustomToolAction(self): mymanager = CustomToolManager() mytool = { 'Name': 'Edit', 'Comment': 'Test Edit', 'X-Zim-ExecTool': 'edit %f', } mymanager.create(**mytool) action = self.get_action('edit-usercreated') def tool_run(args): self.assertEqual(args[0], 'edit') with tests.ApplicationContext(tool_run): action.activate()
def testExecuteCustomToolActionModifyPage(self): mymanager = CustomToolManager() mytool = { 'Name': 'Edit', 'Comment': 'Test Edit', 'X-Zim-ExecTool': 'edit %s', 'X-Zim-ReadOnly': False, } mymanager.create(**mytool) action = self.get_action('edit-usercreated') def tool_run(args): self.assertEqual(args[0], 'edit') self.pageview.page.source_file.write('test 123') with tests.ApplicationContext(tool_run): action.activate()
def testExecuteCustomToolActionReplaceSelection(self): mymanager = CustomToolManager() mytool = { 'Name': 'Edit', 'Comment': 'Test Edit', 'X-Zim-ExecTool': 'edit %f', 'X-Zim-ReplaceSelection': True, } tool = mymanager.create(**mytool) self.assertTrue(tool.replaceselection) action = self.get_action('edit-usercreated') got = [] self.pageview.replace_selection = lambda *a: got.append(a) def tool_run(args): self.assertEqual(args[0], 'edit') return "TEST 123" with tests.ApplicationContext(tool_run): action.activate() self.assertEqual(got, [('TEST 123', )])