Rev 2992: (John Arbash Meinel) Fix 'bzr register-branch' (bug #162494) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Nov 14 16:24:34 GMT 2007
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 2992
revision-id: pqm at pqm.ubuntu.com-20071114162431-vdx7u28fh4et71b6
parent: pqm at pqm.ubuntu.com-20071114092157-du5ikf6q4k64nseu
parent: john at arbash-meinel.com-20071114150318-j0yvbz7et36s005e
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2007-11-14 16:24:31 +0000
message:
(John Arbash Meinel) Fix 'bzr register-branch' (bug #162494)
modified:
bzrlib/plugins/launchpad/lp_registration.py lp_registration.py-20060315190948-daa617eafe3a8d48
bzrlib/plugins/launchpad/test_register.py test_register.py-20060315182712-40f5dda945c829a8
bzrlib/tests/test_config.py testconfig.py-20051011041908-742d0c15d8d8c8eb
------------------------------------------------------------
revno: 2978.5.2
merged: john at arbash-meinel.com-20071114150318-j0yvbz7et36s005e
parent: john at arbash-meinel.com-20071113220221-6kkzbczr91r0gmbt
parent: pqm at pqm.ubuntu.com-20071114092157-du5ikf6q4k64nseu
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: launchpad_plugin_162494
timestamp: Wed 2007-11-14 09:03:18 -0600
message:
merge bzr.dev 2991
------------------------------------------------------------
revno: 2978.5.1
merged: john at arbash-meinel.com-20071113220221-6kkzbczr91r0gmbt
parent: pqm at pqm.ubuntu.com-20071109195036-5o5bwu0a01uniqwg
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: launchpad_plugin_162494
timestamp: Tue 2007-11-13 16:02:21 -0600
message:
Fix bug #162494, 'bzr register-branch' needs proper auth handling.
The recent fix to use ~/.bazaar/authentication.conf had some small bugs.
It was not passing a user to auth.get_password(), and it was accidentally
using a local variable with the same name as a global.
Add tests that gather_user_credentials() gets proper values.
=== modified file 'bzrlib/plugins/launchpad/lp_registration.py'
--- a/bzrlib/plugins/launchpad/lp_registration.py 2007-11-12 21:23:07 +0000
+++ b/bzrlib/plugins/launchpad/lp_registration.py 2007-11-14 15:03:18 +0000
@@ -99,8 +99,8 @@
def gather_user_credentials(self):
"""Get the password from the user."""
- config = config.GlobalConfig()
- self.registrant_email = config.user_email()
+ the_config = config.GlobalConfig()
+ self.registrant_email = the_config.user_email()
if self.registrant_password is None:
auth = config.AuthenticationConfig()
scheme, hostinfo = urlsplit(self.service_url)[:2]
@@ -109,6 +109,7 @@
# We will reuse http[s] credentials if we can, prompt user
# otherwise
self.registrant_password = auth.get_password(scheme, hostinfo,
+ self.registrant_email,
prompt=prompt)
def send_request(self, method_name, method_params, authenticated):
=== modified file 'bzrlib/plugins/launchpad/test_register.py'
--- a/bzrlib/plugins/launchpad/test_register.py 2007-10-14 09:52:55 +0000
+++ b/bzrlib/plugins/launchpad/test_register.py 2007-11-14 15:03:18 +0000
@@ -17,8 +17,15 @@
import base64
import os
from StringIO import StringIO
+import urlparse
import xmlrpclib
+from bzrlib import (
+ config,
+ osutils,
+ tests,
+ ui,
+ )
from bzrlib.tests import TestCase, TestSkipped
# local import
@@ -130,8 +137,7 @@
def setUp(self):
super(TestBranchRegistration, self).setUp()
# make sure we have a reproducible standard environment
- if 'BZR_LP_XMLRPC_URL' in os.environ:
- del os.environ['BZR_LP_XMLRPC_URL']
+ self._captureVar('BZR_LP_XMLRPC_URL', None)
def test_register_help(self):
"""register-branch accepts --help"""
@@ -266,3 +272,55 @@
'sftp://bazaar.launchpad.net~bzr/bzr/trunk',
'bzr+http://bazaar.launchpad.net~bzr/bzr/trunk',
'http://bazaar.launchpad.net~bzr/bzr/trunk'])
+
+
+class TestGatherUserCredentials(tests.TestCaseInTempDir):
+
+ def setUp(self):
+ super(TestGatherUserCredentials, self).setUp()
+ # make sure we have a reproducible standard environment
+ self._captureVar('BZR_LP_XMLRPC_URL', None)
+
+ def test_gather_user_credentials_has_password(self):
+ service = LaunchpadService()
+ service.registrant_password = 'mypassword'
+ # This should be a basic no-op, since we already have the password
+ service.gather_user_credentials()
+ self.assertEqual('mypassword', service.registrant_password)
+
+ def test_gather_user_credentials_from_auth_conf(self):
+ auth_path = config.authentication_config_filename()
+ service = LaunchpadService()
+ g_conf = config.GlobalConfig()
+ g_conf.set_user_option('email', 'Test User <test at user.com>')
+ f = open(auth_path, 'wb')
+ try:
+ scheme, hostinfo = urlparse.urlsplit(service.service_url)[:2]
+ f.write('[section]\n'
+ 'scheme=%s\n'
+ 'host=%s\n'
+ 'user=test at user.com\n'
+ 'password=testpass\n'
+ % (scheme, hostinfo))
+ finally:
+ f.close()
+ self.assertIs(None, service.registrant_password)
+ service.gather_user_credentials()
+ self.assertEqual('test at user.com', service.registrant_email)
+ self.assertEqual('testpass', service.registrant_password)
+
+ def test_gather_user_credentials_prompts(self):
+ service = LaunchpadService()
+ self.assertIs(None, service.registrant_password)
+ g_conf = config.GlobalConfig()
+ g_conf.set_user_option('email', 'Test User <test at user.com>')
+ stdout = tests.StringIOWrapper()
+ ui.ui_factory = tests.TestUIFactory(stdin='userpass\n',
+ stdout=stdout)
+ self.assertIs(None, service.registrant_password)
+ service.gather_user_credentials()
+ self.assertEqual('test at user.com', service.registrant_email)
+ self.assertEqual('userpass', service.registrant_password)
+ self.assertContainsRe(stdout.getvalue(),
+ 'launchpad.net password for test at user\\.com')
+
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2007-10-23 14:31:10 +0000
+++ b/bzrlib/tests/test_config.py 2007-11-13 22:02:21 +0000
@@ -1133,7 +1133,7 @@
self.assertEquals(expected_user, user)
self.assertEquals(expected_password, password)
- def test_empty_config(self):
+ def test_empty_config(self):
conf = config.AuthenticationConfig(_file=StringIO())
self.assertEquals({}, conf._get_config())
self._got_user_passwd(None, None, conf, 'http', 'foo.net')
More information about the bazaar-commits
mailing list