~nataliabidart/ubuntu-sso-client/find-me-bin-dir

« back to all changes in this revision

Viewing changes to ubuntu_sso/qt/tests/test_proxy_dialog.py

  • Committer: Tarmac
  • Author(s): Manuel de la Pena
  • Date: 2012-02-14 12:23:07 UTC
  • mfrom: (846.6.19 creds-dialog-script)
  • Revision ID: tarmac-20120214122307-ewnihrx9xefxn187
Adds the script that allows to launch the creds dialog. Adds tests for main.

Show diffs side-by-side

added added

removed removed

Lines of Context:
165
165
        self.assertIn('domain_label', dialog.ui.called)
166
166
        self.assertIn(('setText', domain), dialog.ui.called['domain_label'])
167
167
 
168
 
    def test_is_error(self):
 
168
    def test_retry(self):
169
169
        """Test that we do set the error label correctly."""
170
 
        dialog = proxy_dialog.ProxyCredsDialog(is_error=False)
 
170
        dialog = proxy_dialog.ProxyCredsDialog(retry=False)
171
171
        self.assertIn('error_label', dialog.ui.called)
172
172
        self.assertIn(('setVisible', False), dialog.ui.called['error_label'])
173
173
 
174
 
    def test_is_not_error(self):
 
174
    def test_is_not_retry(self):
175
175
        """Test that we do set the error label correctly."""
176
 
        dialog = proxy_dialog.ProxyCredsDialog(is_error=True)
 
176
        dialog = proxy_dialog.ProxyCredsDialog(retry=True)
177
177
        self.assertIn('error_label', dialog.ui.called)
178
178
        self.assertIn(('setVisible', True), dialog.ui.called['error_label'])
179
179
 
233
233
        set_creds_cb = lambda: defer.succeed(True)
234
234
        result_number = proxy_dialog.CREDS_ACQUIRED
235
235
        self.assert_save_button(set_creds_cb, result_number)
 
236
 
 
237
 
 
238
class FakeArgs(object):
 
239
    """Some fake args."""
 
240
 
 
241
    def __init__(self, domain='', retry=False):
 
242
        """Create a new instance."""
 
243
        self.domain = domain
 
244
        self.retry = retry
 
245
 
 
246
 
 
247
class MainTest(TestCase):
 
248
    """Test the main method."""
 
249
 
 
250
    @defer.inlineCallbacks
 
251
    def setUp(self):
 
252
        """Set the different tests."""
 
253
        yield super(MainTest, self).setUp()
 
254
        self.called = []
 
255
 
 
256
        self.args = FakeArgs(domain='domain', retry=False)
 
257
        self.patch(proxy_dialog, 'parse_args', lambda: self.args)
 
258
 
 
259
        self.return_code = 0
 
260
        self.patch(proxy_dialog.ProxyCredsDialog, 'exec_', lambda x:
 
261
                self.return_code)
 
262
        self.exit_code = None
 
263
 
 
264
        def fake_exit(code):
 
265
            """Fake the sys.exit."""
 
266
            self.called.append(('exit', code))
 
267
            self.exit_code = code
 
268
 
 
269
        self.patch(proxy_dialog.sys, 'exit', fake_exit)
 
270
 
 
271
        def fake_application(args):
 
272
            """Fake a QApplication."""
 
273
            self.called.append(('QApplication', args))
 
274
 
 
275
        self.patch(proxy_dialog, 'QApplication', fake_application)
 
276
 
 
277
    def test_main(self):
 
278
        """Test the main method."""
 
279
        proxy_dialog.main()
 
280
        self.assertIn('QApplication', self.called[0])
 
281
        self.assertIn(('exit', self.return_code), self.called)