Merge lp:~ralsina/ubuntu-sso-client/testability into lp:ubuntu-sso-client

Proposed by Roberto Alsina
Status: Merged
Approved by: Roberto Alsina
Approved revision: 959
Merged at revision: 954
Proposed branch: lp:~ralsina/ubuntu-sso-client/testability
Merge into: lp:ubuntu-sso-client
Diff against target: 92 lines (+35/-0)
3 files modified
bin/ubuntu-sso-login (+3/-0)
ubuntu_sso/qt/main/__init__.py (+4/-0)
ubuntu_sso/qt/main/tests/test_main.py (+28/-0)
To merge this branch: bzr merge lp:~ralsina/ubuntu-sso-client/testability
Reviewer Review Type Date Requested Status
Eric Casteleijn (community) Approve
Diego Sarmentero (community) Approve
Review via email: mp+105232@code.launchpad.net

Commit message

 - Enable -testability option through the TESTABILITY environment variable (Fixes LP:984964).

Description of the change

Enables -testability through a environment variable.

To test IRL you need the testability driver and start ussoc like this:

PYTHONPATH=. TESTABILITY=1 bin/ubuntu-sso-login

To post a comment you must log in.
957. By Roberto Alsina

oops

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

ubuntu_sso/qt/main/tests/test_main.py:
    155: [C0322, BasicTestCase.test_no_testability] Operator not preceded by a space
                environ['TESTABILITY']=''

review: Needs Fixing
958. By Roberto Alsina

lint

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve
959. By Roberto Alsina

lint

Revision history for this message
Eric Casteleijn (thisfred) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/ubuntu-sso-login'
2--- bin/ubuntu-sso-login 2012-04-09 17:38:24 +0000
3+++ bin/ubuntu-sso-login 2012-05-09 18:03:18 +0000
4@@ -49,11 +49,14 @@
5 # val = globals()[globalname]
6 # KeyError: 'ROUND_CEiLiNG'
7
8+import os
9 import sys
10
11 if sys.platform == 'win32':
12 from PyQt4 import QtGui
13 # need to create the QApplication before installing the reactor
14+ if os.environ.get('TESTABILITY', False):
15+ sys.argv.append('-testability')
16 QtGui.QApplication(sys.argv)
17
18 # pylint: disable=F0401
19
20=== modified file 'ubuntu_sso/qt/main/__init__.py'
21--- ubuntu_sso/qt/main/__init__.py 2012-04-18 10:52:46 +0000
22+++ ubuntu_sso/qt/main/__init__.py 2012-05-09 18:03:18 +0000
23@@ -28,6 +28,7 @@
24 # files in the program, then also delete it here.
25 """Main module to open the QT UI."""
26
27+import os
28 import sys
29
30 from PyQt4 import QtGui, QtCore
31@@ -52,6 +53,9 @@
32
33 def main(**kwargs):
34 """Start the QT mainloop and open the main window."""
35+ if os.environ.get('TESTABILITY', False) and \
36+ '-testability' not in sys.argv:
37+ sys.argv.append('-testability')
38 app = QtGui.QApplication(sys.argv)
39
40 source.main(app)
41
42=== modified file 'ubuntu_sso/qt/main/tests/test_main.py'
43--- ubuntu_sso/qt/main/tests/test_main.py 2012-04-09 17:38:24 +0000
44+++ ubuntu_sso/qt/main/tests/test_main.py 2012-05-09 18:03:18 +0000
45@@ -28,6 +28,10 @@
46 # files in the program, then also delete it here.
47 """Tests for the main module."""
48
49+from copy import copy
50+import os
51+import sys
52+
53 from PyQt4 import QtCore
54 from twisted.internet import defer
55 from twisted.trial.unittest import TestCase
56@@ -120,6 +124,7 @@
57 self.patch(main.source, 'main_start',
58 lambda *arg, **kw: called_ui('main_start', *arg, **kw))
59 self.patch(main.QtGui, 'QApplication', FakeApplication)
60+ FakeApplication.called['args'] = []
61
62 def test_main(self):
63 """Calling main.main() a UI instance is created."""
64@@ -132,6 +137,29 @@
65 ('main_start', (FakeApplication.instance(),), {})]
66 self.assertEqual(self.called, expected)
67
68+ def test_testability(self):
69+ """Calling main.main() with TESTABILITY=1, adds -testability."""
70+ environ = copy(os.environ)
71+ environ['TESTABILITY'] = '1'
72+ self.patch(os, 'environ', environ)
73+ self.patch(sys, 'argv', [])
74+ kwargs = dict(app_name='APP_NAME', foo='foo', bar='bar',
75+ baz='yadda', yadda=0)
76+ main.main(**kwargs)
77+ self.assertIn('-testability', FakeApplication.called['args'])
78+
79+ def test_no_testability(self):
80+ """Calling main.main() with TESTABILITY unset."""
81+ environ = copy(os.environ)
82+ if 'TESTABILITY' in environ:
83+ environ['TESTABILITY'] = ''
84+ self.patch(os, 'environ', environ)
85+ self.patch(sys, 'argv', [])
86+ kwargs = dict(app_name='APP_NAME', foo='foo', bar='bar',
87+ baz='yadda', yadda=0)
88+ main.main(**kwargs)
89+ self.assertNotIn('-testability', FakeApplication.called['args'])
90+
91 def test_check_close_callback(self):
92 """Check that the close callback is main_quit."""
93

Subscribers

People subscribed via source and target branches