Merge lp:~jml/bzr/verbose-lp-login-bug-217031 into lp:~bzr/bzr/trunk-old

Proposed by Jonathan Lange
Status: Merged
Approved by: Jonathan Lange
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~jml/bzr/verbose-lp-login-bug-217031
Merge into: lp:~bzr/bzr/trunk-old
Diff against target: 133 lines
To merge this branch: bzr merge lp:~jml/bzr/verbose-lp-login-bug-217031
Reviewer Review Type Date Requested Status
Vincent Ladeuil Approve
Review via email: mp+8172@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jonathan Lange (jml) wrote :

This makes lp-login respect the verbose option. It also adds a bunch of blackbox tests for lp-login.

Revision history for this message
Vincent Ladeuil (vila) wrote :

Nice.

Too bad we don't have a lp test server in our suite :-P

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2009-07-02 04:49:28 +0000
3+++ NEWS 2009-07-03 09:35:08 +0000
4@@ -105,6 +105,9 @@
5 * Progress bars no longer show the network transport scheme or direction.
6 (Martin Pool)
7
8+* launchpad-login now respects the 'verbose' option.
9+ (Jonathan Lange, #217031)
10+
11
12 Internals
13 *********
14
15=== modified file 'bzrlib/plugins/launchpad/__init__.py'
16--- bzrlib/plugins/launchpad/__init__.py 2009-06-19 15:10:17 +0000
17+++ bzrlib/plugins/launchpad/__init__.py 2009-07-03 09:35:08 +0000
18@@ -220,11 +220,12 @@
19 aliases = ['lp-login']
20 takes_args = ['name?']
21 takes_options = [
22+ 'verbose',
23 Option('no-check',
24 "Don't check that the user name is valid."),
25 ]
26
27- def run(self, name=None, no_check=False):
28+ def run(self, name=None, no_check=False, verbose=False):
29 from bzrlib.plugins.launchpad import account
30 check_account = not no_check
31
32@@ -233,6 +234,9 @@
33 if username:
34 if check_account:
35 account.check_lp_login(username)
36+ if verbose:
37+ self.outf.write(
38+ "Launchpad user ID exists and has SSH keys.\n")
39 self.outf.write(username + '\n')
40 else:
41 self.outf.write('No Launchpad user ID configured.\n')
42@@ -241,7 +245,12 @@
43 name = name.lower()
44 if check_account:
45 account.check_lp_login(name)
46+ if verbose:
47+ self.outf.write(
48+ "Launchpad user ID exists and has SSH keys.\n")
49 account.set_lp_login(name)
50+ if verbose:
51+ self.outf.write("Launchpad user ID set to '%s'.\n" % (name,))
52
53 register_command(cmd_launchpad_login)
54
55@@ -259,6 +268,7 @@
56 from bzrlib.plugins.launchpad import (
57 test_account,
58 test_lp_directory,
59+ test_lp_login,
60 test_lp_open,
61 test_lp_service,
62 test_register,
63@@ -270,6 +280,7 @@
64 test_account,
65 test_register,
66 test_lp_directory,
67+ test_lp_login,
68 test_lp_open,
69 test_lp_service,
70 ]:
71
72=== added file 'bzrlib/plugins/launchpad/test_lp_login.py'
73--- bzrlib/plugins/launchpad/test_lp_login.py 1970-01-01 00:00:00 +0000
74+++ bzrlib/plugins/launchpad/test_lp_login.py 2009-07-03 09:35:08 +0000
75@@ -0,0 +1,58 @@
76+# Copyright (C) 2009 Canonical Ltd
77+#
78+# This program is free software; you can redistribute it and/or modify
79+# it under the terms of the GNU General Public License as published by
80+# the Free Software Foundation; either version 2 of the License, or
81+# (at your option) any later version.
82+#
83+# This program is distributed in the hope that it will be useful,
84+# but WITHOUT ANY WARRANTY; without even the implied warranty of
85+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
86+# GNU General Public License for more details.
87+#
88+# You should have received a copy of the GNU General Public License
89+# along with this program; if not, write to the Free Software
90+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
91+
92+"""Tests for the launchpad-login command."""
93+
94+from bzrlib.plugins.launchpad import account
95+from bzrlib.tests import TestCaseWithTransport
96+
97+
98+class TestLaunchpadLogin(TestCaseWithTransport):
99+ """Tests for launchpad-login."""
100+
101+ def test_login_without_name_when_not_logged_in(self):
102+ # lp-login without a 'name' parameter returns the user ID of the
103+ # logged in user. If no one is logged in, we tell the user as much.
104+ out, err = self.run_bzr(['launchpad-login', '--no-check'], retcode=1)
105+ self.assertEqual('No Launchpad user ID configured.\n', out)
106+ self.assertEqual('', err)
107+
108+ def test_login_with_name_sets_login(self):
109+ # lp-login with a 'name' parameter sets the Launchpad login.
110+ self.run_bzr(['launchpad-login', '--no-check', 'foo'])
111+ self.assertEqual('foo', account.get_lp_login())
112+
113+ def test_login_without_name_when_logged_in(self):
114+ # lp-login without a 'name' parameter returns the user ID of the
115+ # logged in user.
116+ account.set_lp_login('foo')
117+ out, err = self.run_bzr(['launchpad-login', '--no-check'])
118+ self.assertEqual('foo\n', out)
119+ self.assertEqual('', err)
120+
121+ def test_login_with_name_no_output_by_default(self):
122+ # lp-login with a 'name' parameter produces no output by default.
123+ out, err = self.run_bzr(['launchpad-login', '--no-check', 'foo'])
124+ self.assertEqual('', out)
125+ self.assertEqual('', err)
126+
127+ def test_login_with_name_verbose(self):
128+ # lp-login with a 'name' parameter and a verbose flag produces some
129+ # information about what Bazaar just did.
130+ out, err = self.run_bzr(
131+ ['launchpad-login', '-v', '--no-check', 'foo'])
132+ self.assertEqual("Launchpad user ID set to 'foo'.\n", out)
133+ self.assertEqual('', err)