~bzr-pqm/bzr/bzr.dev

6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
1
# Copyright (C) 2006-2010, 2012 Canonical Ltd
2120.5.1 by Alexander Belchenko
Added test for bug #66857 (autonick is urlencoded)
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2120.5.1 by Alexander Belchenko
Added test for bug #66857 (autonick is urlencoded)
16
17
"""Black-box tests for bzr nick."""
18
19
import bzrlib
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
20
from bzrlib import (
21
    branch,
22
    osutils,
23
    tests,
24
    )
25
26
27
class TestNick(tests.TestCaseWithTransport):
28
29
    def assertNick(self, expected, working_dir='.', explicit=None,
30
                   directory=None):
31
        cmd = ['nick']
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())
41
            if explicit:
42
                self.assertEquals(expected, conf._get_explicit_nickname())
2120.5.1 by Alexander Belchenko
Added test for bug #66857 (autonick is urlencoded)
43
44
    def test_nick_command(self):
45
        """bzr nick for viewing, setting nicknames"""
2664.11.1 by Daniel Watkins
tests.blackbox.test_nick now uses internals where appropriate.
46
        self.make_branch_and_tree('me.dev')
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
47
        self.assertNick('me.dev', working_dir='me.dev')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
48
        # set the nickname
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
49
        self.run_bzr("nick moo", working_dir='me.dev')
50
        self.assertNick('moo', working_dir='me.dev')
2120.5.1 by Alexander Belchenko
Added test for bug #66857 (autonick is urlencoded)
51
52
    def test_autonick_urlencoded(self):
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
53
        # https://bugs.launchpad.net/bzr/+bug/66857 -- nick was printed
54
        # urlencoded but shouldn't be
2664.11.1 by Daniel Watkins
tests.blackbox.test_nick now uses internals where appropriate.
55
        self.make_branch_and_tree('!repo')
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
56
        self.assertNick('!repo', working_dir='!repo')
3565.6.12 by Marius Kruger
add some more blackbox tests for nick
57
58
    def test_bound_nick(self):
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
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)
63
64
        self.run_bzr('bind ../base', working_dir='child')
65
        self.assertNick(base.branch.nick, working_dir='child', explicit=False)
66
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)
3565.6.12 by Marius Kruger
add some more blackbox tests for nick
75
76
    def test_boundless_nick(self):
77
        """Nick defaults to implicit local nick when bound branch is AWOL"""
78
        base = self.make_branch_and_tree('base')
79
        child = self.make_branch_and_tree('child')
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
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)
5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
84
85
    def test_nick_directory(self):
86
        """Test --directory option"""
87
        self.make_branch_and_tree('me.dev')
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
88
        self.assertNick('me.dev', directory='me.dev')
5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
89
        self.run_bzr(['nick', '-d', 'me.dev', 'moo'])
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
90
        self.assertNick('moo', directory='me.dev')