/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-04-10 19:37:20 UTC
  • mfrom: (4222.3.15 username)
  • Revision ID: pqm@pqm.ubuntu.com-20090410193720-nyej7ft1k2yoyhui
(Jelmer) Prompt for user names for http if they are not in the
        configuration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""Tests for finding and reading the bzr config file[s]."""
19
19
# import system imports here
20
20
from cStringIO import StringIO
 
21
import getpass
21
22
import os
22
23
import sys
23
24
 
1459
1460
class TestAuthenticationConfig(tests.TestCase):
1460
1461
    """Test AuthenticationConfig behaviour"""
1461
1462
 
1462
 
    def _check_default_prompt(self, expected_prompt_format, scheme,
 
1463
    def _check_default_password_prompt(self, expected_prompt_format, scheme,
1463
1464
                              host=None, port=None, realm=None, path=None):
1464
1465
        if host is None:
1465
1466
            host = 'bar.org'
1478
1479
                                            realm=realm, path=path))
1479
1480
        self.assertEquals(stdout.getvalue(), expected_prompt)
1480
1481
 
1481
 
    def test_default_prompts(self):
1482
 
        # HTTP prompts can't be tested here, see test_http.py
1483
 
        self._check_default_prompt('FTP %(user)s@%(host)s password: ', 'ftp')
1484
 
        self._check_default_prompt('FTP %(user)s@%(host)s:%(port)d password: ',
1485
 
                                   'ftp', port=10020)
1486
 
 
1487
 
        self._check_default_prompt('SSH %(user)s@%(host)s:%(port)d password: ',
1488
 
                                   'ssh', port=12345)
 
1482
    def _check_default_username_prompt(self, expected_prompt_format, scheme,
 
1483
                              host=None, port=None, realm=None, path=None):
 
1484
        if host is None:
 
1485
            host = 'bar.org'
 
1486
        username = 'jim'
 
1487
        expected_prompt = expected_prompt_format % {
 
1488
            'scheme': scheme, 'host': host, 'port': port,
 
1489
            'realm': realm}
 
1490
        stdout = tests.StringIOWrapper()
 
1491
        ui.ui_factory = tests.TestUIFactory(stdin=username+ '\n',
 
1492
                                            stdout=stdout)
 
1493
        # We use an empty conf so that the user is always prompted
 
1494
        conf = config.AuthenticationConfig()
 
1495
        self.assertEquals(username, conf.get_user(scheme, host, port=port,
 
1496
                          realm=realm, path=path, ask=True))
 
1497
        self.assertEquals(stdout.getvalue(), expected_prompt)
 
1498
 
 
1499
    def test_username_defaults_prompts(self):
 
1500
        # HTTP prompts can't be tested here, see test_http.py
 
1501
        self._check_default_username_prompt('FTP %(host)s username: ', 'ftp')
 
1502
        self._check_default_username_prompt(
 
1503
            'FTP %(host)s:%(port)d username: ', 'ftp', port=10020)
 
1504
        self._check_default_username_prompt(
 
1505
            'SSH %(host)s:%(port)d username: ', 'ssh', port=12345)
 
1506
 
 
1507
    def test_username_default_no_prompt(self):
 
1508
        conf = config.AuthenticationConfig()
 
1509
        self.assertEquals(getpass.getuser(), 
 
1510
            conf.get_user('ftp', 'example.com'))
 
1511
        self.assertEquals("explicitdefault", 
 
1512
            conf.get_user('ftp', 'example.com', default="explicitdefault"))
 
1513
 
 
1514
    def test_password_default_prompts(self):
 
1515
        # HTTP prompts can't be tested here, see test_http.py
 
1516
        self._check_default_password_prompt(
 
1517
            'FTP %(user)s@%(host)s password: ', 'ftp')
 
1518
        self._check_default_password_prompt(
 
1519
            'FTP %(user)s@%(host)s:%(port)d password: ', 'ftp', port=10020)
 
1520
        self._check_default_password_prompt(
 
1521
            'SSH %(user)s@%(host)s:%(port)d password: ', 'ssh', port=12345)
1489
1522
        # SMTP port handling is a bit special (it's handled if embedded in the
1490
1523
        # host too)
1491
1524
        # FIXME: should we: forbid that, extend it to other schemes, leave
1492
1525
        # things as they are that's fine thank you ?
1493
 
        self._check_default_prompt('SMTP %(user)s@%(host)s password: ',
 
1526
        self._check_default_password_prompt('SMTP %(user)s@%(host)s password: ',
1494
1527
                                   'smtp')
1495
 
        self._check_default_prompt('SMTP %(user)s@%(host)s password: ',
 
1528
        self._check_default_password_prompt('SMTP %(user)s@%(host)s password: ',
1496
1529
                                   'smtp', host='bar.org:10025')
1497
 
        self._check_default_prompt(
 
1530
        self._check_default_password_prompt(
1498
1531
            'SMTP %(user)s@%(host)s:%(port)d password: ',
1499
1532
            'smtp', port=10025)
1500
1533