/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/launchpad/test_account.py

  • Committer: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2007-2010 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
16
16
 
17
17
"""Tests for Launchpad user ID management functions."""
18
18
 
19
 
from cStringIO import StringIO
20
 
 
21
 
from bzrlib import config
22
 
from bzrlib.tests import TestCaseInTempDir, TestCaseWithMemoryTransport
23
 
from bzrlib.plugins.launchpad import account
 
19
from ... import config
 
20
from ...tests import TestCaseInTempDir, TestCaseWithMemoryTransport
 
21
from . import account
24
22
 
25
23
 
26
24
class LaunchpadAccountTests(TestCaseInTempDir):
27
25
 
28
 
    def setup_config(self, text):
29
 
        my_config = config.GlobalConfig()
30
 
        config_file = StringIO(text)
31
 
        my_config._get_parser(config_file)
32
 
        return my_config
33
 
 
34
26
    def test_get_lp_login_unconfigured(self):
35
27
        # Test that get_lp_login() returns None if no username has
36
28
        # been configured.
37
 
        my_config = self.setup_config('')
 
29
        my_config = config.MemoryStack(b'')
38
30
        self.assertEqual(None, account.get_lp_login(my_config))
39
31
 
40
32
    def test_get_lp_login(self):
41
33
        # Test that get_lp_login() returns the configured username
42
 
        my_config = self.setup_config(
43
 
            '[DEFAULT]\nlaunchpad_username=test-user\n')
 
34
        my_config = config.MemoryStack(
 
35
            b'[DEFAULT]\nlaunchpad_username=test-user\n')
44
36
        self.assertEqual('test-user', account.get_lp_login(my_config))
45
37
 
46
38
    def test_set_lp_login(self):
47
39
        # Test that set_lp_login() updates the config file.
48
 
        my_config = self.setup_config('')
49
 
        self.assertEqual(None, my_config.get_user_option('launchpad_username'))
 
40
        my_config = config.MemoryStack(b'')
 
41
        self.assertEqual(None, my_config.get('launchpad_username'))
50
42
        account.set_lp_login('test-user', my_config)
51
43
        self.assertEqual(
52
 
            'test-user', my_config.get_user_option('launchpad_username'))
 
44
            'test-user', my_config.get('launchpad_username'))
53
45
 
54
46
    def test_unknown_launchpad_username(self):
55
47
        # Test formatting of UnknownLaunchpadUsername exception
61
53
        # Test formatting of NoRegisteredSSHKeys exception
62
54
        error = account.NoRegisteredSSHKeys(user='test-user')
63
55
        self.assertEqualDiff('The user test-user has not registered any '
64
 
            'SSH keys with Launchpad.\n'
65
 
            'See <https://launchpad.net/people/+me>',
66
 
            str(error))
 
56
                             'SSH keys with Launchpad.\n'
 
57
                             'See <https://launchpad.net/people/+me>',
 
58
                             str(error))
67
59
 
68
60
    def test_set_lp_login_updates_authentication_conf(self):
69
61
        self.assertIs(None, account._get_auth_user())
100
92
        account._set_global_option('bar')
101
93
        e = self.assertRaises(account.MismatchedUsernames,
102
94
                              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))
 
95
        self.assertEqual('breezy.conf and authentication.conf disagree about'
 
96
                         ' launchpad account name.  Please re-run launchpad-login.', str(e))
105
97
 
106
98
 
107
99
class CheckAccountTests(TestCaseWithMemoryTransport):
109
101
    def test_check_lp_login_valid_user(self):
110
102
        transport = self.get_transport()
111
103
        transport.mkdir('~test-user')
112
 
        transport.put_bytes('~test-user/+sshkeys', 'some keys here')
 
104
        transport.put_bytes('~test-user/+sshkeys', b'some keys here')
113
105
        account.check_lp_login('test-user', transport)
114
106
 
115
107
    def test_check_lp_login_no_user(self):
120
112
    def test_check_lp_login_no_ssh_keys(self):
121
113
        transport = self.get_transport()
122
114
        transport.mkdir('~test-user')
123
 
        transport.put_bytes('~test-user/+sshkeys', '')
 
115
        transport.put_bytes('~test-user/+sshkeys', b'')
124
116
        self.assertRaises(account.NoRegisteredSSHKeys,
125
117
                          account.check_lp_login, 'test-user', transport)