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
17
17
"""Tests for Launchpad user ID management functions."""
61
61
# Test formatting of NoRegisteredSSHKeys exception
62
62
error = account.NoRegisteredSSHKeys(user='test-user')
63
63
self.assertEqualDiff('The user test-user has not registered any '
64
'SSH keys with Launchpad.', str(error))
64
'SSH keys with Launchpad.\n'
65
'See <https://launchpad.net/people/+me>',
68
def test_set_lp_login_updates_authentication_conf(self):
69
self.assertIs(None, account._get_auth_user())
70
account.set_lp_login('foo')
71
self.assertEqual('foo', account._get_auth_user())
73
def test_get_lp_login_does_not_update_for_none_user(self):
74
account.get_lp_login()
75
self.assertIs(None, account._get_auth_user())
77
def test_get_lp_login_updates_authentication_conf(self):
78
account._set_global_option('foo')
79
self.assertIs(None, account._get_auth_user())
80
account.get_lp_login()
81
auth = config.AuthenticationConfig()
82
self.assertEqual('foo', account._get_auth_user(auth))
83
self.assertEqual('foo', auth.get_user('ssh', 'bazaar.launchpad.net'))
84
self.assertEqual('foo', auth.get_user('ssh',
85
'bazaar.staging.launchpad.net'))
87
def test_get_lp_login_leaves_existing_credentials(self):
88
auth = config.AuthenticationConfig()
89
auth.set_credentials('Foo', 'bazaar.launchpad.net', 'foo', 'ssh')
90
auth.set_credentials('Bar', 'bazaar.staging.launchpad.net', 'foo',
92
account._set_global_option('foo')
93
account.get_lp_login()
94
auth = config.AuthenticationConfig()
95
credentials = auth.get_credentials('ssh', 'bazaar.launchpad.net')
96
self.assertEqual('Foo', credentials['name'])
98
def test_get_lp_login_errors_on_mismatch(self):
99
account._set_auth_user('foo')
100
account._set_global_option('bar')
101
e = self.assertRaises(account.MismatchedUsernames,
102
account.get_lp_login)
103
self.assertEqual('bazaar.conf and authentication.conf disagree about'
104
' launchpad account name. Please re-run launchpad-login.', str(e))
67
107
class CheckAccountTests(TestCaseWithMemoryTransport):