/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2006, 2007, 2009-2012, 2016 Canonical Ltd
1816.2.10 by Robey Pointer
code style changes
2
#
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
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.
1816.2.10 by Robey Pointer
code style changes
7
#
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
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.
1816.2.10 by Robey Pointer
code style changes
12
#
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
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
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
16
17
6622.1.29 by Jelmer Vernooij
Fix some more tests.
18
"""Black-box tests for brz whoami."""
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
19
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
20
from breezy import (
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
21
    branch,
5171.3.18 by Andrew Bennetts
Specifically assert that setting an identity with --directory and --branch sets it in the branch, not globally.
22
    config,
6421.3.3 by Vincent Ladeuil
Mwhahaha. You cannot get None for email not being set in bazaar.conf. On the other hand, a test raising NoWhoami was missing here ;)
23
    errors,
5991.1.1 by Vincent Ladeuil
Slightly simplify whoami tests.
24
    tests,
5171.3.18 by Andrew Bennetts
Specifically assert that setting an identity with --directory and --branch sets it in the branch, not globally.
25
    )
5991.1.1 by Vincent Ladeuil
Slightly simplify whoami tests.
26
7344.1.1 by Martin
Fix tests that need whoami not to be set
27
from ..test_bedding import override_whoami
28
5991.1.1 by Vincent Ladeuil
Slightly simplify whoami tests.
29
30
class TestWhoami(tests.TestCaseWithTransport):
31
32
    def assertWhoAmI(self, expected, *cmd_args, **kwargs):
33
        out, err = self.run_bzr(('whoami',) + cmd_args, **kwargs)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
34
        self.assertEqual('', err)
5991.1.1 by Vincent Ladeuil
Slightly simplify whoami tests.
35
        lines = out.splitlines()
36
        self.assertLength(1, lines)
7479.2.1 by Jelmer Vernooij
Drop python2 support.
37
        if isinstance(expected, bytes):
7045.2.2 by Jelmer Vernooij
Fix whoami test.
38
            expected = expected.decode(kwargs.get('encoding', 'ascii'))
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
39
        self.assertEqual(expected, lines[0].rstrip())
5991.1.1 by Vincent Ladeuil
Slightly simplify whoami tests.
40
41
    def test_whoami_no_args_no_conf(self):
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
42
        # this should always identify something, if only "john@localhost"
1816.2.5 by Robey Pointer
clean up whoami tests a bit
43
        out = self.run_bzr("whoami")[0]
44
        self.assertTrue(len(out) > 0)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
