21
21
from bzrlib import (
27
class TestWhoami(tests.TestCaseWithTransport):
29
def assertWhoAmI(self, expected, *cmd_args, **kwargs):
30
out, err = self.run_bzr(('whoami',) + cmd_args, **kwargs)
31
self.assertEquals('', err)
32
lines = out.splitlines()
33
self.assertLength(1, lines)
34
self.assertEquals(expected, lines[0].rstrip())
36
def test_whoami_no_args_no_conf(self):
24
from bzrlib.tests import TestCaseWithTransport
27
class TestWhoami(TestCaseWithTransport):
29
def test_whoami(self):
37
30
# this should always identify something, if only "john@localhost"
38
31
out = self.run_bzr("whoami")[0]
39
32
self.assertTrue(len(out) > 0)
40
33
self.assertEquals(1, out.count('@'))
42
def test_whoami_email_no_args(self):
43
35
out = self.run_bzr("whoami --email")[0]
44
36
self.assertTrue(len(out) > 0)
45
37
self.assertEquals(1, out.count('@'))
55
47
b = bzrlib.branch.Branch.open('.')
56
48
b.get_config().set_user_option('email',
57
49
'Branch Identity <branch@identi.ty>')
58
self.assertWhoAmI('Branch Identity <branch@identi.ty>')
59
self.assertWhoAmI('branch@identi.ty', '--email')
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)
61
55
# Verify that the environment variable overrides the value
63
57
self.overrideEnv('BZR_EMAIL', 'Different ID <other@environ.ment>')
64
self.assertWhoAmI('Different ID <other@environ.ment>')
65
self.assertWhoAmI('other@environ.ment', '--email')
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)
67
63
def test_whoami_utf8(self):
68
64
"""verify that an identity can be in utf-8."""
65
wt = self.make_branch_and_tree('.')
69
66
self.run_bzr(['whoami', u'Branch Identity \u20ac <branch@identi.ty>'],
71
self.assertWhoAmI('Branch Identity \xe2\x82\xac <branch@identi.ty>',
73
self.assertWhoAmI('branch@identi.ty', '--email')
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)
75
74
def test_whoami_ascii(self):
81
80
b = bzrlib.branch.Branch.open('.')
82
81
b.get_config().set_user_option('email', u'Branch Identity \u20ac ' +
83
82
'<branch@identi.ty>')
84
self.assertWhoAmI('Branch Identity ? <branch@identi.ty>',
86
self.assertWhoAmI('branch@identi.ty', '--email',
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)
89
88
def test_warning(self):
90
89
"""verify that a warning is displayed if no email is given."""
110
109
wt = self.make_branch_and_tree('subdir')
111
110
c = wt.branch.get_config()
112
111
c.set_user_option('email', 'Branch Identity <branch@identi.ty>')
113
self.assertWhoAmI('Branch Identity <branch@identi.ty>',
114
'--directory', 'subdir')
112
out, err = self.run_bzr("whoami --directory subdir")
113
self.assertEquals('Branch Identity <branch@identi.ty>\n', out)
115
114
self.run_bzr(['whoami', '--directory', 'subdir', '--branch',
116
115
'Changed Identity <changed@identi.ty>'])
117
c = wt.branch.get_config()
118
116
self.assertEquals('Changed Identity <changed@identi.ty>',
119
117
c.get_user_option('email'))
124
122
c = wt.branch.get_config()
125
123
c.set_user_option('email', 'Branch Identity <branch@identi.ty>')
126
124
url = self.get_readonly_url() + '/subdir'
127
self.assertWhoAmI('Branch Identity <branch@identi.ty>',
125
out, err = self.run_bzr(['whoami', '--directory', url])
126
self.assertEquals('Branch Identity <branch@identi.ty>\n', out)
129
127
url = self.get_url('subdir')
130
128
self.run_bzr(['whoami', '--directory', url, '--branch',
131
129
'Changed Identity <changed@identi.ty>'])
132
130
# The identity has been set in the branch config (but not the global
134
c = wt.branch.get_config()
135
132
self.assertEquals('Changed Identity <changed@identi.ty>',
136
133
c.get_user_option('email'))
137
134
global_conf = config.GlobalConfig()