/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5394.1.1 by Vincent Ladeuil
Config files in bazaar home now use a lock
1
# Copyright (C) 2007-2010 Canonical Ltd
2898.3.5 by James Henstridge
Add copyright headers to new files
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2898.3.5 by James Henstridge
Add copyright headers to new files
16
17
"""Tests for Launchpad user ID management functions."""
18
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
19
from ... import config
20
from ...tests import TestCaseInTempDir, TestCaseWithMemoryTransport
21
from . import account
2898.3.1 by James Henstridge
API for storing and retrieving the Launchpad user ID that will be used
22
23
2898.3.10 by James Henstridge
Make LaunchpadAccountTests a TestCaseInTempDir so that config changes
24
class LaunchpadAccountTests(TestCaseInTempDir):
2898.3.1 by James Henstridge
API for storing and retrieving the Launchpad user ID that will be used
25
2898.3.2 by James Henstridge
Rename functions.
26
    def test_get_lp_login_unconfigured(self):
27
        # Test that get_lp_login() returns None if no username has
2898.3.1 by James Henstridge
API for storing and retrieving the Launchpad user ID that will be used
28
        # been configured.
6973.12.11 by Jelmer Vernooij
Fix some more tests.
29
        my_config = config.MemoryStack(b'')
2898.3.2 by James Henstridge
Rename functions.
30
        self.assertEqual(None, account.get_lp_login(my_config))
2898.3.1 by James Henstridge
API for storing and retrieving the Launchpad user ID that will be used
31
2898.3.2 by James Henstridge
Rename functions.
32
    def test_get_lp_login(self):
33
        # Test that get_lp_login() returns the configured username
6464.1.1 by Jelmer Vernooij
Merge launchpad configuration to config stacks.
34
        my_config = config.MemoryStack(
6973.12.11 by Jelmer Vernooij
Fix some more tests.
35
            b'[DEFAULT]\nlaunchpad_username=test-user\n')
2898.3.9 by James Henstridge
* Add a simple NEWS item for the command.
36
        self.assertEqual('test-user', account.get_lp_login(my_config))
2898.3.1 by James Henstridge
API for storing and retrieving the Launchpad user ID that will be used
37
2898.3.2 by James Henstridge
Rename functions.
38
    def test_set_lp_login(self):
39
        # Test that set_lp_login() updates the config file.
6973.12.11 by Jelmer Vernooij
Fix some more tests.
40
        my_config = config.MemoryStack(b'')
6464.1.1 by Jelmer Vernooij
Merge launchpad configuration to config stacks.
41
        self.assertEqual(None, my_config.get('launchpad_username'))
2898.3.9 by James Henstridge
* Add a simple NEWS item for the command.
42
        account.set_lp_login('test-user', my_config)
2898.3.1 by James Henstridge
API for storing and retrieving the Launchpad user ID that will be used
43
        self.assertEqual(
6464.1.1 by Jelmer Vernooij
Merge launchpad configuration to config stacks.
44
            'test-user', my_config.get('launchpad_username'))
2898.3.1 by James Henstridge
API for storing and retrieving the Launchpad user ID that will be used
45
2898.3.7 by James Henstridge
* Add tests for account.py exception messages.
46
    def test_unknown_launchpad_username(self):
47
        # Test formatting of UnknownLaunchpadUsername exception
2898.3.9 by James Henstridge
* Add a simple NEWS item for the command.
48
        error = account.UnknownLaunchpadUsername(user='test-user')
49
        self.assertEqualDiff('The user name test-user is not registered '
2898.3.7 by James Henstridge
* Add tests for account.py exception messages.
50
                             'on Launchpad.', str(error))
51
52
    def test_no_registered_ssh_keys(self):
53
        # Test formatting of NoRegisteredSSHKeys exception
2898.3.9 by James Henstridge
* Add a simple NEWS item for the command.
54
        error = account.NoRegisteredSSHKeys(user='test-user')
55
        self.assertEqualDiff('The user test-user has not registered any '
7143.15.2 by Jelmer Vernooij
Run autopep8.
56
                             'SSH keys with Launchpad.\n'
57
                             'See <https://launchpad.net/people/+me>',
58
                             str(error))
2898.3.7 by James Henstridge
* Add tests for account.py exception messages.
59
3777.1.12 by Aaron Bentley
Enable configuring ssh auth from launchpad-login, with auto-upgrade.
60
    def test_set_lp_login_updates_authentication_conf(self):
3777.1.24 by Aaron Bentley
Use .launchpad.net instead of bazaar. and bazaar.staging.
61
        self.assertIs(None, account._get_auth_user())
3777.1.12 by Aaron Bentley
Enable configuring ssh auth from launchpad-login, with auto-upgrade.
62
        account.set_lp_login('foo')
