~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for Launchpad user ID management functions."""
18
18
 
 
19
from cStringIO import StringIO
 
20
 
19
21
from bzrlib import config
20
22
from bzrlib.tests import TestCaseInTempDir, TestCaseWithMemoryTransport
21
23
from bzrlib.plugins.launchpad import account
23
25
 
24
26
class LaunchpadAccountTests(TestCaseInTempDir):
25
27
 
 
28
    def setup_config(self, text):
 
29
        my_config = config.GlobalConfig()
 
30
        config_file = StringIO(text)
 
31
        my_config._get_parser(config_file)
 
32
        return my_config
 
33
 
26
34
    def test_get_lp_login_unconfigured(self):
27
35
        # Test that get_lp_login() returns None if no username has
28
36
        # been configured.
29
 
        my_config = config.MemoryStack('')
 
37
        my_config = self.setup_config('')
30
38
        self.assertEqual(None, account.get_lp_login(my_config))
31
39
 
32
40
    def test_get_lp_login(self):
33
41
        # Test that get_lp_login() returns the configured username
34
 
        my_config = config.MemoryStack(
 
42
        my_config = self.setup_config(
35
43
            '[DEFAULT]\nlaunchpad_username=test-user\n')
36
44
        self.assertEqual('test-user', account.get_lp_login(my_config))
37
45
 
38
46
    def test_set_lp_login(self):
39
47
        # Test that set_lp_login() updates the config file.
40
 
        my_config = config.MemoryStack('')
41
 
        self.assertEqual(None, my_config.get('launchpad_username'))
 
48
        my_config = self.setup_config('')
 
49
        self.assertEqual(None, my_config.get_user_option('launchpad_username'))
42
50
        account.set_lp_login('test-user', my_config)
43
51
        self.assertEqual(
44
 
            'test-user', my_config.get('launchpad_username'))
 
52
            'test-user', my_config.get_user_option('launchpad_username'))
45
53
 
46
54
    def test_unknown_launchpad_username(self):
47
55
        # Test formatting of UnknownLaunchpadUsername exception
53
61
        # Test formatting of NoRegisteredSSHKeys exception
54
62
        error = account.NoRegisteredSSHKeys(user='test-user')
55
63
        self.assertEqualDiff('The user test-user has not registered any '
56
 
            'SSH keys with Launchpad.\n'
57
 
            'See <https://launchpad.net/people/+me>',
58
 
            str(error))
59
 
 
60
 
    def test_set_lp_login_updates_authentication_conf(self):
61
 
        self.assertIs(None, account._get_auth_user())
62
 
        account.set_lp_login('foo')
63
 
        self.assertEqual('foo', account._get_auth_user())
64
 
 
65
 
    def test_get_lp_login_does_not_update_for_none_user(self):
66
 
        account.get_lp_login()
67
 
        self.assertIs(None, account._get_auth_user())
68
 
 
69
 
    def test_get_lp_login_updates_authentication_conf(self):
70
 
        account._set_global_option('foo')
71
 
        self.assertIs(None, account._get_auth_user())
72
 
        account.get_lp_login()
73
 
        auth = config.AuthenticationConfig()
74
 
        self.assertEqual('foo', account._get_auth_user(auth))
75
 
        self.assertEqual('foo', auth.get_user('ssh', 'bazaar.launchpad.net'))
76
 
        self.assertEqual('foo', auth.get_user('ssh',
77
 
                                              'bazaar.staging.launchpad.net'))
78
 
 
79
 
    def test_get_lp_login_leaves_existing_credentials(self):
80
 
        auth = config.AuthenticationConfig()
81
 
        auth.set_credentials('Foo', 'bazaar.launchpad.net', 'foo', 'ssh')
82
 
        auth.set_credentials('Bar', 'bazaar.staging.launchpad.net', 'foo',
83
 
                             'ssh')
84
 
        account._set_global_option('foo')
85
 
        account.get_lp_login()
86
 
        auth = config.AuthenticationConfig()
87
 
        credentials = auth.get_credentials('ssh', 'bazaar.launchpad.net')
88
 
        self.assertEqual('Foo', credentials['name'])
89
 
 
90
 
    def test_get_lp_login_errors_on_mismatch(self):
91
 
        account._set_auth_user('foo')
92
 
        account._set_global_option('bar')
93
 
        e = self.assertRaises(account.MismatchedUsernames,
94
 
                              account.get_lp_login)
95
 
        self.assertEqual('bazaar.conf and authentication.conf disagree about'
96
 
            ' launchpad account name.  Please re-run launchpad-login.', str(e))
 
64
                             'SSH keys with Launchpad.', str(error))
97
65
 
98
66
 
99
67
class CheckAccountTests(TestCaseWithMemoryTransport):