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
out = self.run_bzr("whoami")[0]
34
self.assertTrue(len(out) > 0)
35
self.assertEquals(out.count('@'), 1)
37
out = self.run_bzr("whoami", "--email")[0]
38
self.assertTrue(len(out) > 0)
39
self.assertEquals(out.count('@'), 1)
41
def test_whoami_branch(self):
42
"""branch specific user identity works."""
44
b = bzrlib.branch.Branch.open('.')
45
b.get_config().set_user_option('email', 'Branch Identity <branch@identi.ty>')
46
bzr_email = os.environ.get('BZREMAIL')
47
if bzr_email is not None:
48
del os.environ['BZREMAIL']
50
whoami = self.run_bzr("whoami")[0]
51
whoami_email = self.run_bzr("whoami", "--email")[0]
52
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
53
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
55
# Verify that the environment variable overrides the value
57
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
58
whoami = self.run_bzr("whoami")[0]
59
whoami_email = self.run_bzr("whoami", "--email")[0]
60
self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
61
self.assertTrue(whoami_email.startswith('other@environ.ment'))
63
if bzr_email is not None:
64
os.environ['BZREMAIL'] = bzr_email
66
def test_whoami_utf8(self):
67
"""verify that an identity can be in utf-8."""
69
self.run_bzr('whoami', u'Branch Identity \u20ac <branch@identi.ty>', encoding='utf-8')
70
bzr_email = os.environ.get('BZREMAIL')
71
if bzr_email is not None:
72
del os.environ['BZREMAIL']
74
whoami = self.run_bzr("whoami", encoding='utf-8')[0]
75
whoami_email = self.run_bzr("whoami", "--email", encoding='utf-8')[0]
76
self.assertTrue(whoami.startswith('Branch Identity \xe2\x82\xac <branch@identi.ty>'))
77
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
79
if bzr_email is not None:
80
os.environ['BZREMAIL'] = bzr_email
82
def test_whoami_ascii(self):
83
"""verify that whoami doesn't totally break when in utf-8, using an ascii encoding."""
85
b = bzrlib.branch.Branch.open('.')
86
b.get_config().set_user_option('email', u'Branch Identity \u20ac <branch@identi.ty>')
87
bzr_email = os.environ.get('BZREMAIL')
88
if bzr_email is not None:
89
del os.environ['BZREMAIL']
91
whoami = self.run_bzr("whoami", encoding='ascii')[0]
92
whoami_email = self.run_bzr("whoami", "--email", encoding='ascii')[0]
93
self.assertTrue(whoami.startswith('Branch Identity ? <branch@identi.ty>'))
94
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
96
if bzr_email is not None:
97
os.environ['BZREMAIL'] = bzr_email