~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_whoami.py

  • Committer: Robey Pointer
  • Date: 2006-06-29 05:13:26 UTC
  • mto: This revision was merged to the branch mainline in revision 1839.
  • Revision ID: robey@lag.net-20060629051326-55354a4283dc69da
move the whoami blackbox tests into their own file and add more tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 by Canonical Ltd
 
2
# -*- coding: utf-8 -*-
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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
 
17
 
 
18
 
 
19
"""Black-box tests for bzr whoami.
 
20
"""
 
21
 
 
22
import os
 
23
 
 
24
import bzrlib
 
25
from bzrlib.branch import Branch
 
26
from bzrlib.tests.blackbox import ExternalBase
 
27
 
 
28
 
 
29
class TestWhoami(ExternalBase):
 
30
 
 
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")
 
35
 
 
36
        self.assertEquals(self.run_bzr("whoami", "--email")[0].count('@'), 1)
 
37
        
 
38
    def test_whoami_branch(self):
 
39
        """branch specific user identity works."""
 
40
        self.run_bzr('init')
 
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'))
 
50
 
 
51
        # Verify that the environment variable overrides the value 
 
52
        # in the file
 
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
 
60
 
 
61
    def test_whoami_utf8(self):
 
62
        """verify that an identity can be in utf-8."""
 
63
        self.run_bzr('init')
 
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'))
 
72
 
 
73
    def test_whoami_ascii(self):
 
74
        """verify that whoami doesn't totally break when in utf-8."""
 
75
        self.runbzr('init')
 
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'))