fix for Bug #11210
[wifi-assistant] / package / test / unit / settings / application_settings_test.py
1 from gnome import gconf
2 from wifi_assistant.settings.application_settings import ApplicationSettings
3
4 import unittest
5
6 class ApplicationSettingsTest(unittest.TestCase):
7
8     def setUp(self):
9         self.gc = gconf.client_get_default()
10         self.root = '/apps/maemo/wifi/unit_tests'
11         self._clearGConf(self.root)
12         self._setupDefaultValues(self.root)
13         self._firstCallbackCalled = None
14         self._secondCallbackCalled = None
15         self.testee = ApplicationSettings(self.gc, self.root)
16         
17     def _setupDefaultValues(self, dir):
18         self.gc.set_bool(dir + '/daemon', True)
19
20     # FIXME: inherit
21     def _clearGConf(self, dir):
22         # there's no recursive_unset available
23         all_entries = self.gc.all_entries(dir)
24         for entry in all_entries:
25             self.gc.unset(entry.get_key())
26         for sub_dir in self.gc.all_dirs(dir):
27             self._clearGConf(sub_dir)
28         self.gc.suggest_sync()
29         
30
31     def test_default_is_to_use_popup(self):
32         assert self.testee.getUsePopup() is True
33     
34     
35     def test_setting_use_popup_works(self):
36         assert self.testee.getUsePopup() is True
37
38         self.testee.setUsePopup(False)
39         assert self.testee.getUsePopup() is False
40
41         self.testee.setUsePopup(True)
42         assert self.testee.getUsePopup() is True
43         
44     
45     def dont_test_adding_two_listeners_removing_one_still_notifies_first_listener(self):
46         firstSignal = False
47         secondSignal = True
48         
49         self.testee.registerUsePopupListener(self._firstCallback)
50         self.testee.registerUsePopupListener(self._secondCallback)
51         
52         # TODO: start thread to have signalling work properly ... 
53         
54         self.testee.setUsePopup(firstSignal)
55         
56         assert self._firstCallbackCalled == firstSignal
57         assert self._secondCallbackCalled == firstSignal
58     
59         self.testee.unregisterUsePopupListener(self._secondCallback)
60         self.testee.setUsePopup(secondSignal)
61         
62         assert self._firstCallbackCalled == secondSignal
63         assert self._secondCallbackCalled == firstSignal
64         
65     
66     def _firstCallback(self, value):
67         self._firstCallbackCalled = value
68         
69     def _secondCallback(self, value):
70         self._secondCallbackCalled = value
71     
72     
73 if __name__ == '__main__':
74     unittest.main()
75