~chaghi/zim/zim-profiles

« back to all changes in this revision

Viewing changes to tests/notebook.py

  • Committer: Mariano Draghi
  • Date: 2012-03-11 14:22:19 UTC
  • Revision ID: mdraghi@gmail.com-20120311142219-g2duoislgwt1w4oa
Fixed location for signal 'preferences-changed'. Added some unit-tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
import os
10
10
 
11
11
from zim.fs import File, Dir
12
 
from zim.config import config_file
 
12
from zim.config import config_file, ConfigDictFile, XDG_CONFIG_HOME
13
13
from zim.notebook import *
14
14
from zim.index import *
15
15
import zim.errors
16
16
from zim.formats import ParseTree
17
17
 
18
 
from zim import _get_default_or_only_notebook
 
18
from zim import NotebookInterface, _get_default_or_only_notebook
19
19
        # private, but want to check it anyway
20
20
 
21
21
 
745
745
 
746
746
                text = ''.join(notebook.get_page(Path('page3:page1:child')).dump('wiki'))
747
747
                self.assertEqual(text, 'I have backlinks !\n')
 
748
 
 
749
 
 
750
class TestProfiles(tests.TestCase):
 
751
 
 
752
        def setUp(self):
 
753
                path = self.get_tmp_name()
 
754
                self.notebook = tests.new_notebook(fakedir=path)
 
755
 
 
756
        def testProfilePreferences(self):
 
757
                '''Test the profile is used and its preferences applied'''
 
758
                # set up a test profile
 
759
                file = XDG_CONFIG_HOME.file('zim/profiles/profile_TestProfile.conf')
 
760
                if file.exists():
 
761
                        file.remove()
 
762
                assert not file.exists()
 
763
                profile = ConfigDictFile(file)
 
764
                profile['GtkInterface'] = {}
 
765
                profile['General']['plugins'] = ['calendar',]
 
766
                profile['CalendarPlugin']['embedded'] = True
 
767
                profile['CalendarPlugin']['granularity'] = 'Week'
 
768
                profile['CalendarPlugin']['namespace'] = 'TestProfile'
 
769
                profile.write()
 
770
 
 
771
                # se the profile name in the notebook, open it, and
 
772
                # check that the profila was applied
 
773
                self.notebook.config['Notebook']['profile'] = 'profile_TestProfile'
 
774
                self.assertEqual(self.notebook.profile, 'profile_TestProfile')
 
775
                interface = NotebookInterface(self.notebook)
 
776
                self.assertEqual(interface.preferences.file, file)
 
777
                self.assertTrue(len(interface.preferences['GtkInterface'].keys()) == 0)
 
778
                self.assertTrue(len(interface.plugins) == 1)
 
779
                self.assertEqual(interface.preferences['General']['plugins'][0],
 
780
                                   'calendar')
 
781
                self.assertTrue(interface.preferences['CalendarPlugin']['embedded'])
 
782
                self.assertEqual(interface.preferences['CalendarPlugin']['granularity'],
 
783
                                   'Week')
 
784
                self.assertEqual(interface.preferences['CalendarPlugin']['namespace'],
 
785
                                   'TestProfile')
 
786
 
 
787