~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/launchpad/test_register.py

  • Committer: Patch Queue Manager
  • Date: 2016-02-01 19:13:13 UTC
  • mfrom: (6614.2.2 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20160201191313-wdfvmfff1djde6oq
(vila) Release 2.7.0 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
118
118
                    % (auth_hdrs,))
119
119
            authinfo = auth_hdrs[0]
120
120
            expected_auth = 'testuser@launchpad.net:testpassword'
121
 
            test.assertEquals(authinfo,
 
121
            test.assertEqual(authinfo,
122
122
                    'Basic ' + base64.encodestring(expected_auth).strip())
123
123
        elif http_headers:
124
124
            raise AssertionError()
190
190
        out, err = self.run_bzr(['register-branch',
191
191
                                'http://test-server.com/bzr/branch',
192
192
                                '--dry-run'])
193
 
        self.assertEquals(out, 'Branch registered.\n')
 
193
        self.assertEqual(out, 'Branch registered.\n')
194
194
 
195
195
    def test_onto_transport(self):
196
196
        """How the request is sent by transmitting across a mock Transport"""
206
206
                'author@launchpad.net',
207
207
                'product')
208
208
        rego.submit(service)
209
 
        self.assertEquals(transport.connected_host, 'xmlrpc.launchpad.net')
210
 
        self.assertEquals(len(transport.sent_params), 6)