45
        self.assertEqual(1, out.count('@'))
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
46
5991.1.1 by Vincent Ladeuil
Slightly simplify whoami tests.
47
    def test_whoami_email_no_args(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
48
        out = self.run_bzr("whoami --email")[0]
1816.2.5 by Robey Pointer
clean up whoami tests a bit
49
        self.assertTrue(len(out) > 0)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
50
        self.assertEqual(1, out.count('@'))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
51
5616.3.1 by Jelmer Vernooij
Print error if both --email and a new identity were specified.
52
    def test_whoami_email_arg(self):
53
        # whoami --email is mutually exclusive with any arguments
54
        out = self.run_bzr("whoami --email 'foo <foo@example.com>'", 3)[0]
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
55
        self.assertEqual("", out)
5616.3.1 by Jelmer Vernooij
Print error if both --email and a new identity were specified.
56
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
57
    def set_branch_email(self, b, email):
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
58
        b.get_config_stack().set('email', email)
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
59
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
60
    def test_whoami_branch(self):
61
        """branch specific user identity works."""
1816.2.10 by Robey Pointer
code style changes
62
        wt = self.make_branch_and_tree('.')
7344.1.1 by Martin
Fix tests that need whoami not to be set
63
        b = branch.Branch.open('.')
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
64
        self.set_branch_email(b, 'Branch Identity <branch@identi.ty>')
5991.1.1 by Vincent Ladeuil
Slightly simplify whoami tests.
65
        self.assertWhoAmI('Branch Identity <branch@identi.ty>')
66
        self.assertWhoAmI('branch@identi.ty', '--email')
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
67
5171.3.16 by Andrew Bennetts
Remove redundant clearing and restoring of BZR_EMAIL; the TestCase base class already takes care of that.
68
        # Verify that the environment variable overrides the value
69
        # in the file
6622.1.28 by Jelmer Vernooij
More renames; commands in output, environment variables.
70
        self.overrideEnv('BRZ_EMAIL', 'Different ID <other@environ.ment>')
5991.1.1 by Vincent Ladeuil
Slightly simplify whoami tests.
71
        self.assertWhoAmI('Different ID <other@environ.ment>')
72
        self.assertWhoAmI('other@environ.ment', '--email')
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
73
74
    def test_whoami_utf8(self):
75
        """verify that an identity can be in utf-8."""
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
76
        self.run_bzr(['whoami', u'Branch Identity \u20ac <branch@identi.ty>'],
1840.1.3 by Robey Pointer
fix some 80col wrapping and add a blackbox test to verify that a warning is displayed when a non-email identity is set
77
                     encoding='utf-8')
7045.2.2 by Jelmer Vernooij
Fix whoami test.
78
        self.assertWhoAmI(b'Branch Identity \xe2\x82\xac <branch@identi.ty>',
5991.1.1 by Vincent Ladeuil
Slightly simplify whoami tests.
79
                          encoding='utf-8')
80
        self.assertWhoAmI('branch@identi.ty', '--email')
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
81
82
    def test_whoami_ascii(self):
1840.1.3 by Robey Pointer
fix some 80col wrapping and add a blackbox test to verify that a warning is displayed when a non-email identity is set
83
        """
84
        verify that whoami doesn't totally break when in utf-8, using an ascii
85
        encoding.
86
        """
1816.2.10 by Robey Pointer
code style changes
87
        wt = self.make_branch_and_tree('.')
7344.1.1 by Martin
Fix tests that need whoami not to be set
88
        b = branch.Branch.open('.')
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
89
        self.set_branch_email(b, u'Branch Identity \u20ac <branch@identi.ty>')
5991.1.1 by Vincent Ladeuil
Slightly simplify whoami tests.
90
        self.assertWhoAmI('Branch Identity ? <branch@identi.ty>',
91
                          encoding='ascii')
92
        self.assertWhoAmI('branch@identi.ty', '--email',
93
                          encoding='ascii')
1840.1.3 by Robey Pointer
fix some 80col wrapping and add a blackbox test to verify that a warning is displayed when a non-email identity is set
94
95
    def test_warning(self):
96
        """verify that a warning is displayed if no email is given."""
97
        self.make_branch_and_tree('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
98
        display = self.run_bzr(['whoami', 'Branch Identity'])[1]
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
99
        self.assertEqual('"Branch Identity" does not seem to contain an '
7143.15.2 by Jelmer Vernooij
Run autopep8.
100
                         'email address.  This is allowed, but not '
101
                         'recommended.\n', display)
5187.2.4 by Parth Malwankar
added tests.
102
103
    def test_whoami_not_set(self):
5609.31.1 by mbp at sourcefrog
Blackbox tests for no identity set must disable whoami inference
104
        """Ensure whoami error if username is not set and not inferred.
5187.2.4 by Parth Malwankar
added tests.
105
        """
7344.1.1 by Martin
Fix tests that need whoami not to be set
106
        override_whoami(self)
5187.2.4 by Parth Malwankar
added tests.
107
        out, err = self.run_bzr(['whoami'], 3)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
108
        self.assertContainsRe(err, 'Unable to determine your name')
5171.3.15 by Martin von Gagern
Add --directory option to whoami.
109
110
    def test_whoami_directory(self):
5171.3.17 by Andrew Bennetts
Tweak docstrings.
111
        """Test --directory option."""
5171.3.15 by Martin von Gagern
Add --directory option to whoami.
112
        wt = self.make_branch_and_tree('subdir')
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
113
        self.set_branch_email(wt.branch, 'Branch Identity <branch@identi.ty>')
5991.1.1 by Vincent Ladeuil
Slightly simplify whoami tests.
114
        self.assertWhoAmI('Branch Identity <branch@identi.ty>',
115
                          '--directory', 'subdir')
5171.3.16 by Andrew Bennetts
Remove redundant clearing and restoring of BZR_EMAIL; the TestCase base class already takes care of that.
116
        self.run_bzr(['whoami', '--directory', 'subdir', '--branch',
117
                      'Changed Identity <changed@identi.ty>'])
6404.6.6 by Vincent Ladeuil
Use idioms coherently and add comments to make their purpose clearer.
118
        # Refresh wt as 'whoami' modified it
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
119
        wt = wt.controldir.open_workingtree()
6404.6.6 by Vincent Ladeuil
Use idioms coherently and add comments to make their purpose clearer.
120
        c = wt.branch.get_config_stack()
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
121
        self.assertEqual('Changed Identity <changed@identi.ty>',
7143.15.2 by Jelmer Vernooij
Run autopep8.
122
                         c.get('email'))
5171.3.15 by Martin von Gagern
Add --directory option to whoami.
123
124
    def test_whoami_remote_directory(self):
5171.3.17 by Andrew Bennetts
Tweak docstrings.
125
        """Test --directory option with a remote directory."""
5171.3.15 by Martin von Gagern
Add --directory option to whoami.
126
        wt = self.make_branch_and_tree('subdir')
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
127
        self.set_branch_email(wt.branch, 'Branch Identity <branch@identi.ty>')
5171.3.16 by Andrew Bennetts
Remove redundant clearing and restoring of BZR_EMAIL; the TestCase base class already takes care of that.
128
        url = self.get_readonly_url() + '/subdir'
5991.1.1 by Vincent Ladeuil
Slightly simplify whoami tests.
129
        self.assertWhoAmI('Branch Identity <branch@identi.ty>',
130
                          '--directory', url)
5171.3.16 by Andrew Bennetts
Remove redundant clearing and restoring of BZR_EMAIL; the TestCase base class already takes care of that.
131
        url = self.get_url('subdir')
132
        self.run_bzr(['whoami', '--directory', url, '--branch',
133
                      'Changed Identity <changed@identi.ty>'])
5171.3.18 by Andrew Bennetts
Specifically assert that setting an identity with --directory and --branch sets it in the branch, not globally.
134
        # The identity has been set in the branch config (but not the global
135
        # config)
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
136
        c = branch.Branch.open(url).get_config_stack()
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
137
        self.assertEqual('Changed Identity <changed@identi.ty>',
7143.15.2 by Jelmer Vernooij
Run autopep8.
138
                         c.get('email'))
6740.1.1 by Jelmer Vernooij
Rename bazaar.conf to breezy.conf.
139
        # Ensuring that the value does not come from the breezy.conf file
6421.3.1 by Vincent Ladeuil
Migrate more branch options to config stacks.
140
        # itself requires some isolation setup
7344.1.1 by Martin
Fix tests that need whoami not to be set
141
        override_whoami(self)
6421.3.1 by Vincent Ladeuil
Migrate more branch options to config stacks.
142
        global_conf = config.GlobalStack()
7336.2.1 by Martin
Split non-ini config methods to bedding
143
        self.assertRaises(errors.NoWhoami, global_conf.get, 'email')
5171.3.15 by Martin von Gagern
Add --directory option to whoami.
144
145
    def test_whoami_nonbranch_directory(self):
5171.3.17 by Andrew Bennetts
Tweak docstrings.
146
        """Test --directory mentioning a non-branch directory."""
5171.3.15 by Martin von Gagern
Add --directory option to whoami.
147
        wt = self.build_tree(['subdir/'])
5171.3.16 by Andrew Bennetts
Remove redundant clearing and restoring of BZR_EMAIL; the TestCase base class already takes care of that.
148
        out, err = self.run_bzr("whoami --directory subdir", retcode=3)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
149
        self.assertContainsRe(err, 'ERROR: Not a branch')