/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:48 UTC
  • mto: This revision was merged to the branch mainline in revision 1839.
  • Revision ID: robey@lag.net-20060629232548-25aaee5fe809193c
fix typo

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
2
 
#
 
1
# Copyright (C) 2005 by Canonical Ltd
 
2
# -*- coding: utf-8 -*-
 
3
 
3
4
# This program is free software; you can redistribute it and/or modify
4
5
# it under the terms of the GNU General Public License as published by
5
6
# the Free Software Foundation; either version 2 of the License, or
6
7
# (at your option) any later version.
7
 
#
 
8
 
8
9
# This program is distributed in the hope that it will be useful,
9
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
12
# GNU General Public License for more details.
12
 
#
 
13
 
13
14
# You should have received a copy of the GNU General Public License
14
15
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
 
18
 
"""Black-box tests for bzr whoami."""
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 
 
18
 
 
19
"""Black-box tests for bzr whoami.
 
20
"""
19
21
 
20
22
import os
21
23
 
30
32
        # this should always identify something, if only "john@localhost"
31
33
        out = self.run_bzr("whoami")[0]
32
34
        self.assertTrue(len(out) > 0)
33
 
        self.assertEquals(1, out.count('@'))
 
35
        self.assertEquals(out.count('@'), 1)
34
36
 
35
 
        out = self.run_bzr("whoami --email")[0]
 
37
        out = self.run_bzr("whoami", "--email")[0]
36
38
        self.assertTrue(len(out) > 0)
37
 
        self.assertEquals(1, out.count('@'))
38
 
 
 
39
        self.assertEquals(out.count('@'), 1)
 
40
        
39
41
    def test_whoami_branch(self):
40
42
        """branch specific user identity works."""
41
 
        wt = self.make_branch_and_tree('.')
 
43
        self.run_bzr('init')
42
44
        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')
 
45
        b.get_config().set_user_option('email', 'Branch Identity <branch@identi.ty>')
 
46
        bzr_email = os.environ.get('BZREMAIL')
46
47
        if bzr_email is not None:
47
 
            del os.environ['BZR_EMAIL']
 
48
            del os.environ['BZREMAIL']
48
49
        try:
49
50
            whoami = self.run_bzr("whoami")[0]
50
 
            self.assertEquals('Branch Identity <branch@identi.ty>\n', whoami)
51
 
            whoami_email = self.run_bzr("whoami --email")[0]
52
 
            self.assertEquals('branch@identi.ty\n', whoami_email)
 
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'))
53
54
 
54
 
            # Verify that the environment variable overrides the value
 
55
            # Verify that the environment variable overrides the value 
55
56
            # in the file
56
 
            os.environ['BZR_EMAIL'] = 'Different ID <other@environ.ment>'
 
57
            os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
57
58
            whoami = self.run_bzr("whoami")[0]
58
 
            self.assertEquals('Different ID <other@environ.ment>\n', whoami)
59
 
            whoami_email = self.run_bzr("whoami --email")[0]
60
 
            self.assertEquals('other@environ.ment\n', whoami_email)
61
 
            del os.environ['BZR_EMAIL']
 
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
62
        finally:
63
63
            if bzr_email is not None:
64
 
                os.environ['BZR_EMAIL'] = bzr_email
 
64
                os.environ['BZREMAIL'] = bzr_email
65
65
 
66
66
    def test_whoami_utf8(self):
67
67
        """verify that an identity can be in utf-8."""
68
 
        wt = self.make_branch_and_tree('.')
69
 
        self.run_bzr(['whoami', u'Branch Identity \u20ac <branch@identi.ty>'],
70
 
                     encoding='utf-8')
71
 
        bzr_email = os.environ.get('BZR_EMAIL')
 
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')
72
71
        if bzr_email is not None:
73
 
            del os.environ['BZR_EMAIL']
 
72
            del os.environ['BZREMAIL']
74
73
        try:
75
74
            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",
79
 
                                        encoding='utf-8')[0]
80
 
            self.assertEquals('branch@identi.ty\n', whoami_email)
 
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'))
81
78
        finally:
82
79
            if bzr_email is not None:
83
 
                os.environ['BZR_EMAIL'] = bzr_email
 
80
                os.environ['BZREMAIL'] = bzr_email
84
81
 
85
82
    def test_whoami_ascii(self):
86
 
        """
87
 
        verify that whoami doesn't totally break when in utf-8, using an ascii
88
 
        encoding.
89
 
        """
90
 
        wt = self.make_branch_and_tree('.')
 
83
        """verify that whoami doesn't totally break when in utf-8, using an ascii encoding."""
 
84
        self.runbzr('init')
91
85
        b = bzrlib.branch.Branch.open('.')
92
 
        b.get_config().set_user_option('email', u'Branch Identity \u20ac ' +
93
 
                                       '<branch@identi.ty>')
94
 
        bzr_email = os.environ.get('BZR_EMAIL')
 
86
        b.get_config().set_user_option('email', u'Branch Identity \u20ac <branch@identi.ty>')
 
87
        bzr_email = os.environ.get('BZREMAIL')
95
88
        if bzr_email is not None:
96
 
            del os.environ['BZR_EMAIL']
 
89
            del os.environ['BZREMAIL']
97
90
        try:
98
91
            whoami = self.run_bzr("whoami", encoding='ascii')[0]
99
 
            self.assertEquals('Branch Identity ? <branch@identi.ty>\n', whoami)
100
 
            whoami_email = self.run_bzr("whoami --email",
101
 
                                        encoding='ascii')[0]
102
 
            self.assertEquals('branch@identi.ty\n', whoami_email)
 
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'))
103
95
        finally:
104
96
            if bzr_email is not None:
105
 
                os.environ['BZR_EMAIL'] = bzr_email
106
 
 
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)
 
97
                os.environ['BZREMAIL'] = bzr_email