1
# Copyright (C) 2007, 2008 Canonical Ltd
1
# Copyright (C) 2007-2010 Canonical Ltd
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
17
17
"""Tests for Launchpad user ID management functions."""
19
from cStringIO import StringIO
21
19
from bzrlib import config
22
20
from bzrlib.tests import TestCaseInTempDir, TestCaseWithMemoryTransport
23
21
from bzrlib.plugins.launchpad import account
26
24
class LaunchpadAccountTests(TestCaseInTempDir):
28
def setup_config(self, text):
29
my_config = config.GlobalConfig()
30
config_file = StringIO(text)
31
my_config._get_parser(config_file)
34
26
def test_get_lp_login_unconfigured(self):
35
27
# Test that get_lp_login() returns None if no username has
37
my_config = self.setup_config('')
29
my_config = config.MemoryStack('')
38
30
self.assertEqual(None, account.get_lp_login(my_config))
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(
34
my_config = config.MemoryStack(
43
35
'[DEFAULT]\nlaunchpad_username=test-user\n')
44
36
self.assertEqual('test-user', account.get_lp_login(my_config))
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('')
41
self.assertEqual(None, my_config.get('launchpad_username'))
50
42
account.set_lp_login('test-user', my_config)
52
'test-user', my_config.get_user_option('launchpad_username'))
44
'test-user', my_config.get('launchpad_username'))
54
46
def test_unknown_launchpad_username(self):
55
47
# Test formatting of UnknownLaunchpadUsername exception