1816.2.10
by Robey Pointer
code style changes |
1 |
# Copyright (C) 2006 by Canonical Ltd
|
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 |
|
1816.2.5
by Robey Pointer
clean up whoami tests a bit |
35 |
out = self.run_bzr("whoami", "--email")[0] |
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('.') |
43 |
b.get_config().set_user_option('email', 'Branch Identity <branch@identi.ty>') |
|
44 |
bzr_email = os.environ.get('BZREMAIL') |
|
45 |
if bzr_email is not None: |
|
46 |
del os.environ['BZREMAIL'] |
|
1816.2.5
by Robey Pointer
clean up whoami tests a bit |
47 |
try: |
48 |
whoami = self.run_bzr("whoami")[0] |
|
1816.2.10
by Robey Pointer
code style changes |
49 |
self.assertEquals('Branch Identity <branch@identi.ty>\n', whoami) |
1816.2.5
by Robey Pointer
clean up whoami tests a bit |
50 |
whoami_email = self.run_bzr("whoami", "--email")[0] |
1816.2.10
by Robey Pointer
code style changes |
51 |
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 |
52 |
|
1816.2.5
by Robey Pointer
clean up whoami tests a bit |
53 |
# Verify that the environment variable overrides the value
|
54 |
# in the file
|
|
55 |
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>' |
|
56 |
whoami = self.run_bzr("whoami")[0] |
|
1816.2.10
by Robey Pointer
code style changes |
57 |
self.assertEquals('Different ID <other@environ.ment>\n', whoami) |
1816.2.5
by Robey Pointer
clean up whoami tests a bit |
58 |
whoami_email = self.run_bzr("whoami", "--email")[0] |
1816.2.10
by Robey Pointer
code style changes |
59 |
self.assertEquals('other@environ.ment\n', whoami_email) |
1816.2.5
by Robey Pointer
clean up whoami tests a bit |
60 |
finally: |
61 |
if bzr_email is not None: |
|
62 |
os.environ['BZREMAIL'] = bzr_email |
|
1816.2.3
by Robey Pointer
move the whoami blackbox tests into their own file and add more tests |
63 |
|
64 |
def test_whoami_utf8(self): |
|
65 |
"""verify that an identity can be in utf-8."""
|
|
1816.2.10
by Robey Pointer
code style changes |
66 |
wt = self.make_branch_and_tree('.') |
1816.2.5
by Robey Pointer
clean up whoami tests a bit |
67 |
self.run_bzr('whoami', u'Branch Identity \u20ac <branch@identi.ty>', encoding='utf-8') |
1816.2.3
by Robey Pointer
move the whoami blackbox tests into their own file and add more tests |
68 |
bzr_email = os.environ.get('BZREMAIL') |
69 |
if bzr_email is not None: |
|
70 |
del os.environ['BZREMAIL'] |
|
1816.2.5
by Robey Pointer
clean up whoami tests a bit |
71 |
try: |
72 |
whoami = self.run_bzr("whoami", encoding='utf-8')[0] |
|
1816.2.10
by Robey Pointer
code style changes |
73 |
self.assertEquals('Branch Identity \xe2\x82\xac <branch@identi.ty>\n', whoami) |
1816.2.5
by Robey Pointer
clean up whoami tests a bit |
74 |
whoami_email = self.run_bzr("whoami", "--email", encoding='utf-8')[0] |
1816.2.10
by Robey Pointer
code style changes |
75 |
self.assertEquals('branch@identi.ty\n', whoami_email) |
1816.2.5
by Robey Pointer
clean up whoami tests a bit |
76 |
finally: |
77 |
if bzr_email is not None: |
|
78 |
os.environ['BZREMAIL'] = bzr_email |
|
1816.2.3
by Robey Pointer
move the whoami blackbox tests into their own file and add more tests |
79 |
|
80 |
def test_whoami_ascii(self): |
|
1816.2.5
by Robey Pointer
clean up whoami tests a bit |
81 |
"""verify that whoami doesn't totally break when in utf-8, using an ascii encoding."""
|
1816.2.10
by Robey Pointer
code style changes |
82 |
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 |
83 |
b = bzrlib.branch.Branch.open('.') |
84 |
b.get_config().set_user_option('email', u'Branch Identity \u20ac <branch@identi.ty>') |
|
85 |
bzr_email = os.environ.get('BZREMAIL') |
|
86 |
if bzr_email is not None: |
|
1816.2.5
by Robey Pointer
clean up whoami tests a bit |
87 |
del os.environ['BZREMAIL'] |
88 |
try: |
|
89 |
whoami = self.run_bzr("whoami", encoding='ascii')[0] |
|
1816.2.10
by Robey Pointer
code style changes |
90 |
self.assertEquals('Branch Identity ? <branch@identi.ty>\n', whoami) |
1816.2.5
by Robey Pointer
clean up whoami tests a bit |
91 |
whoami_email = self.run_bzr("whoami", "--email", encoding='ascii')[0] |
1816.2.10
by Robey Pointer
code style changes |
92 |
self.assertEquals('branch@identi.ty\n', whoami_email) |
1816.2.5
by Robey Pointer
clean up whoami tests a bit |
93 |
finally: |
94 |
if bzr_email is not None: |
|
95 |
os.environ['BZREMAIL'] = bzr_email |