32
32
self.assertTrue(len(out) > 0)
33
33
self.assertEquals(1, out.count('@'))
35
out = self.run_bzr("whoami --email")[0]
35
out = self.run_bzr("whoami", "--email")[0]
36
36
self.assertTrue(len(out) > 0)
37
37
self.assertEquals(1, out.count('@'))
39
39
def test_whoami_branch(self):
40
40
"""branch specific user identity works."""
41
41
wt = self.make_branch_and_tree('.')
42
42
b = bzrlib.branch.Branch.open('.')
43
b.get_config().set_user_option('email',
44
'Branch Identity <branch@identi.ty>')
45
bzr_email = os.environ.get('BZR_EMAIL')
43
b.get_config().set_user_option('email', 'Branch Identity <branch@identi.ty>')
44
bzr_email = os.environ.get('BZREMAIL')
46
45
if bzr_email is not None:
47
del os.environ['BZR_EMAIL']
46
del os.environ['BZREMAIL']
49
48
whoami = self.run_bzr("whoami")[0]
50
49
self.assertEquals('Branch Identity <branch@identi.ty>\n', whoami)
51
whoami_email = self.run_bzr("whoami --email")[0]
50
whoami_email = self.run_bzr("whoami", "--email")[0]
52
51
self.assertEquals('branch@identi.ty\n', whoami_email)
54
# Verify that the environment variable overrides the value
53
# Verify that the environment variable overrides the value
56
os.environ['BZR_EMAIL'] = 'Different ID <other@environ.ment>'
55
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
57
56
whoami = self.run_bzr("whoami")[0]
58
57
self.assertEquals('Different ID <other@environ.ment>\n', whoami)
59
whoami_email = self.run_bzr("whoami --email")[0]
58
whoami_email = self.run_bzr("whoami", "--email")[0]
60
59
self.assertEquals('other@environ.ment\n', whoami_email)
61
del os.environ['BZR_EMAIL']
63
61
if bzr_email is not None:
64
os.environ['BZR_EMAIL'] = bzr_email
62
os.environ['BZREMAIL'] = bzr_email
66
64
def test_whoami_utf8(self):
67
65
"""verify that an identity can be in utf-8."""
68
66
wt = self.make_branch_and_tree('.')
69
self.run_bzr(['whoami', u'Branch Identity \u20ac <branch@identi.ty>'],
71
bzr_email = os.environ.get('BZR_EMAIL')
67
self.run_bzr('whoami', u'Branch Identity \u20ac <branch@identi.ty>', encoding='utf-8')
68
bzr_email = os.environ.get('BZREMAIL')
72
69
if bzr_email is not None:
73
del os.environ['BZR_EMAIL']
70
del os.environ['BZREMAIL']
75
72
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",
73
self.assertEquals('Branch Identity \xe2\x82\xac <branch@identi.ty>\n', whoami)
74
whoami_email = self.run_bzr("whoami", "--email", encoding='utf-8')[0]
80
75
self.assertEquals('branch@identi.ty\n', whoami_email)
82
77
if bzr_email is not None:
83
os.environ['BZR_EMAIL'] = bzr_email
78
os.environ['BZREMAIL'] = bzr_email
85
80
def test_whoami_ascii(self):
87
verify that whoami doesn't totally break when in utf-8, using an ascii
81
"""verify that whoami doesn't totally break when in utf-8, using an ascii encoding."""
90
82
wt = self.make_branch_and_tree('.')
91
83
b = bzrlib.branch.Branch.open('.')
92
b.get_config().set_user_option('email', u'Branch Identity \u20ac ' +
94
bzr_email = os.environ.get('BZR_EMAIL')
84
b.get_config().set_user_option('email', u'Branch Identity \u20ac <branch@identi.ty>')
85
bzr_email = os.environ.get('BZREMAIL')
95
86
if bzr_email is not None:
96
del os.environ['BZR_EMAIL']
87
del os.environ['BZREMAIL']
98
89
whoami = self.run_bzr("whoami", encoding='ascii')[0]
99
90
self.assertEquals('Branch Identity ? <branch@identi.ty>\n', whoami)
100
whoami_email = self.run_bzr("whoami --email",
91
whoami_email = self.run_bzr("whoami", "--email", encoding='ascii')[0]
102
92
self.assertEquals('branch@identi.ty\n', whoami_email)
104
94
if bzr_email is not None:
105
os.environ['BZR_EMAIL'] = bzr_email
107
def test_warning(self):
108
"""verify that a warning is displayed if no email is given."""
109
self.make_branch_and_tree('.')
110
display = self.run_bzr(['whoami', 'Branch Identity'])[1]
111
self.assertEquals('"Branch Identity" does not seem to contain an '
112
'email address. This is allowed, but not '
113
'recommended.\n', display)
95
os.environ['BZREMAIL'] = bzr_email