/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Robey Pointer
  • Date: 2006-06-29 23:25:58 UTC
  • mto: This revision was merged to the branch mainline in revision 1839.
  • Revision ID: robey@lag.net-20060629232558-a7b7c4da6c455841
add whoami info to NEWS

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
        out = self.run_bzr("whoami")[0]
 
34
        self.assertTrue(len(out) > 0)
 
35
        self.assertEquals(out.count('@'), 1)
 
36
 
 
37
        out = self.run_bzr("whoami", "--email")[0]
 
38
        self.assertTrue(len(out) > 0)
 
39
        self.assertEquals(out.count('@'), 1)
 
40
        
 
41
    def test_whoami_branch(self):
 
42
        """branch specific user identity works."""
 
43
        self.run_bzr('init')
 
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']
 
49
        try:
 
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'))
 
54
 
 
55
            # Verify that the environment variable overrides the value 
 
56
            # in the file
 
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'))
 
62
        finally:
 
63
            if bzr_email is not None:
 
64
                os.environ['BZREMAIL'] = bzr_email
 
65
 
 
66
    def test_whoami_utf8(self):
 
67
        """verify that an identity can be in utf-8."""
 
68
        self.run_bzr('init')
 
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']
 
73
        try:
 
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'))
 
78
        finally:
 
79
            if bzr_email is not None:
 
80
                os.environ['BZREMAIL'] = bzr_email
 
81
 
 
82
    def test_whoami_ascii(self):
 
83
        """verify that whoami doesn't totally break when in utf-8, using an ascii encoding."""
 
84
        self.runbzr('init')
 
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']
 
90
        try:
 
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'))
 
95
        finally:
 
96
            if bzr_email is not None:
 
97
                os.environ['BZREMAIL'] = bzr_email