~bzr-pqm/bzr/bzr.dev

2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 Canonical Ltd
1816.2.10 by Robey Pointer
code style changes
2
#
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1816.2.10 by Robey Pointer
code style changes
7
#
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1816.2.10 by Robey Pointer
code style changes
12
#
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
1816.2.10 by Robey Pointer
code style changes
18
"""Black-box tests for bzr whoami."""
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
19
20
import os
21
22
import bzrlib
23
from bzrlib.branch import Branch
24
from bzrlib.tests.blackbox import ExternalBase
25
26
27
class TestWhoami(ExternalBase):
28
29
    def test_whoami(self):
30
        # this should always identify something, if only "john@localhost"
1816.2.5 by Robey Pointer
clean up whoami tests a bit
31
        out = self.run_bzr("whoami")[0]
32
        self.assertTrue(len(out) > 0)
1816.2.10 by Robey Pointer
code style changes
33
        self.assertEquals(1, out.count('@'))
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
34
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
35
        out = self.run_bzr("whoami --email")[0]
1816.2.5 by Robey Pointer
clean up whoami tests a bit
36
        self.assertTrue(len(out) > 0)
1816.2.10 by Robey Pointer
code style changes
37
        self.assertEquals(1, out.count('@'))
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
38
        
39
    def test_whoami_branch(self):
40
        """branch specific user identity works."""
1816.2.10 by Robey Pointer
code style changes
41
        wt = self.make_branch_and_tree('.')
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
42
        b = bzrlib.branch.Branch.open('.')
1840.1.3 by Robey Pointer
fix some 80col wrapping and add a blackbox test to verify that a warning is displayed when a non-email identity is set
43
        b.get_config().set_user_option('email',
44
                                       'Branch Identity <branch@identi.ty>')
1861.4.1 by Matthieu Moy
BZREMAIL renamed to BZR_EMAIL.
45
        bzr_email = os.environ.get('BZR_EMAIL')
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
46
        if bzr_email is not None:
1861.4.1 by Matthieu Moy
BZREMAIL renamed to BZR_EMAIL.
47
            del os.environ['BZR_EMAIL']
1816.2.5 by Robey Pointer
clean up whoami tests a bit
48
        try:
49
            whoami = self.run_bzr("whoami")[0]
1816.2.10 by Robey Pointer
code style changes
50
            self.assertEquals('Branch Identity <branch@identi.ty>\n', whoami)
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
51
            whoami_email = self.run_bzr("whoami --email")[0]
1816.2.10 by Robey Pointer
code style changes
52
            self.assertEquals('branch@identi.ty\n', whoami_email)
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
53
1816.2.5 by Robey Pointer
clean up whoami tests a bit
54
            # Verify that the environment variable overrides the value 
55
            # in the file
1861.4.1 by Matthieu Moy
BZREMAIL renamed to BZR_EMAIL.
56
            os.environ['BZR_EMAIL'] = 'Different ID <other@environ.ment>'
1816.2.5 by Robey Pointer
clean up whoami tests a bit
57
            whoami = self.run_bzr("whoami")[0]
1816.2.10 by Robey Pointer
code style changes
58
            self.assertEquals('Different ID <other@environ.ment>\n', whoami)
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
59
            whoami_email = self.run_bzr("whoami --email")[0]
1816.2.10 by Robey Pointer
code style changes
60
            self.assertEquals('other@environ.ment\n', whoami_email)
1861.4.3 by Matthieu Moy
Better test for BZREMAIL.
61
            del os.environ['BZR_EMAIL']
1816.2.5 by Robey Pointer
clean up whoami tests a bit
62
        finally:
63
            if bzr_email is not None:
1861.4.1 by Matthieu Moy
BZREMAIL renamed to BZR_EMAIL.
64
                os.environ['BZR_EMAIL'] = bzr_email
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
65
66
    def test_whoami_utf8(self):
67
        """verify that an identity can be in utf-8."""
