示例#1
0
文件: gui.py 项目: Jam71/Zim-QDA
	def runTest(self):
		from zim.gui.notebookdialog import prompt_notebook, \
			AddNotebookDialog, NotebookDialog

		tmpdir = self.create_tmp_dir()
		dir1 = Dir(tmpdir + '/mynotebook1')
		dir2 = Dir(tmpdir + '/mynotebook2')

		# First time we get directly the AddNotebookDialog
		def doAddNotebook(dialog):
			self.assertTrue(isinstance(dialog, AddNotebookDialog))
			dialog.form['name'] = 'Foo'
			dialog.form['folder'] = dir1.path
			dialog.assert_response_ok()

		with tests.DialogContext(doAddNotebook):
			self.assertEqual(prompt_notebook(), dir1.uri)

		# Second time we get the list
		def testNotebookDialog(dialog):
			self.assertTrue(isinstance(dialog, NotebookDialog))
			selection = dialog.treeview.get_selection()
			selection.select_path((0,)) # select first and only notebook
			dialog.assert_response_ok()

		with tests.DialogContext(testNotebookDialog):
			self.assertEqual(prompt_notebook(), dir1.uri)

		# Third time we add a notebook and set the default
		def doAddNotebook(dialog):
			self.assertTrue(isinstance(dialog, AddNotebookDialog))
			dialog.form['name'] = 'Bar'
			dialog.form['folder'] = dir2.path
			dialog.assert_response_ok()

		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()

		with tests.DialogContext(testAddNotebook):
			self.assertEqual(prompt_notebook(), dir2.uri)

		# Check the notebook exists and the notebook list looks like it should
		for dir in (dir1, dir2):
			self.assertTrue(dir.exists())
			self.assertTrue(dir.file('notebook.zim').exists())

		list = get_notebook_list()
		self.assertTrue(len(list) == 2)
		self.assertEqual(list[0], NotebookInfo(dir1.uri, name='Foo'))
		self.assertEqual(list[1], NotebookInfo(dir2.uri, name='Bar'))
		self.assertEqual(list.default, NotebookInfo(dir1.uri, name='Foo'))

		# Now unset the default and again check the notebook list
		def unsetDefault(dialog):
			self.assertTrue(isinstance(dialog, NotebookDialog))
			dialog.combobox.set_active(-1)
			selection = dialog.treeview.get_selection()
			selection.select_path((1,)) # select newly added notebook
			dialog.assert_response_ok()

		with tests.DialogContext(unsetDefault):
			self.assertEqual(prompt_notebook(), dir2.uri)

		list = get_notebook_list()
		self.assertTrue(len(list) == 2)
		self.assertTrue(list.default is None)
示例#2
0
    def runTest(self):
        from zim.gui.notebookdialog import prompt_notebook, \
         AddNotebookDialog, NotebookDialog

        tmpdir = self.create_tmp_dir()
        dir1 = Dir(tmpdir + '/mynotebook1')
        dir2 = Dir(tmpdir + '/mynotebook2')

        # First time we get directly the AddNotebookDialog
        def doAddNotebook(dialog):
            self.assertTrue(isinstance(dialog, AddNotebookDialog))
            dialog.form['name'] = 'Foo'
            dialog.form['folder'] = dir1.path
            dialog.assert_response_ok()

        with tests.DialogContext(doAddNotebook):
            info = prompt_notebook()
            self.assertIsNotNone(info)
            self.assertEqual(info.uri, dir1.uri)

        # Second time we get the list
        def testNotebookDialog(dialog):
            self.assertTrue(isinstance(dialog, NotebookDialog))
            selection = dialog.treeview.get_selection()
            selection.select_path((0, ))  # select first and only notebook
            dialog.assert_response_ok()

        with tests.DialogContext(testNotebookDialog):
            info = prompt_notebook()
            self.assertIsNotNone(info)
            self.assertEqual(info.uri, dir1.uri)

        # Third time we add a notebook and set the default
        def doAddNotebook(dialog):
            self.assertTrue(isinstance(dialog, AddNotebookDialog))
            dialog.form['name'] = 'Bar'
            dialog.form['folder'] = dir2.path
            dialog.assert_response_ok()

        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()

        with tests.DialogContext(testAddNotebook):
            info = prompt_notebook()
            self.assertIsNotNone(info)
            self.assertEqual(info.uri, dir2.uri)

        # Check the notebook exists and the notebook list looks like it should
        for dir in (dir1, dir2):
            self.assertTrue(dir.exists())
            self.assertTrue(dir.file('notebook.zim').exists())

        list = get_notebook_list()
        self.assertTrue(len(list) == 2)
        self.assertEqual(list[0], NotebookInfo(dir1.uri, name='Foo'))
        self.assertEqual(list[1], NotebookInfo(dir2.uri, name='Bar'))
        self.assertEqual(list.default, NotebookInfo(dir1.uri, name='Foo'))

        # Now unset the default and again check the notebook list
        def unsetDefault(dialog):
            self.assertTrue(isinstance(dialog, NotebookDialog))
            dialog.combobox.set_active(-1)
            selection = dialog.treeview.get_selection()
            selection.select_path((1, ))  # select newly added notebook
            dialog.assert_response_ok()

        with tests.DialogContext(unsetDefault):
            info = prompt_notebook()
            self.assertIsNotNone(info)
            self.assertEqual(info.uri, dir2.uri)

        list = get_notebook_list()
        self.assertTrue(len(list) == 2)
        self.assertTrue(list.default is None)