~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-08-17 07:52:09 UTC
  • mfrom: (1910.3.4 trivial)
  • Revision ID: pqm@pqm.ubuntu.com-20060817075209-e85a1f9e05ff8b87
(andrew) Trivial fixes to NotImplemented errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
"""Tests for Launchpad user ID management functions."""
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
24
 
 
25
 
 
26
 
class LaunchpadAccountTests(TestCaseInTempDir):
27
 
 
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
 
    def test_get_lp_login_unconfigured(self):
35
 
        # Test that get_lp_login() returns None if no username has
36
 
        # been configured.
37
 
        my_config = self.setup_config('')
38
 
        self.assertEqual(None, account.get_lp_login(my_config))
39
 
 
40
 
    def test_get_lp_login(self):
41
 
        # Test that get_lp_login() returns the configured username
42
 
        my_config = self.setup_config(
43
 
            '[DEFAULT]\nlaunchpad_username=test-user\n')
44
 
        self.assertEqual('test-user', account.get_lp_login(my_config))
45
 
 
46
 
    def test_set_lp_login(self):
47
 
        # 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'))
50
 
        account.set_lp_login('test-user', my_config)
51
 
        self.assertEqual(
52
 
            'test-user', my_config.get_user_option('launchpad_username'))
53
 
 
54
 
    def test_unknown_launchpad_username(self):
55
 
        # Test formatting of UnknownLaunchpadUsername exception
56
 
        error = account.UnknownLaunchpadUsername(user='test-user')
57
 
        self.assertEqualDiff('The user name test-user is not registered '
58
 
                             'on Launchpad.', str(error))
59
 
 
60
 
    def test_no_registered_ssh_keys(self):
61
 
        # Test formatting of NoRegisteredSSHKeys exception
62
 
        error = account.NoRegisteredSSHKeys(user='test-user')
63
 
        self.assertEqualDiff('The user test-user has not registered any '
64
 
                             'SSH keys with Launchpad.', str(error))
65
 
 
66
 
 
67
 
class CheckAccountTests(TestCaseWithMemoryTransport):
68
 
 
69
 
    def test_check_lp_login_valid_user(self):
70
 
        transport = self.get_transport()
71
 
        transport.mkdir('~test-user')
72
 
        transport.put_bytes('~test-user/+sshkeys', 'some keys here')
73
 
        account.check_lp_login('test-user', transport)
74
 
 
75
 
    def test_check_lp_login_no_user(self):
76
 
        transport = self.get_transport()
77
 
        self.assertRaises(account.UnknownLaunchpadUsername,
78
 
                          account.check_lp_login, 'test-user', transport)
79
 
 
80
 
    def test_check_lp_login_no_ssh_keys(self):
81
 
        transport = self.get_transport()
82
 
        transport.mkdir('~test-user')
83
 
        transport.put_bytes('~test-user/+sshkeys', '')
84
 
        self.assertRaises(account.NoRegisteredSSHKeys,
85
 
                          account.check_lp_login, 'test-user', transport)