1816.2.10 by Robey Pointer
code style changes
68
        wt = self.make_branch_and_tree('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
69
        self.run_bzr(['whoami', u'Branch Identity \u20ac <branch@identi.ty>'],
1840.1.3 by Robey Pointer
fix some 80col wrapping and add a blackbox test to verify that a warning is displayed when a non-email identity is set
70
                     encoding='utf-8')
1861.4.1 by Matthieu Moy
BZREMAIL renamed to BZR_EMAIL.
71
        bzr_email = os.environ.get('BZR_EMAIL')
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
72
        if bzr_email is not None:
1861.4.1 by Matthieu Moy
BZREMAIL renamed to BZR_EMAIL.
73
            del os.environ['BZR_EMAIL']
1816.2.5 by Robey Pointer
clean up whoami tests a bit
74
        try:
75
            whoami = self.run_bzr("whoami", encoding='utf-8')[0]
1840.1.3 by Robey Pointer
fix some 80col wrapping and add a blackbox test to verify that a warning is displayed when a non-email identity is set
76
            self.assertEquals('Branch Identity \xe2\x82\xac ' +
77
                              '<branch@identi.ty>\n', whoami)
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
78
            whoami_email = self.run_bzr("whoami --email",
1840.1.3 by Robey Pointer
fix some 80col wrapping and add a blackbox test to verify that a warning is displayed when a non-email identity is set
79
                                        encoding='utf-8')[0]
1816.2.10 by Robey Pointer
code style changes
80
            self.assertEquals('branch@identi.ty\n', whoami_email)
1816.2.5 by Robey Pointer
clean up whoami tests a bit
81
        finally:
82
            if bzr_email is not None:
1861.4.1 by Matthieu Moy
BZREMAIL renamed to BZR_EMAIL.
83
                os.environ['BZR_EMAIL'] = bzr_email
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
84
85
    def test_whoami_ascii(self):
1840.1.3 by Robey Pointer
fix some 80col wrapping and add a blackbox test to verify that a warning is displayed when a non-email identity is set
86
        """
87
        verify that whoami doesn't totally break when in utf-8, using an ascii
88
        encoding.
89
        """
1816.2.10 by Robey Pointer
code style changes
90
        wt = self.make_branch_and_tree('.')
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
91
        b = bzrlib.branch.Branch.open('.')
1840.1.3 by Robey Pointer
fix some 80col wrapping and add a blackbox test to verify that a warning is displayed when a non-email identity is set
92
        b.get_config().set_user_option('email', u'Branch Identity \u20ac ' +
93
                                       '<branch@identi.ty>')
1861.4.1 by Matthieu Moy
BZREMAIL renamed to BZR_EMAIL.
94
        bzr_email = os.environ.get('BZR_EMAIL')
1816.2.3 by Robey Pointer
move the whoami blackbox tests into their own file and add more tests
95
        if bzr_email is not None:
1861.4.1 by Matthieu Moy
BZREMAIL renamed to BZR_EMAIL.
96
            del os.environ['BZR_EMAIL']
1816.2.5 by Robey Pointer
clean up whoami tests a bit
97
        try:
98
            whoami = self.run_bzr("whoami", encoding='ascii')[0]
1816.2.10 by Robey Pointer
code style changes
99
            self.assertEquals('Branch Identity ? <branch@identi.ty>\n', whoami)
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
100
            whoami_email = self.run_bzr("whoami --email",
1840.1.3 by Robey Pointer
fix some 80col wrapping and add a blackbox test to verify that a warning is displayed when a non-email identity is set
101
                                        encoding='ascii')[0]
1816.2.10 by Robey Pointer
code style changes
102
            self.assertEquals('branch@identi.ty\n', whoami_email)
1816.2.5 by Robey Pointer
clean up whoami tests a bit
103
        finally:
104
            if bzr_email is not None:
1861.4.1 by Matthieu Moy
BZREMAIL renamed to BZR_EMAIL.
105
                os.environ['BZR_EMAIL'] = bzr_email
1840.1.3 by Robey Pointer
fix some 80col wrapping and add a blackbox test to verify that a warning is displayed when a non-email identity is set
106
107
    def test_warning(self):
108
        """verify that a warning is displayed if no email is given."""
109
        self.make_branch_and_tree('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
110
        display = self.run_bzr(['whoami', 'Branch Identity'])[1]
1840.1.5 by Robey Pointer
change the warning message for a 'whoami' with no email address, on jam's recommendation
111
        self.assertEquals('"Branch Identity" does not seem to contain an '
112
                          'email address.  This is allowed, but not '
113
                          'recommended.\n', display)