~mvo/ubuntu-sso-client/strawman-lp711413

« back to all changes in this revision

Viewing changes to ubuntu_sso/qt/main/tests/test_main.py

  • Committer: Tarmac
  • Author(s): Diego Sarmentero, Roberto Alsina, Natalia B. Bidart, manuel.delapena at canonical, Manuel de la Pena
  • Date: 2012-03-27 19:33:27 UTC
  • mfrom: (831.1.2 stable-3-0-update-2.99.91.1)
  • Revision ID: tarmac-20120327193327-rgwi1z1cbfxxrx9d
Tags: release-2_99_91_1
[ Diego Sarmentero <diego.sarmentero@canonical.com> ]
  - Converting to unicode some data returned by webclient in
    QByteArray format (LP: #961315).
  - Adding ubuntu_sso.qt.main module to the setup script (LP: #965377).
  - Fixed the backend getting stuck installing the qtreactor before
    the qt process is executed and running the application in the
    twisted process (This fix affects only Windows OS) (LP: #961511).

[ Roberto Alsina <roberto.alsina@canonical.com> ]
   - Forced white background (LP: #961346).

[ Manuel de la Pena <manuel.delapena@canonical.com> ]
  - 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).

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
    def setUp(self):
92
92
        yield super(BasicTestCase, self).setUp()
93
93
        self.called = []
 
94
        self._close_callback = None
 
95
        self._app = None
94
96
 
95
 
        def called_ui(**kw):
 
97
        def called_ui(method, *args, **kw):
96
98
            """record ui call."""
97
 
            self.called.append(('GUI', kw))
 
99
            if 'close_callback' in kw:
 
100
                self._close_callback = kw.pop('close_callback')
 
101
            self.called.append((method, args, kw))
98
102
            return FakeUi()
99
103
 
100
 
        self.patch(main, 'UbuntuSSOClientGUI', called_ui)
 
104
        self.patch(main, 'UbuntuSSOClientGUI',
 
105
            lambda *arg, **kw: called_ui('GUI', *arg, **kw))
 
106
        self.patch(main.source, 'main',
 
107
            lambda *arg, **kw: called_ui('main', *arg, **kw))
 
108
        self.patch(main.source, 'main_start',
 
109
            lambda *arg, **kw: called_ui('main_start', *arg, **kw))
101
110
        self.patch(main.QtGui, 'QApplication', FakeApplication)
102
111
 
103
112
    def test_main(self):
106
115
            baz='yadda', yadda=0)
107
116
        main.main(**kwargs)
108
117
 
109
 
        kwargs['close_callback'] = main.QtGui.QApplication.instance().exit
110
 
        self.assertEqual(self.called, [('GUI', kwargs)])
 
118
        expected = [('main', (FakeApplication.instance(),), {}),
 
119
            ('GUI', (), kwargs),
 
120
            ('main_start', (FakeApplication.instance(),), {})]
 
121
        self.assertEqual(self.called, expected)
 
122
 
 
123
    def test_check_close_callback(self):
 
124
        """Check that the close callback is main_quit."""
 
125
 
 
126
        def called_quit(app):
 
127
            """Record the call to quit."""
 
128
            self._app = app
 
129
 
 
130
        self.patch(main.source, 'main_quit', called_quit)
 
131
 
 
132
        kwargs = dict(app_name='APP_NAME', foo='foo', bar='bar',
 
133
            baz='yadda', yadda=0)
 
134
        main.main(**kwargs)
 
135
 
 
136
        expected = [('main', (FakeApplication.instance(),), {}),
 
137
            ('GUI', (), kwargs),
 
138
            ('main_start', (FakeApplication.instance(),), {})]
 
139
        self._close_callback()
 
140
        self.assertEqual(self.called, expected)
 
141
        self.assertEqual(self._app, FakeApplication.instance())
111
142
 
112
143
    def test_main_args(self):
113
144
        """Calling main.main() a UI instance is created."""
119
150
            baz=arg_list[3].encode('utf-8'))
120
151
        main.main(**kwargs)
121
152
 
122
 
        kwargs['close_callback'] = main.QtGui.QApplication.instance().exit
123
 
        expected = dict(app_name=arg_list[0], foo=arg_list[1],
124
 
            bar=arg_list[2], baz=arg_list[3],
125
 
            close_callback=main.QtGui.QApplication.instance().exit)
126
 
        self.assertEqual(self.called, [('GUI', expected)])
 
153
        args_unicode = dict(app_name=arg_list[0], foo=arg_list[1],
 
154
            bar=arg_list[2], baz=arg_list[3])
 
155
        expected = [('main', (FakeApplication.instance(),), {}),
 
156
            ('GUI', (), args_unicode),
 
157
            ('main_start', (FakeApplication.instance(),), {})]
 
158
        self.assertEqual(self.called, expected)
127
159
 
128
160
    def test_styles_load(self):
129
161
        """Test that all stylesheets load."""