Merge lp:~mandel/ubuntu-sso-client/proxy-creds-windows into lp:ubuntu-sso-client

Proposed by Manuel de la Peña
Status: Merged
Approved by: Roberto Alsina
Approved revision: 936
Merged at revision: 931
Proposed branch: lp:~mandel/ubuntu-sso-client/proxy-creds-windows
Merge into: lp:ubuntu-sso-client
Diff against target: 241 lines (+168/-18)
2 files modified
ubuntu_sso/qt/proxy_dialog.py (+31/-2)
ubuntu_sso/qt/tests/test_proxy_dialog.py (+137/-16)
To merge this branch: bzr merge lp:~mandel/ubuntu-sso-client/proxy-creds-windows
Reviewer Review Type Date Requested Status
Brian Curtin (community) Approve
Roberto Alsina (community) Approve
Diego Sarmentero (community) Approve
Review via email: mp+98481@code.launchpad.net

Commit message

- Fixed dialog on window by using show so that the QEventLoop does not block the execution of the main loop of the reactor which did not allow the deferreds to be fired (LP: #960481)

Description of the change

- Fixed dialog on window by using show so that the QEventLoop does not block the execution of the main loop of the reactor which did not allow the deferreds to be fired (LP: #960481)

Please test that the dialog works on both platforms in IRL by doing

PYTHONPATH=. python bin/ubuntu-sso-proxy-creds-qt --domamin test_domain

To post a comment you must log in.
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve
Revision history for this message
Roberto Alsina (ralsina) wrote :

There is no need to log in line 50, and am slightly concerned about having win32-specific bits here, but since this is "just a script" and has no modules where we could stash platform-specific bits, I am giving it a +1.

Maybe we can file a bug to refactor those bits away.

review: Approve
Revision history for this message
Brian Curtin (brian.curtin) wrote :

Refactoring post-release would be nice. IRL testing on Windows worked well.

review: Approve
Revision history for this message
Brian Curtin (brian.curtin) wrote :

I entered #960529 to keep track of the refactoring.

Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (69.0 KiB)

The attempt to merge lp:~mandel/ubuntu-sso-client/proxy-creds-windows into lp:ubuntu-sso-client failed. Below is the output from the failed tests.

*** Running GTK test suite for ubuntu_sso ***
ubuntu_sso.xdg_base_directory.tests.test_common
  TestBaseDirectory
    test_load_config_paths_filter ... [OK]
    test_save_config_path ... [OK]
    test_xdg_cache_home_is_utf8_bytes ... [OK]
    test_xdg_config_dirs_are_bytes ... [OK]
    test_xdg_config_home_is_utf8_bytes ... [OK]
    test_xdg_data_dirs_are_bytes ... [OK]
    test_xdg_data_home_is_utf8_bytes ... [OK]
    test_xdg_home_is_utf8_bytes ... [OK]
twisted.trial.unittest
  TestCase
    runTest ... [OK]
ubuntu_sso.gtk.tests.test_main
  BasicTestCase
    test_main ... [OK]
twisted.trial.unittest
  TestCase
    runTest ... [OK]
ubuntu_sso.gtk.tests.test_gui
  BasicTestCase
    runTest ... [OK]
  BasicUbuntuSSOClientTestCase
    test_app_name_is_stored ... [OK]
    test_cancel_buttons_close_window ... [OK]
    test_close_callback_if_not_set ... [OK]
    test_closing_main_window_calls_close_callback ... [OK]
    test_entries_activates_default ... [OK]
    test_finish_error_shows_error_page ... [OK]
    test_finish_success_shows_success_page ... [OK]
    test_initial_text_for_entries ... [OK]
    test_main_window_is_resizable ... [OK]
    test_main_window_is_visible_at_startup ... [OK]
    test_pages_are_packed_into_container ... [OK]
    test_password_fields_are_password ... [OK]
    test_signals_are_removed ... [OK]
    test_warning_fields_are_cleared ... [OK]
    test_window_icon ... [OK]
  DefaultButtonsTestCase
    test_default_widget_can_default ... [OK]
    test_pages_have_default_widget_set ... [OK]
    test_set_current_page_grabs_focus_for_default_button ... [OK]
  EnterDetailsTestCase
    test_captcha_filename_is_different_each_time ... [OK]
    test_captcha_id_is_stored_when_captcha_is_available ... [OK]
    test_captcha_image_is_a_spinner_at_first ... [OK]
    test_captcha_image_is_not_visible_at_startup ... ...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/qt/proxy_dialog.py'
2--- ubuntu_sso/qt/proxy_dialog.py 2012-03-08 12:35:25 +0000
3+++ ubuntu_sso/qt/proxy_dialog.py 2012-03-20 18:35:21 +0000
4@@ -106,6 +106,7 @@
5 except Exception, e:
6 logger.exception('Could not set credentials:')
7 self.done(EXCEPTION_RAISED)
8+ logger.debug('Stored creds')
9 # pylint: disable=W0703, W0612
10 self.done(USER_SUCCESS)
11
12@@ -140,13 +141,41 @@
13 return parser.parse_args()
14
15
16+def exit_code(return_code):
17+ """Use the window result code and the sys.exit."""
18+ logger.debug('exit %s', return_code)
19+ QApplication.instance().exit(return_code)
20+ if sys.platform == 'win32':
21+ logger.debug('Stop qt reactor')
22+ from twisted.internet import reactor
23+ reactor.stop()
24+
25+
26 def main():
27 """Main method used to show the creds dialog."""
28 # Keep ref to avoid core dump, pylint: disable=W0612
29+
30+ if sys.platform == 'win32':
31+ import qt4reactor
32+ qt4reactor.install()
33+ logger.debug('Qt reactor installed.')
34+
35 app = QApplication(sys.argv)
36 # pylint: enable=W0612
37 args = parse_args()
38 win = ProxyCredsDialog(domain=args.domain,
39 retry=args.retry)
40- return_code = win.exec_()
41- sys.exit(return_code)
42+
43+ if sys.platform == 'win32':
44+ win.show()
45+ win.finished.connect(exit_code)
46+
47+ logger.debug('Starting reactor')
48+ # pylint: disable=E1101
49+ from twisted.internet import reactor
50+ logger.debug('QApp is %s', reactor.qApp)
51+ reactor.run()
52+ # pylint: enable=E1101
53+ else:
54+ return_code = win.exec_()
55+ sys.exit(return_code)
56
57=== modified file 'ubuntu_sso/qt/tests/test_proxy_dialog.py'
58--- ubuntu_sso/qt/tests/test_proxy_dialog.py 2012-03-07 18:13:04 +0000
59+++ ubuntu_sso/qt/tests/test_proxy_dialog.py 2012-03-20 18:35:21 +0000
60@@ -15,7 +15,10 @@
61 # with this program. If not, see <http://www.gnu.org/licenses/>.
62 """Test the proxy UI."""
63
64-from twisted.internet import defer
65+import qt4reactor
66+
67+from PyQt4.QtCore import QObject, pyqtSignal
68+from twisted.internet import defer, reactor
69 from twisted.trial.unittest import TestCase
70
71 from ubuntu_sso.qt import proxy_dialog
72@@ -301,6 +304,62 @@
73 self.retry = retry
74
75
76+class FakeCredsDialog(QObject):
77+ """A fake dialog."""
78+
79+ finished = pyqtSignal(int)
80+
81+ def __init__(self, called, code):
82+ """Create a new instance."""
83+ super(FakeCredsDialog, self).__init__()
84+ self.domain = None
85+ self.retry = None
86+ self.called = called
87+ self.return_code = code
88+
89+ def __call__(self, domain, retry):
90+ """Fake init."""
91+ self.domain = domain
92+ self.retry = retry
93+ return self
94+
95+ def show(self):
96+ """Show the dialog."""
97+ self.called.append(('show',))
98+
99+ def exec_(self):
100+ """Show the dialog."""
101+ self.called.append(('exec_',))
102+ return self.return_code
103+
104+
105+class FakeQApplication(object):
106+ """A fake QApplication."""
107+
108+ test_instance = None
109+
110+ def __init__(self, called):
111+ """Create a new instance."""
112+ self.called = called
113+ self.args = None
114+ self.code = None
115+ FakeQApplication.test_instance = self
116+
117+ def __call__(self, args):
118+ """Fake construntor."""
119+ self.args = args
120+
121+ @classmethod
122+ def instance(cls):
123+ """Return the instance."""
124+ return FakeQApplication.test_instance
125+
126+ def exit(self, code):
127+ """Exit the app."""
128+ self.called.append(('exit', code))
129+ self.code = code
130+
131+
132 class MainTest(TestCase):
133 """Test the main method."""
134
135@@ -310,29 +369,91 @@
136 yield super(MainTest, self).setUp()
137 self.called = []
138
139+ self.return_code = 0
140+ self.dialog = FakeCredsDialog(self.called, self.return_code)
141+ self.patch(proxy_dialog, 'ProxyCredsDialog', self.dialog)
142+
143 self.args = FakeArgs(domain='domain', retry=False)
144 self.patch(proxy_dialog, 'parse_args', lambda: self.args)
145
146- self.return_code = 0
147- self.patch(proxy_dialog.ProxyCredsDialog, 'exec_', lambda x:
148- self.return_code)
149 self.exit_code = None
150
151+ self.app = FakeQApplication(self.called)
152+
153+ self.patch(proxy_dialog, 'QApplication', self.app)
154+
155+ def _set_old_platform(self, platform):
156+ """Set back the platform."""
157+ proxy_dialog.sys.platform = platform
158+
159+ def _assert_basic_start(self):
160+ """Assert the common code is actually ran."""
161+ self.assertEqual(self.args.domain, self.dialog.domain)
162+ self.assertEqual(self.args.retry, self.dialog.retry)
163+
164+ def test_linux_main(self):
165+ """Test the main method on linux."""
166+ old_platform = proxy_dialog.sys.platform
167+ proxy_dialog.sys.platform = 'linux'
168+ self.addCleanup(self._set_old_platform, old_platform)
169+
170 def fake_exit(code):
171- """Fake the sys.exit."""
172+ """Fake sys exit."""
173 self.called.append(('exit', code))
174- self.exit_code = code
175
176 self.patch(proxy_dialog.sys, 'exit', fake_exit)
177
178- def fake_application(args):
179- """Fake a QApplication."""
180- self.called.append(('QApplication', args))
181-
182- self.patch(proxy_dialog, 'QApplication', fake_application)
183-
184- def test_main(self):
185- """Test the main method."""
186- proxy_dialog.main()
187- self.assertIn('QApplication', self.called[0])
188+ proxy_dialog.main()
189+
190+ self._assert_basic_start()
191+ self.assertIn(('exec_',), self.called)
192+ self.assertIn(('exit', self.return_code), self.called)
193+
194+ def test_windows_main(self):
195+ """Test the main method on windows."""
196+ old_platform = proxy_dialog.sys.platform
197+ proxy_dialog.sys.platform = 'win32'
198+ self.addCleanup(self._set_old_platform, old_platform)
199+
200+ def fake_install():
201+ """Fake the reactor installation."""
202+ self.called.append(('install',))
203+
204+ self.patch(qt4reactor, 'install', fake_install)
205+
206+ def fake_start():
207+ """Fake reactor.start."""
208+ self.called.append(('run',))
209+
210+ self.patch(reactor, 'run', fake_start)
211+
212+ def fake_exit(code):
213+ """Fake the exit method."""
214+ self.called.append(('exit_code', code))
215+
216+ self.patch(proxy_dialog, 'exit_code', fake_exit)
217+
218+ proxy_dialog.main()
219+
220+ self._assert_basic_start()
221+ self.assertIn(('show',), self.called)
222+ self.assertIn(('run',), self.called)
223+
224+ self.dialog.finished.emit(self.return_code)
225+ self.assertIn(('exit_code', self.return_code), self.called)
226+
227+ def test_exit_code_windows(self):
228+ """"Test the exit code function."""
229+ old_platform = proxy_dialog.sys.platform
230+ proxy_dialog.sys.platform = 'win32'
231+ self.addCleanup(self._set_old_platform, old_platform)
232+
233+ def fake_stop():
234+ """Fake reactor.start."""
235+ self.called.append(('stop',))
236+
237+ self.patch(reactor, 'stop', fake_stop)
238+
239+ proxy_dialog.exit_code(self.return_code)
240+ self.assertIn(('stop',), self.called)
241 self.assertIn(('exit', self.return_code), self.called)

Subscribers

People subscribed via source and target branches