42
45
b = bzrlib.branch.Branch.open('.')
43
46
b.get_config().set_user_option('email',
44
47
'Branch Identity <branch@identi.ty>')
45
bzr_email = os.environ.get('BZR_EMAIL')
46
if bzr_email is not None:
47
del os.environ['BZR_EMAIL']
49
whoami = self.run_bzr("whoami")[0]
50
self.assertEquals('Branch Identity <branch@identi.ty>\n', whoami)
51
whoami_email = self.run_bzr("whoami --email")[0]
52
self.assertEquals('branch@identi.ty\n', whoami_email)
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)
54
# Verify that the environment variable overrides the value
56
os.environ['BZR_EMAIL'] = 'Different ID <other@environ.ment>'
57
whoami = self.run_bzr("whoami")[0]
58
self.assertEquals('Different ID <other@environ.ment>\n', whoami)
59
whoami_email = self.run_bzr("whoami --email")[0]
60
self.assertEquals('other@environ.ment\n', whoami_email)
61
del os.environ['BZR_EMAIL']
63
if bzr_email is not None:
64
os.environ['BZR_EMAIL'] = bzr_email
53
# Verify that the environment variable overrides the value
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)
66
61
def test_whoami_utf8(self):
67
62
"""verify that an identity can be in utf-8."""
68
63
wt = self.make_branch_and_tree('.')
69
64
self.run_bzr(['whoami', u'Branch Identity \u20ac <branch@identi.ty>'],
71
bzr_email = os.environ.get('BZR_EMAIL')
72
if bzr_email is not None:
73
del os.environ['BZR_EMAIL']
75
whoami = self.run_bzr("whoami", encoding='utf-8')[0]
76
self.assertEquals('Branch Identity \xe2\x82\xac ' +
77
'<branch@identi.ty>\n', whoami)
78
whoami_email = self.run_bzr("whoami --email",
80
self.assertEquals('branch@identi.ty\n', whoami_email)
82
if bzr_email is not None:
83
os.environ['BZR_EMAIL'] = bzr_email
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)
85
72
def test_whoami_ascii(self):
91
78
b = bzrlib.branch.Branch.open('.')
92
79
b.get_config().set_user_option('email', u'Branch Identity \u20ac ' +
93
80
'<branch@identi.ty>')
94
bzr_email = os.environ.get('BZR_EMAIL')
95
if bzr_email is not None:
96
del os.environ['BZR_EMAIL']
98
whoami = self.run_bzr("whoami", encoding='ascii')[0]
99
self.assertEquals('Branch Identity ? <branch@identi.ty>\n', whoami)
100
whoami_email = self.run_bzr("whoami --email",
102
self.assertEquals('branch@identi.ty\n', whoami_email)
104
if bzr_email is not None:
105
os.environ['BZR_EMAIL'] = bzr_email
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)
107
86
def test_warning(self):
108
87
"""verify that a warning is displayed if no email is given."""
111
90
self.assertEquals('"Branch Identity" does not seem to contain an '
112
91
'email address. This is allowed, but not '
113
92
'recommended.\n', display)
94
def test_whoami_not_set(self):
95
"""Ensure whoami error if username is not set.
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')
102
def test_whoami_directory(self):
103
"""Test --directory option."""
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>')
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'))
114
def test_whoami_remote_directory(self):
115
"""Test --directory option with a remote directory."""
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>')
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>'])
125
# The identity has been set in the branch config (but not the global
127
self.assertEquals('Changed Identity <changed@identi.ty>',
128
c.get_user_option('email'))
129
global_conf = config.GlobalConfig()
130
self.assertEquals(None, global_conf.get_user_option('email'))
132
def test_whoami_nonbranch_directory(self):
133
"""Test --directory mentioning a non-branch directory."""
134
wt = self.build_tree(['subdir/'])
135
out, err = self.run_bzr("whoami --directory subdir", retcode=3)
136
self.assertContainsRe(err, 'ERROR: Not a branch')