17
17
"""Black-box tests for bzr nick."""
27
class TestNick(tests.TestCaseWithTransport):
29
def assertNick(self, expected, working_dir='.', explicit=None,
32
if directory is not None:
33
cmd.extend(['--directory', directory])
34
# The nick command outputs the nick on a single line
35
actual = self.run_bzr(cmd, working_dir=working_dir)[0][:-1]
36
self.assertEquals(expected, actual)
37
if explicit is not None:
38
br = branch.Branch.open(working_dir)
39
conf = br.get_config()
40
self.assertEquals(explicit, conf.has_explicit_nickname())
42
self.assertEquals(expected, conf._get_explicit_nickname())
22
from bzrlib import osutils
23
from bzrlib.tests.blackbox import ExternalBase
26
class TestNick(ExternalBase):
44
28
def test_nick_command(self):
45
29
"""bzr nick for viewing, setting nicknames"""
46
30
self.make_branch_and_tree('me.dev')
47
self.assertNick('me.dev', working_dir='me.dev')
32
nick = self.run_bzr('nick')[0]
33
self.assertEqual(nick, 'me.dev\n')
49
self.run_bzr("nick moo", working_dir='me.dev')
50
self.assertNick('moo', working_dir='me.dev')
35
self.run_bzr("nick moo")
36
nick = self.run_bzr('nick')[0]
37
self.assertEqual(nick, 'moo\n')
52
39
def test_autonick_urlencoded(self):
53
40
# https://bugs.launchpad.net/bzr/+bug/66857 -- nick was printed
54
41
# urlencoded but shouldn't be
55
42
self.make_branch_and_tree('!repo')
56
self.assertNick('!repo', working_dir='!repo')
44
nick = self.run_bzr('nick')[0]
45
self.assertEqual(nick, '!repo\n')
58
47
def test_bound_nick(self):
59
"""Bind should not update implicit nick."""
60
base = self.make_branch_and_tree('base')
61
child = self.make_branch_and_tree('child')
62
self.assertNick('child', working_dir='child', explicit=False)
64
self.run_bzr('bind ../base', working_dir='child')
65
self.assertNick(base.branch.nick, working_dir='child', explicit=False)
67
def test_bound_nick_explicit(self):
68
"""Bind should update explicit nick."""
69
base = self.make_branch_and_tree('base')
70
child = self.make_branch_and_tree('child')
71
self.run_bzr("nick explicit_nick", working_dir='child')
72
self.assertNick('explicit_nick', working_dir='child', explicit=True)
73
self.run_bzr('bind ../base', working_dir='child')
74
self.assertNick(base.branch.nick, working_dir='child', explicit=True)
48
"""Check that nick works well for checkouts."""
49
base = self.make_branch_and_tree('base')
50
child = self.make_branch_and_tree('child')
52
self.assertEqual(self.run_bzr('nick')[0][:-1], 'child')
53
self.assertEqual(child.branch.get_config().has_explicit_nickname(),
55
self.run_bzr('bind ../base')
56
self.assertEqual(self.run_bzr('nick')[0][:-1], base.branch.nick)
57
self.assertEqual(child.branch.get_config().has_explicit_nickname(),
60
self.run_bzr('unbind')
61
self.run_bzr("nick explicit_nick")
62
self.assertEqual(self.run_bzr('nick')[0][:-1], "explicit_nick")
63
self.assertEqual(child.branch.get_config()._get_explicit_nickname(),
65
self.run_bzr('bind ../base')
66
self.assertEqual(self.run_bzr('nick')[0][:-1], base.branch.nick)
67
self.assertEqual(child.branch.get_config()._get_explicit_nickname(),
76
70
def test_boundless_nick(self):
77
71
"""Nick defaults to implicit local nick when bound branch is AWOL"""
78
72
base = self.make_branch_and_tree('base')
79
73
child = self.make_branch_and_tree('child')
80
self.run_bzr('bind ../base', working_dir='child')
81
self.assertNick(base.branch.nick, working_dir='child', explicit=False)
82
osutils.rmtree('base')
83
self.assertNick('child', working_dir='child', explicit=False)
85
def test_nick_directory(self):
86
"""Test --directory option"""
87
self.make_branch_and_tree('me.dev')
88
self.assertNick('me.dev', directory='me.dev')
89
self.run_bzr(['nick', '-d', 'me.dev', 'moo'])
90
self.assertNick('moo', directory='me.dev')
75
self.run_bzr('bind ../base')
76
self.assertEqual(self.run_bzr('nick')[0][:-1], base.branch.nick)
77
self.assertEqual(child.branch.get_config().has_explicit_nickname(),
79
osutils.rmtree('../base')
80
self.assertEqual(self.run_bzr('nick')[0][:-1], 'child')