~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Vincent Ladeuil
  • Date: 2009-05-15 10:14:51 UTC
  • mto: (4396.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4397.
  • Revision ID: v.ladeuil+lp@free.fr-20090515101451-bffnsywhvaskrz1h
Use stderr for UI prompt to address bug #376582.

* bzrlib/ui/__init__.py:
(CLIUIFactory.prompt): Display prompt on stderr.

* bzrlib/tests/test_ui.py: (UITests.test_text_factory_ascii_password,
UITests.test_text_factory_utf8_password,
UITests.assert_get_bool_acceptance_of_user_input,
UITests.test_text_factory_prompt,
UITests.test_silent_ui_getusername,
UITests.test_text_ui_getusername,
UITests.test_text_ui_getusername_utf8):prompt is now displayed on
stderr.

* bzrlib/tests/test_http.py:
(TestAuth.test_prompt_for_username,
TestAuth.test_prompt_for_password): prompt is now displayed on
stderr.

* bzrlib/tests/test_config.py:
(TestAuthenticationConfig._check_default_password_prompt,
TestAuthenticationConfig._check_default_username_prompt): prompt
is now displayed on stderr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1461
1461
    """Test AuthenticationConfig behaviour"""
1462
1462
 
1463
1463
    def _check_default_password_prompt(self, expected_prompt_format, scheme,
1464
 
                              host=None, port=None, realm=None, path=None):
 
1464
                                       host=None, port=None, realm=None,
 
1465
                                       path=None):
1465
1466
        if host is None:
1466
1467
            host = 'bar.org'
1467
1468
        user, password = 'jim', 'precious'
1470
1471
            'user': user, 'realm': realm}
1471
1472
 
1472
1473
        stdout = tests.StringIOWrapper()
 
1474
        stderr = tests.StringIOWrapper()
1473
1475
        ui.ui_factory = tests.TestUIFactory(stdin=password + '\n',
1474
 
                                            stdout=stdout)
 
1476
                                            stdout=stdout, stderr=stderr)
1475
1477
        # We use an empty conf so that the user is always prompted
1476
1478
        conf = config.AuthenticationConfig()
1477
1479
        self.assertEquals(password,
1478
1480
                          conf.get_password(scheme, host, user, port=port,
1479
1481
                                            realm=realm, path=path))
1480
 
        self.assertEquals(stdout.getvalue(), expected_prompt)
 
1482
        self.assertEquals(expected_prompt, stderr.getvalue())
 
1483
        self.assertEquals('', stdout.getvalue())
1481
1484
 
1482
1485
    def _check_default_username_prompt(self, expected_prompt_format, scheme,
1483
 
                              host=None, port=None, realm=None, path=None):
 
1486
                                       host=None, port=None, realm=None,
 
1487
                                       path=None):
1484
1488
        if host is None:
1485
1489
            host = 'bar.org'
1486
1490
        username = 'jim'
1488
1492
            'scheme': scheme, 'host': host, 'port': port,
1489
1493
            'realm': realm}
1490
1494
        stdout = tests.StringIOWrapper()
 
1495
        stderr = tests.StringIOWrapper()
1491
1496
        ui.ui_factory = tests.TestUIFactory(stdin=username+ '\n',
1492
 
                                            stdout=stdout)
 
1497
                                            stdout=stdout, stderr=stderr)
1493
1498
        # We use an empty conf so that the user is always prompted
1494
1499
        conf = config.AuthenticationConfig()
1495
1500
        self.assertEquals(username, conf.get_user(scheme, host, port=port,
1496
1501
                          realm=realm, path=path, ask=True))
1497
 
        self.assertEquals(stdout.getvalue(), expected_prompt)
 
1502
        self.assertEquals(expected_prompt, stderr.getvalue())
 
1503
        self.assertEquals('', stdout.getvalue())
1498
1504
 
1499
1505
    def test_username_defaults_prompts(self):
1500
1506
        # HTTP prompts can't be tested here, see test_http.py