def test_lp_branch_shortcut(self): service = LaunchpadService() factory = FakeResolveFactory( self, 'foo', dict(urls=['http://bazaar.launchpad.net/~foo/bar/baz'])) web_url = service.get_web_url_from_branch_url('lp:foo', factory) self.assertEqual('https://code.launchpad.net/~foo/bar/baz', web_url)
def test_lp_branch_shortcut(self): service = LaunchpadService() factory = FakeResolveFactory( self, 'foo', dict(urls=['http://bazaar.launchpad.net/~foo/bar/baz'])) web_url = service.get_web_url_from_branch_url('lp:foo', factory) self.assertEqual( 'https://code.launchpad.net/~foo/bar/baz', web_url)
def test_lp_branch_url(self): service = LaunchpadService(lp_instance='production') factory = FakeResolveFactory( self, '~foo/bar/baz', dict(urls=['http://bazaar.launchpad.net/~foo/bar/baz'])) web_url = service.get_web_url_from_branch_url('lp:~foo/bar/baz', factory) self.assertEqual('https://code.launchpad.net/~foo/bar/baz', web_url)
def test_lp_branch_url(self): service = LaunchpadService(lp_instance='production') factory = FakeResolveFactory( self, '~foo/bar/baz', dict(urls=['http://bazaar.launchpad.net/~foo/bar/baz'])) web_url = service.get_web_url_from_branch_url( 'lp:~foo/bar/baz', factory) self.assertEqual( 'https://code.launchpad.net/~foo/bar/baz', web_url)
def run(self, public_url=None, project='', product=None, branch_name='', branch_title='', branch_description='', author='', link_bug=None, dry_run=False): from bzrlib.plugins.launchpad.lp_registration import ( BranchRegistrationRequest, BranchBugLinkRequest, DryRunLaunchpadService, LaunchpadService) if public_url is None: try: b = _mod_branch.Branch.open_containing('.')[0] except NotBranchError: raise BzrCommandError(gettext( 'register-branch requires a public ' 'branch url - see bzr help register-branch.')) public_url = b.get_public_branch() if public_url is None: raise NoPublicBranch(b) if product is not None: project = product trace.note(gettext( '--product is deprecated; please use --project.')) rego = BranchRegistrationRequest(branch_url=public_url, branch_name=branch_name, branch_title=branch_title, branch_description=branch_description, product_name=project, author_email=author, ) linko = BranchBugLinkRequest(branch_url=public_url, bug_id=link_bug) if not dry_run: service = LaunchpadService() # This gives back the xmlrpc url that can be used for future # operations on the branch. It's not so useful to print to the # user since they can't do anything with it from a web browser; it # might be nice for the server to tell us about an html url as # well. else: # Run on service entirely in memory service = DryRunLaunchpadService() service.gather_user_credentials() rego.submit(service) if link_bug: linko.submit(service) self.outf.write('Branch registered.\n')
def run(self, public_url=None, project='', product=None, branch_name='', branch_title='', branch_description='', author='', link_bug=None, dry_run=False): from bzrlib.plugins.launchpad.lp_registration import ( BranchRegistrationRequest, BranchBugLinkRequest, DryRunLaunchpadService, LaunchpadService) if public_url is None: try: b = _mod_branch.Branch.open_containing('.')[0] except NotBranchError: raise BzrCommandError( gettext('register-branch requires a public ' 'branch url - see bzr help register-branch.')) public_url = b.get_public_branch() if public_url is None: raise NoPublicBranch(b) if product is not None: project = product trace.note( gettext('--product is deprecated; please use --project.')) rego = BranchRegistrationRequest( branch_url=public_url, branch_name=branch_name, branch_title=branch_title, branch_description=branch_description, product_name=project, author_email=author, ) linko = BranchBugLinkRequest(branch_url=public_url, bug_id=link_bug) if not dry_run: service = LaunchpadService() # This gives back the xmlrpc url that can be used for future # operations on the branch. It's not so useful to print to the # user since they can't do anything with it from a web browser; it # might be nice for the server to tell us about an html url as # well. else: # Run on service entirely in memory service = DryRunLaunchpadService() service.gather_user_credentials() rego.submit(service) if link_bug: linko.submit(service) self.outf.write('Branch registered.\n')
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 <*****@*****.**>') 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('*****@*****.**', service.registrant_email) self.assertEqual('userpass', service.registrant_password) self.assertContainsRe(stdout.getvalue(), 'launchpad.net password for test@user\\.com')
def _resolve_via_xmlrpc(self, path, url, _request_factory): service = LaunchpadService.for_url(url) resolve = _request_factory(path) try: result = resolve.submit(service) except xmlrpclib.Fault, fault: raise errors.InvalidURL(path=url, extra=fault.faultString)
def _resolve_via_xmlrpc(self, path, url, _request_factory): service = LaunchpadService.for_url(url) resolve = _request_factory(path) try: result = resolve.submit(service) except xmlrpclib.Fault, fault: raise errors.InvalidURL( path=url, extra=fault.faultString)
def test_non_launchpad_url(self): service = LaunchpadService() error = self.assertRaises(NotLaunchpadBranch, service.get_web_url_from_branch_url, 'bzr+ssh://example.com/~foo/bar/baz') self.assertEqual( 'bzr+ssh://example.com/~foo/bar/baz is not registered on Launchpad.', str(error))
def test_alter_default_service_url(self): LaunchpadService.DEFAULT_SERVICE_URL = 'http://example.com/' try: service = LaunchpadService() self.assertEqual('http://example.com/', service.service_url) finally: LaunchpadService.DEFAULT_SERVICE_URL = \ LaunchpadService.LAUNCHPAD_INSTANCE['production']
def run(self, location=None, dry_run=False): from bzrlib.plugins.launchpad.lp_registration import (LaunchpadService) if location is None: location = u'.' web_url = self._get_web_url(LaunchpadService(), location) trace.note(gettext('Opening %s in web browser') % web_url) if not dry_run: import webbrowser # this import should not be lazy # otherwise bzr.exe lacks this module webbrowser.open(web_url)
def run(self, location='.'): from bzrlib.plugins.launchpad import lp_api from bzrlib.plugins.launchpad.lp_registration import LaunchpadService branch, _ = _mod_branch.Branch.open_containing(location) service = LaunchpadService() launchpad = lp_api.login(service) lp_branch = lp_api.LaunchpadBranch.from_bzr(launchpad, branch, create_missing=False) lp_branch.lp.requestMirror()
def test_onto_transport_unauthenticated(self): """An unauthenticated request is transmitted across a mock Transport""" transport = InstrumentedXMLRPCTransport(self, expect_auth=False) service = LaunchpadService(transport) resolve = ResolveLaunchpadPathRequest('bzr') resolve.submit(service) self.assertEquals(transport.connected_host, 'xmlrpc.launchpad.net') self.assertEquals(len(transport.sent_params), 1) self.assertEquals(transport.sent_params, ('bzr', )) self.assertTrue(transport.got_request)
def test_gather_user_credentials_from_auth_conf(self): auth_path = config.authentication_config_filename() service = LaunchpadService() g_conf = config.GlobalStack() g_conf.set('email', 'Test User <*****@*****.**>') f = open(auth_path, 'wb') try: scheme, hostinfo = urlparse.urlsplit(service.service_url)[:2] f.write('[section]\n' 'scheme=%s\n' 'host=%s\n' '[email protected]\n' 'password=testpass\n' % (scheme, hostinfo)) finally: f.close() self.assertIs(None, service.registrant_password) service.gather_user_credentials() self.assertEqual('*****@*****.**', service.registrant_email) self.assertEqual('testpass', 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 <*****@*****.**>') f = open(auth_path, 'wb') try: scheme, hostinfo = urlparse.urlsplit(service.service_url)[:2] f.write('[section]\n' 'scheme=%s\n' 'host=%s\n' '[email protected]\n' 'password=testpass\n' % (scheme, hostinfo)) finally: f.close() self.assertIs(None, service.registrant_password) service.gather_user_credentials() self.assertEqual('*****@*****.**', service.registrant_email) self.assertEqual('testpass', service.registrant_password)
def test_lp_branch_fault(self): service = LaunchpadService() factory = FakeResolveFactory(self, 'foo', None) def submit(service): raise xmlrpclib.Fault(42, 'something went wrong') factory.submit = submit self.assertRaises(errors.InvalidURL, service.get_web_url_from_branch_url, 'lp:foo', factory)
def test_gather_user_credentials_from_auth_conf(self): auth_path = config.authentication_config_filename() service = LaunchpadService() g_conf = config.GlobalStack() g_conf.set('email', 'Test User <*****@*****.**>') g_conf.store.save() # FIXME: auth_path base dir exists only because bazaar.conf has just # been saved, brittle... -- vila 20120731 f = open(auth_path, 'wb') try: scheme, hostinfo = urlparse.urlsplit(service.service_url)[:2] f.write('[section]\n' 'scheme=%s\n' 'host=%s\n' '[email protected]\n' 'password=testpass\n' % (scheme, hostinfo)) finally: f.close() self.assertIs(None, service.registrant_password) service.gather_user_credentials() self.assertEqual('*****@*****.**', service.registrant_email) self.assertEqual('testpass', service.registrant_password)
def test_onto_transport(self): """How the request is sent by transmitting across a mock Transport""" # use a real transport, but intercept at the http/xml layer transport = InstrumentedXMLRPCTransport(self, expect_auth=True) service = LaunchpadService(transport) service.registrant_email = '*****@*****.**' service.registrant_password = '******' rego = BranchRegistrationRequest('http://test-server.com/bzr/branch', 'branch-id', 'my test branch', 'description', '*****@*****.**', 'product') rego.submit(service) self.assertEquals(transport.connected_host, 'xmlrpc.launchpad.net') self.assertEquals(len(transport.sent_params), 6) self.assertEquals(transport.sent_params, ('http://test-server.com/bzr/branch', # branch_url 'branch-id', # branch_name 'my test branch', # branch_title 'description', '*****@*****.**', 'product')) self.assertTrue(transport.got_request)
def _resolve(self, url, _request_factory=ResolveLaunchpadPathRequest, _lp_login=None): """Resolve the base URL for this transport.""" result = urlsplit(url) # Perform an XMLRPC request to resolve the path lp_instance = result[1] if lp_instance == '': lp_instance = None elif lp_instance not in LaunchpadService.LAUNCHPAD_INSTANCE: raise errors.InvalidURL(path=url) resolve = _request_factory(result[2].strip('/')) service = LaunchpadService(lp_instance=lp_instance) try: result = resolve.submit(service) except xmlrpclib.Fault, fault: raise errors.InvalidURL(path=url, extra=fault.faultString)
def test_product_bzr_ssh_url(self): service = LaunchpadService(lp_instance='production') web_url = service.get_web_url_from_branch_url( 'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz') self.assertEqual( 'https://code.launchpad.net/~foo/bar/baz', web_url)
def test_default_service(self): service = LaunchpadService() self.assertEqual('https://xmlrpc.launchpad.net/bazaar/', service.service_url)
def test_default_bzr_ssh_url(self): service = LaunchpadService() web_url = service.get_web_url_from_branch_url( 'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz') self.assertEqual('https://code.launchpad.net/~foo/bar/baz', web_url)
def test_sftp_branch_url(self): service = LaunchpadService(lp_instance='production') web_url = service.get_web_url_from_branch_url( 'sftp://bazaar.launchpad.net/~foo/bar/baz') self.assertEqual('https://code.launchpad.net/~foo/bar/baz', web_url)
def test_environment_overrides_default(self): os.environ['BZR_LP_XMLRPC_URL'] = 'http://example.com/' service = LaunchpadService() self.assertEqual('http://example.com/', service.service_url)
def test_environment_overrides_specified_service(self): os.environ['BZR_LP_XMLRPC_URL'] = 'http://example.com/' service = LaunchpadService(lp_instance='staging') self.assertEqual('http://example.com/', service.service_url)
def test_demo_service(self): service = LaunchpadService(lp_instance='demo') self.assertEqual('https://xmlrpc.demo.launchpad.net/bazaar/', service.service_url)
def test_default_bzr_ssh_url(self): service = LaunchpadService() web_url = service.get_web_url_from_branch_url( 'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz') self.assertEqual( 'https://code.launchpad.net/~foo/bar/baz', web_url)
def test_dodgy_launchpad_url(self): service = LaunchpadService() self.assertRaises(NotLaunchpadBranch, service.get_web_url_from_branch_url, 'bzr+ssh://launchpad.net/~foo/bar/baz')
def test_dev_service(self): service = LaunchpadService(lp_instance='dev') self.assertEqual('http://xmlrpc.launchpad.dev/bazaar/', service.service_url)
def test_demo_url(self): service = LaunchpadService(lp_instance='demo') web_url = service.get_web_url_from_branch_url( 'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz') self.assertEqual('https://code.demo.launchpad.net/~foo/bar/baz', web_url)
def test_gather_user_credentials_has_password(self): service = LaunchpadService() service.registrant_password = '******' # 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_edge_service(self): service = LaunchpadService(lp_instance='edge') self.assertEqual('https://xmlrpc.edge.launchpad.net/bazaar/', service.service_url)
def test_staging_service(self): service = LaunchpadService(lp_instance='staging') self.assertEqual('https://xmlrpc.staging.launchpad.net/bazaar/', service.service_url)
def test_demo_url(self): service = LaunchpadService(lp_instance='demo') web_url = service.get_web_url_from_branch_url( 'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz') self.assertEqual( 'https://code.demo.launchpad.net/~foo/bar/baz', web_url)