~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/launchpad/test_account.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 18:13:57 UTC
  • mfrom: (5268.7.29 transport-segments)
  • Revision ID: pqm@pqm.ubuntu.com-20110817181357-y5q5eth1hk8bl3om
(jelmer) Allow specifying the colocated branch to use in the branch URL,
 and retrieving the branch name using ControlDir._get_selected_branch.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for Launchpad user ID management functions."""
18
18
 
26
26
class LaunchpadAccountTests(TestCaseInTempDir):
27
27
 
28
28
    def setup_config(self, text):
29
 
        my_config = config.GlobalConfig()
30
 
        config_file = StringIO(text)
31
 
        my_config._get_parser(config_file)
 
29
        my_config = config.GlobalConfig.from_string(text)
32
30
        return my_config
33
31
 
34
32
    def test_get_lp_login_unconfigured(self):
61
59
        # Test formatting of NoRegisteredSSHKeys exception
62
60
        error = account.NoRegisteredSSHKeys(user='test-user')
63
61
        self.assertEqualDiff('The user test-user has not registered any '
64
 
                             'SSH keys with Launchpad.', str(error))
 
62
            'SSH keys with Launchpad.\n'
 
63
            'See <https://launchpad.net/people/+me>',
 
64
            str(error))
 
65
 
 
66
    def test_set_lp_login_updates_authentication_conf(self):
 
67
        self.assertIs(None, account._get_auth_user())
 
68
        account.set_lp_login('foo')
 
69
        self.assertEqual('foo', account._get_auth_user())
 
70
 
 
71
    def test_get_lp_login_does_not_update_for_none_user(self):
 
72
        account.get_lp_login()
 
73
        self.assertIs(None, account._get_auth_user())
 
74
 
 
75
    def test_get_lp_login_updates_authentication_conf(self):
 
76
        account._set_global_option('foo')
 
77
        self.assertIs(None, account._get_auth_user())
 
78
        account.get_lp_login()
 
79
        auth = config.AuthenticationConfig()
 
80
        self.assertEqual('foo', account._get_auth_user(auth))
 
81
        self.assertEqual('foo', auth.get_user('ssh', 'bazaar.launchpad.net'))
 
82
        self.assertEqual('foo', auth.get_user('ssh',
 
83
                                              'bazaar.staging.launchpad.net'))
 
84
 
 
85
    def test_get_lp_login_leaves_existing_credentials(self):
 
86
        auth = config.AuthenticationConfig()
 
87
        auth.set_credentials('Foo', 'bazaar.launchpad.net', 'foo', 'ssh')
 
88
        auth.set_credentials('Bar', 'bazaar.staging.launchpad.net', 'foo',
 
89
                             'ssh')
 
90
        account._set_global_option('foo')
 
91
        account.get_lp_login()
 
92
        auth = config.AuthenticationConfig()
 
93
        credentials = auth.get_credentials('ssh', 'bazaar.launchpad.net')
 
94
        self.assertEqual('Foo', credentials['name'])
 
95
 
 
96
    def test_get_lp_login_errors_on_mismatch(self):
 
97
        account._set_auth_user('foo')
 
98
        account._set_global_option('bar')
 
99
        e = self.assertRaises(account.MismatchedUsernames,
 
100
                              account.get_lp_login)
 
101
        self.assertEqual('bazaar.conf and authentication.conf disagree about'
 
102
            ' launchpad account name.  Please re-run launchpad-login.', str(e))
65
103
 
66
104
 
67
105
class CheckAccountTests(TestCaseWithMemoryTransport):