1
# Copyright (C) 2005 by Canonical Ltd
2
# -*- coding: utf-8 -*-
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
"""Black-box tests for bzr whoami.
25
from bzrlib.branch import Branch
26
from bzrlib.tests.blackbox import ExternalBase
29
class TestWhoami(ExternalBase):
31
def test_whoami(self):
32
# this should always identify something, if only "john@localhost"
33
self.run_bzr("whoami")
34
self.run_bzr("whoami", "--email")
36
self.assertEquals(self.run_bzr("whoami", "--email")[0].count('@'), 1)
38
def test_whoami_branch(self):
39
"""branch specific user identity works."""
41
b = bzrlib.branch.Branch.open('.')
42
b.get_config().set_user_option('email', 'Branch Identity <branch@identi.ty>')
43
bzr_email = os.environ.get('BZREMAIL')
44
if bzr_email is not None:
45
del os.environ['BZREMAIL']
46
whoami = self.run_bzr("whoami")[0]
47
whoami_email = self.run_bzr("whoami", "--email")[0]
48
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
49
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
51
# Verify that the environment variable overrides the value
53
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
54
whoami = self.run_bzr("whoami")[0]
55
whoami_email = self.run_bzr("whoami", "--email")[0]
56
self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
57
self.assertTrue(whoami_email.startswith('other@environ.ment'))
58
if bzr_email is not None:
59
os.environ['BZREMAIL'] = bzr_email
61
def test_whoami_utf8(self):
62
"""verify that an identity can be in utf-8."""
64
self.run_bzr('whoami', u'Branch Identity \u20ac <branch@identi.ty>'.encode('utf-8'), encoding='utf-8')
65
bzr_email = os.environ.get('BZREMAIL')
66
if bzr_email is not None:
67
del os.environ['BZREMAIL']
68
whoami = self.run_bzr("whoami", encoding='utf-8')[0]
69
whoami_email = self.run_bzr("whoami", "--email", encoding='utf-8')[0]
70
self.assertTrue(whoami.startswith('Branch Identity \xe2\x82\xac <branch@identi.ty>'))
71
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
73
def test_whoami_ascii(self):
74
"""verify that whoami doesn't totally break when in utf-8."""
76
b = bzrlib.branch.Branch.open('.')
77
b.get_config().set_user_option('email', u'Branch Identity \u20ac <branch@identi.ty>')
78
bzr_email = os.environ.get('BZREMAIL')
79
if bzr_email is not None:
80
del os.environ['BZREMAIL']
81
whoami = self.run_bzr("whoami", encoding='ascii')[0]
82
whoami_email = self.run_bzr("whoami", "--email", encoding='ascii')[0]
83
self.assertTrue(whoami.startswith('Branch Identity ? <branch@identi.ty>'))
84
self.assertTrue(whoami_email.startswith('branch@identi.ty'))