211
 
        self.assertEquals(transport.sent_params,
 
209
        self.assertEqual(transport.connected_host, 'xmlrpc.launchpad.net')
 
210
        self.assertEqual(len(transport.sent_params), 6)
 
211
        self.assertEqual(transport.sent_params,
212
212
                ('http://test-server.com/bzr/branch',  # branch_url
213
213
                 'branch-id',                          # branch_name
214
214
                 'my test branch',                     # branch_title
223
223
        service = LaunchpadService(transport)
224
224
        resolve = ResolveLaunchpadPathRequest('bzr')
225
225
        resolve.submit(service)
226
 
        self.assertEquals(transport.connected_host, 'xmlrpc.launchpad.net')
227
 
        self.assertEquals(len(transport.sent_params), 1)
228
 
        self.assertEquals(transport.sent_params, ('bzr', ))
 
226
        self.assertEqual(transport.connected_host, 'xmlrpc.launchpad.net')
 
227
        self.assertEqual(len(transport.sent_params), 1)
 
228
        self.assertEqual(transport.sent_params, ('bzr', ))
229
229
        self.assertTrue(transport.got_request)
230
230
 
231
231
    def test_subclass_request(self):
240
240
        service.registrant_password = ''
241
241
        request = DummyRequest()
242
242
        request.submit(service)
243
 
        self.assertEquals(service.called_method_name, 'dummy_request')
244
 
        self.assertEquals(service.called_method_params, (42,))
 
243
        self.assertEqual(service.called_method_name, 'dummy_request')
 
244
        self.assertEqual(service.called_method_params, (42,))
245
245
 
246
246
    def test_mock_server_registration(self):
247
247
        """Send registration to mock server"""
248
248
        test_case = self
249
249
        class MockRegistrationService(MockLaunchpadService):
250
250
            def send_request(self, method_name, method_params, authenticated):
251
 
                test_case.assertEquals(method_name, "register_branch")
252
 
                test_case.assertEquals(list(method_params),
 
251
                test_case.assertEqual(method_name, "register_branch")
 
252
                test_case.assertEqual(list(method_params),
253
253
                        ['url', 'name', 'title', 'description', 'email', 'name'])
254
 
                test_case.assertEquals(authenticated, True)
 
254
                test_case.assertEqual(authenticated, True)
255
255
                return 'result'
256
256
        service = MockRegistrationService()
257
257
        rego = BranchRegistrationRequest('url', 'name', 'title',
258
258
                        'description', 'email', 'name')
259
259
        result = rego.submit(service)
260
 
        self.assertEquals(result, 'result')
 
260
        self.assertEqual(result, 'result')
261
261
 
262
262
    def test_mock_server_registration_with_defaults(self):
263
263
        """Send registration to mock server"""
264
264
        test_case = self
265
265
        class MockRegistrationService(MockLaunchpadService):
266
266
            def send_request(self, method_name, method_params, authenticated):
267
 
                test_case.assertEquals(method_name, "register_branch")
268
 
                test_case.assertEquals(list(method_params),
 
267
                test_case.assertEqual(method_name, "register_branch")
 
268
                test_case.assertEqual(list(method_params),
269
269
                        ['http://server/branch', 'branch', '', '', '', ''])
270
 
                test_case.assertEquals(authenticated, True)
 
270
                test_case.assertEqual(authenticated, True)
271
271
                return 'result'
272
272
        service = MockRegistrationService()
273
273
        rego = BranchRegistrationRequest('http://server/branch')
274
274
        result = rego.submit(service)
275
 
        self.assertEquals(result, 'result')
 
275
        self.assertEqual(result, 'result')
276
276
 
277
277
    def test_mock_bug_branch_link(self):
278
278
        """Send bug-branch link to mock server"""
279
279
        test_case = self
280
280
        class MockService(MockLaunchpadService):
281
281
            def send_request(self, method_name, method_params, authenticated):
282
 
                test_case.assertEquals(method_name, "link_branch_to_bug")
283
 
                test_case.assertEquals(list(method_params),
 
282
                test_case.assertEqual(method_name, "link_branch_to_bug")
 
283
                test_case.assertEqual(list(method_params),
284
284
                        ['http://server/branch', 1234, ''])
285
 
                test_case.assertEquals(authenticated, True)
 
285
                test_case.assertEqual(authenticated, True)
286
286
                return 'http://launchpad.net/bug/1234'
287
287
        service = MockService()
288
288
        rego = BranchBugLinkRequest('http://server/branch', 1234)
289
289
        result = rego.submit(service)
290
 
        self.assertEquals(result, 'http://launchpad.net/bug/1234')
 
290
        self.assertEqual(result, 'http://launchpad.net/bug/1234')
291
291
 
292
292
    def test_mock_resolve_lp_url(self):
293
293
        test_case = self
294
294
        class MockService(MockLaunchpadService):
295
295
            def send_request(self, method_name, method_params, authenticated):
296
 
                test_case.assertEquals(method_name, "resolve_lp_path")
297
 
                test_case.assertEquals(list(method_params), ['bzr'])
298
 
                test_case.assertEquals(authenticated, False)
 
296
                test_case.assertEqual(method_name, "resolve_lp_path")
 
297
                test_case.assertEqual(list(method_params), ['bzr'])
 
298
                test_case.assertEqual(authenticated, False)
299
299
                return dict(urls=[
300
300
                        'bzr+ssh://bazaar.launchpad.net~bzr/bzr/trunk',
301
301
                        'sftp://bazaar.launchpad.net~bzr/bzr/trunk',
305
305
        resolve = ResolveLaunchpadPathRequest('bzr')
306
306
        result = resolve.submit(service)
307
307
        self.assertTrue('urls' in result)
308
 
        self.assertEquals(result['urls'], [
 
308
        self.assertEqual(result['urls'], [
309
309
                'bzr+ssh://bazaar.launchpad.net~bzr/bzr/trunk',
310
310
                'sftp://bazaar.launchpad.net~bzr/bzr/trunk',
311
311
                'bzr+http://bazaar.launchpad.net~bzr/bzr/trunk',
329
329
    def test_gather_user_credentials_from_auth_conf(self):
330
330
        auth_path = config.authentication_config_filename()
331
331
        service = LaunchpadService()
332
 
        g_conf = config.GlobalConfig()
333
 
        g_conf.set_user_option('email', 'Test User <test@user.com>')
 
332
        g_conf = config.GlobalStack()
 
333
        g_conf.set('email', 'Test User <test@user.com>')
 
334
        g_conf.store.save()
 
335
        # FIXME: auth_path base dir exists only because bazaar.conf has just
 
336
        # been saved, brittle... -- vila 20120731
334
337
        f = open(auth_path, 'wb')
335
338
        try:
336
339
            scheme, hostinfo = urlparse.urlsplit(service.service_url)[:2]
350
353
    def test_gather_user_credentials_prompts(self):
351
354
        service = LaunchpadService()
352
355
        self.assertIs(None, service.registrant_password)
353
 
        g_conf = config.GlobalConfig()
354
 
        g_conf.set_user_option('email', 'Test User <test@user.com>')
 
356
        g_conf = config.GlobalStack()
 
357
        g_conf.set('email', 'Test User <test@user.com>')
 
358
        g_conf.store.save()
355
359
        stdout = tests.StringIOWrapper()
356
360
        stderr = tests.StringIOWrapper()
357
361
        ui.ui_factory = tests.TestUIFactory(stdin='userpass\n',
360
364
        service.gather_user_credentials()
361
365
        self.assertEqual('test@user.com', service.registrant_email)
362
366
        self.assertEqual('userpass', service.registrant_password)
363
 
        self.assertEquals('', stdout.getvalue())
 
367
        self.assertEqual('', stdout.getvalue())
364
368
        self.assertContainsRe(stderr.getvalue(),
365
369
                             'launchpad.net password for test@user\\.com')
366
370