/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 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
1816.2.10 by Robey Pointer
code style changes
18
"""Black-box tests for bzr whoami."""
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
19
20
import os
21
22
import bzrlib
5171.3.18 by Andrew Bennetts
Specifically assert that setting an identity with --directory and --branch sets it in the branch, not globally.
23
from bzrlib import (
24
    osutils,
25
    config,
26
    )
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
27
from bzrlib.tests import TestCaseWithTransport
28
29
30
class TestWhoami(TestCaseWithTransport):
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
31
32
    def test_whoami(self):
33
        # this should always identify something, if only "john@localhost"
1816.2.5 by Robey Pointer
clean up whoami tests a bit
34
        out = self.run_bzr("whoami")[0]
35
        self.assertTrue(len(out) > 0)
1816.2.10 by Robey Pointer
code style changes
36
        self.assertEquals(1, out.count('@'))
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
37
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
38
        out = self.run_bzr("whoami --email")[0]
1816.2.5 by Robey Pointer
clean up whoami tests a bit
39
        self.assertTrue(len(out) > 0)
1816.2.10 by Robey Pointer
code style changes
40
        self.assertEquals(1, out.count('@'))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
41
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
42
    def test_whoami_branch(self):
43
        """branch specific user identity works."""
1816.2.10 by Robey Pointer
code style changes
44
        wt = self.make_branch_and_tree('.')
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
45
        b = bzrlib.branch.Branch.open('.')
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
46
        b.get_config().set_user_option('email',
47
                                       '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.
48
        whoami = self.run_bzr("whoami")[0]
49
        self.assertEquals('Branch Identity <branch@identi.ty>\n', whoami)
50
        whoami_email = self.run_bzr("whoami --email")[0]
51
        self.assertEquals('branch@identi.ty\n', whoami_email)
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
52
5171.3.16 by Andrew Bennetts
Remove redundant clearing and restoring of BZR_EMAIL; the TestCase base class already takes care of that.
53
        # Verify that the environment variable overrides the value
54
        # in the file
55
        os.environ['BZR_EMAIL'] = 'Different ID <other@environ.ment>'
56
        whoami = self.run_bzr("whoami")[0]
57
        self.assertEquals('Different ID <other@environ.ment>\n', whoami)
58
        whoami_email = self.run_bzr("whoami --email")[0]
59
        self.assertEquals('other@environ.ment\n', whoami_email)
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
60
61
    def test_whoami_utf8(self):
62
        """verify that an identity can be in utf-8."""
1816.2.10 by Robey Pointer
code style changes
63
        wt = self.make_branch_and_tree('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
64
        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
65
                     encoding='utf-8')
5171.3.16 by Andrew Bennetts
Remove redundant clearing and restoring of BZR_EMAIL; the TestCase base class already takes care of that.
66
        whoami = self.run_bzr("whoami", encoding='utf-8')[0]
67
        self.assertEquals('Branch Identity \xe2\x82\xac ' +
68
                          '<branch@identi.ty>\n', whoami)
69
        whoami_email = self.run_bzr("whoami --email", encoding='utf-8')[0]
70
        self.assertEquals('branch@identi.ty\n', whoami_email)
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
71
72
    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
73
        """
74
        verify that whoami doesn't totally break when in utf-8, using an ascii
75
        encoding.
76
        """
1816.2.10 by Robey Pointer
code style changes
77
        wt = self.make_branch_and_tree('.')
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
78
        b = bzrlib.branch.Branch.open('.')
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
79
        b.get_config().set_user_option('email', u'Branch Identity \u20ac ' +
80
                                       '<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.
81
        whoami = self.run_bzr("whoami", encoding='ascii')[0]
82
        self.assertEquals('Branch Identity ? <branch@identi.ty>\n', whoami)
83
        whoami_email = self.run_bzr("whoami --email", encoding='ascii')[0]
84
        self.assertEquals('branch@identi.ty\n', whoami_email)
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
85
86
    def test_warning(self):
87
        """verify that a warning is displayed if no email is given."""
88
        self.make_branch_and_tree('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
89
        display = self.run_bzr(['whoami', 'Branch Identity'])[1]
1840.1.5 by Robey Pointer
change the warning message for a 'whoami' with no email address, on jam's recommendation
90
        self.assertEquals('"Branch Identity" does not seem to contain an '
91
                          'email address.  This is allowed, but not '
92
                          'recommended.\n', display)
5187.2.4 by Parth Malwankar
added tests.
93
94
    def test_whoami_not_set(self):
95
        """Ensure whoami error if username is not set.
96
        """
97
        osutils.set_or_unset_env('EMAIL', None)
98
        osutils.set_or_unset_env('BZR_EMAIL', None)
99
        out, err = self.run_bzr(['whoami'], 3)
100
        self.assertContainsRe(err, 'Unable to determine your name')
5171.3.15 by Martin von Gagern
Add --directory option to whoami.
101
102
    def test_whoami_directory(self):
5171.3.17 by Andrew Bennetts
Tweak docstrings.
103
        """Test --directory option."""
5171.3.15 by Martin von Gagern
Add --directory option to whoami.
104
        wt = self.make_branch_and_tree('subdir')
105
        c = wt.branch.get_config()
106
        c.set_user_option('email', '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.
107
        out, err = self.run_bzr("whoami --directory subdir")
108
        self.assertEquals('Branch Identity <branch@identi.ty>\n', out)
109
        self.run_bzr(['whoami', '--directory', 'subdir', '--branch',
110
                      'Changed Identity <changed@identi.ty>'])
111
        self.assertEquals('Changed Identity <changed@identi.ty>',
112
                          c.get_user_option('email'))
5171.3.15 by Martin von Gagern
Add --directory option to whoami.
113
114
    def test_whoami_remote_directory(self):
5171.3.17 by Andrew Bennetts
Tweak docstrings.
115
        """Test --directory option with a remote directory."""
5171.3.15 by Martin von Gagern
Add --directory option to whoami.
116
        wt = self.make_branch_and_tree('subdir')
117
        c = wt.branch.get_config()
118
        c.set_user_option('email', '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.
119
        url = self.get_readonly_url() + '/subdir'
120
        out, err = self.run_bzr(['whoami', '--directory', url])
121
        self.assertEquals('Branch Identity <branch@identi.ty>\n', out)
122
        url = self.get_url('subdir')
123
        self.run_bzr(['whoami', '--directory', url, '--branch',
124
                      '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.
125
        # The identity has been set in the branch config (but not the global
126
        # config)
5171.3.16 by Andrew Bennetts
Remove redundant clearing and restoring of BZR_EMAIL; the TestCase base class already takes care of that.
127
        self.assertEquals('Changed Identity <changed@identi.ty>',
128
                          c.get_user_option('email'))
5171.3.18 by Andrew Bennetts
Specifically assert that setting an identity with --directory and --branch sets it in the branch, not globally.
129
        global_conf = config.GlobalConfig()
130
        self.assertEquals(None, global_conf.get_user_option('email'))
5171.3.15 by Martin von Gagern
Add --directory option to whoami.
131
132
    def test_whoami_nonbranch_directory(self):
5171.3.17 by Andrew Bennetts
Tweak docstrings.
133
        """Test --directory mentioning a non-branch directory."""
5171.3.15 by Martin von Gagern
Add --directory option to whoami.
134
        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.
135
        out, err = self.run_bzr("whoami --directory subdir", retcode=3)
136
        self.assertContainsRe(err, 'ERROR: Not a branch')