3777.1.24 by Aaron Bentley
Use .launchpad.net instead of bazaar. and bazaar.staging.
63
        self.assertEqual('foo', account._get_auth_user())
3777.1.12 by Aaron Bentley
Enable configuring ssh auth from launchpad-login, with auto-upgrade.
64
3777.1.18 by Aaron Bentley
Fix None handling wrt auth upgrades
65
    def test_get_lp_login_does_not_update_for_none_user(self):
66
        account.get_lp_login()
3777.1.24 by Aaron Bentley
Use .launchpad.net instead of bazaar. and bazaar.staging.
67
        self.assertIs(None, account._get_auth_user())
3777.1.18 by Aaron Bentley
Fix None handling wrt auth upgrades
68
3777.1.12 by Aaron Bentley
Enable configuring ssh auth from launchpad-login, with auto-upgrade.
69
    def test_get_lp_login_updates_authentication_conf(self):
70
        account._set_global_option('foo')
3777.1.24 by Aaron Bentley
Use .launchpad.net instead of bazaar. and bazaar.staging.
71
        self.assertIs(None, account._get_auth_user())
3777.1.12 by Aaron Bentley
Enable configuring ssh auth from launchpad-login, with auto-upgrade.
72
        account.get_lp_login()
3777.1.24 by Aaron Bentley
Use .launchpad.net instead of bazaar. and bazaar.staging.
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'))
3777.1.12 by Aaron Bentley
Enable configuring ssh auth from launchpad-login, with auto-upgrade.
78
79
    def test_get_lp_login_leaves_existing_credentials(self):
80
        auth = config.AuthenticationConfig()
3777.1.14 by Aaron Bentley
Adjust for new set_credentials signature
81
        auth.set_credentials('Foo', 'bazaar.launchpad.net', 'foo', 'ssh')
3777.1.20 by Aaron Bentley
Include staging in launchpad-login authentication.
82
        auth.set_credentials('Bar', 'bazaar.staging.launchpad.net', 'foo',
83
                             'ssh')
3777.1.12 by Aaron Bentley
Enable configuring ssh auth from launchpad-login, with auto-upgrade.
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)
6740.1.1 by Jelmer Vernooij
Rename bazaar.conf to breezy.conf.
95
        self.assertEqual('breezy.conf and authentication.conf disagree about'
7143.15.2 by Jelmer Vernooij
Run autopep8.
96
                         ' launchpad account name.  Please re-run launchpad-login.', str(e))
3777.1.12 by Aaron Bentley
Enable configuring ssh auth from launchpad-login, with auto-upgrade.
97
2898.3.1 by James Henstridge
API for storing and retrieving the Launchpad user ID that will be used
98
99
class CheckAccountTests(TestCaseWithMemoryTransport):
100
2898.3.2 by James Henstridge
Rename functions.
101
    def test_check_lp_login_valid_user(self):
2898.3.1 by James Henstridge
API for storing and retrieving the Launchpad user ID that will be used
102
        transport = self.get_transport()
2898.3.9 by James Henstridge
* Add a simple NEWS item for the command.
103
        transport.mkdir('~test-user')
6973.12.11 by Jelmer Vernooij
Fix some more tests.
104
        transport.put_bytes('~test-user/+sshkeys', b'some keys here')
2898.3.9 by James Henstridge
* Add a simple NEWS item for the command.
105
        account.check_lp_login('test-user', transport)
2898.3.1 by James Henstridge
API for storing and retrieving the Launchpad user ID that will be used
106
2898.3.2 by James Henstridge
Rename functions.
107
    def test_check_lp_login_no_user(self):
2898.3.1 by James Henstridge
API for storing and retrieving the Launchpad user ID that will be used
108
        transport = self.get_transport()
109
        self.assertRaises(account.UnknownLaunchpadUsername,
2898.3.9 by James Henstridge
* Add a simple NEWS item for the command.
110
                          account.check_lp_login, 'test-user', transport)
2898.3.1 by James Henstridge
API for storing and retrieving the Launchpad user ID that will be used
111
2898.3.2 by James Henstridge
Rename functions.
112
    def test_check_lp_login_no_ssh_keys(self):
2898.3.1 by James Henstridge
API for storing and retrieving the Launchpad user ID that will be used
113
        transport = self.get_transport()
2898.3.9 by James Henstridge
* Add a simple NEWS item for the command.
114
        transport.mkdir('~test-user')
6973.12.11 by Jelmer Vernooij
Fix some more tests.
115
        transport.put_bytes('~test-user/+sshkeys', b'')
2898.3.1 by James Henstridge
API for storing and retrieving the Launchpad user ID that will be used
116
        self.assertRaises(account.NoRegisteredSSHKeys,
2898.3.9 by James Henstridge
* Add a simple NEWS item for the command.
117
                          account.check_lp_login, 'test-user', transport)