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