/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: v.ladeuil+lp at free
  • Date: 2006-10-12 14:29:32 UTC
  • mto: (2145.1.1 keepalive)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: v.ladeuil+lp@free.fr-20061012142932-7221fe16d2b48fa3
Shuffle http related test code. Hopefully it ends up at the right place :)

* bzrlib/tests/HttpServer.py: 
New file. bzrlib.tests.ChrootedTestCase use HttpServer. So the
class can't be defined in bzrlib.tests.HTTPUtils because it
creates a circular dependency (bzrlib.tests.HTTPUtils needs to
import bzrlib.tests).

* bzrlib/transport/http/_urllib.py: 
Transfer test server definition to bzrlib.tests.HttpServer. Clean
up imports.

* bzrlib/transport/http/_pycurl.py: 
Transfer test server definition to bzrlib.tests.HttpServer. Clean
up imports.

* bzrlib/transport/http/__init__.py: 
Transfer all test related code to either bzrlib.tests.HttpServer
and bzrlib.tests.HTTPUtils.
Fix all use of TransportNotPossible and InvalidURL by prefixing it
by 'errors.' (this seems to be the preferred way in the rest of
bzr).
Get rid of unused imports.

* bzrlib/tests/test_transport.py:
(ReadonlyDecoratorTransportTest.test_local_parameters,
FakeNFSDecoratorTests.test_http_parameters): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

* bzrlib/tests/test_sftp_transport.py:
(set_test_transport_to_sftp): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

* bzrlib/tests/test_selftest.py:
(TestTestCaseWithTransport.test_get_readonly_url_http): Use
HttpServer from bzrlib.tests.HttpServer instead of
bzrlib.transport.http.

* bzrlib/tests/test_repository.py: 
Does *not* use HttpServer.

* bzrlib/tests/test_http.py: 
Build on top of bzrlib.tests.HttpServer and bzrlib.tests.HTTPUtils
instead of bzrlib.transport.http.

* bzrlib/tests/test_bzrdir.py:
(ChrootedTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/branch_implementations/test_http.py:
(HTTPBranchTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/branch_implementations/test_branch.py:
(ChrootedTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/__init__.py:
(ChrootedTestCase.setUp): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
 
18
"""Black-box tests for bzr whoami."""
 
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"
 
31
        out = self.run_bzr("whoami")[0]
 
32
        self.assertTrue(len(out) > 0)
 
33
        self.assertEquals(1, out.count('@'))
 
34
 
 
35
        out = self.run_bzr("whoami", "--email")[0]
 
36
        self.assertTrue(len(out) > 0)
 
37
        self.assertEquals(1, out.count('@'))
 
38
        
 
39
    def test_whoami_branch(self):
 
40
        """branch specific user identity works."""
 
41
        wt = self.make_branch_and_tree('.')
 
42
        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')
 
46
        if bzr_email is not None:
 
47
            del os.environ['BZR_EMAIL']
 
48
        bzremail = os.environ.get('BZREMAIL')
 
49
        if bzremail is not None:
 
50
            del os.environ['BZREMAIL']
 
51
        try:
 
52
            whoami = self.run_bzr("whoami")[0]
 
53
            self.assertEquals('Branch Identity <branch@identi.ty>\n', whoami)
 
54
            whoami_email = self.run_bzr("whoami", "--email")[0]
 
55
            self.assertEquals('branch@identi.ty\n', whoami_email)
 
56
 
 
57
            # Verify that the environment variable overrides the value 
 
58
            # in the file
 
59
            os.environ['BZR_EMAIL'] = 'Different ID <other@environ.ment>'
 
60
            whoami = self.run_bzr("whoami")[0]
 
61
            self.assertEquals('Different ID <other@environ.ment>\n', whoami)
 
62
            whoami_email = self.run_bzr("whoami", "--email")[0]
 
63
            self.assertEquals('other@environ.ment\n', whoami_email)
 
64
            del os.environ['BZR_EMAIL']
 
65
            os.environ['BZREMAIL'] = 'Yet Another ID <yetother@environ.ment>'
 
66
            whoami, warn = self.run_bzr("whoami")
 
67
            self.assertEquals('Yet Another ID <yetother@environ.ment>\n', whoami)
 
68
            self.assertTrue(len(warn) > 0)
 
69
            del os.environ['BZREMAIL']
 
70
        finally:
 
71
            if bzr_email is not None:
 
72
                os.environ['BZR_EMAIL'] = bzr_email
 
73
            if bzremail is not None:
 
74
                os.environ['BZREMAIL'] = bzremail
 
75
 
 
76
    def test_whoami_utf8(self):
 
77
        """verify that an identity can be in utf-8."""
 
78
        wt = self.make_branch_and_tree('.')
 
79
        self.run_bzr('whoami', u'Branch Identity \u20ac <branch@identi.ty>',
 
80
                     encoding='utf-8')
 
81
        bzr_email = os.environ.get('BZR_EMAIL')
 
82
        if bzr_email is not None:
 
83
            del os.environ['BZR_EMAIL']
 
84
        try:
 
85
            whoami = self.run_bzr("whoami", encoding='utf-8')[0]
 
86
            self.assertEquals('Branch Identity \xe2\x82\xac ' +
 
87
                              '<branch@identi.ty>\n', whoami)
 
88
            whoami_email = self.run_bzr("whoami", "--email",
 
89
                                        encoding='utf-8')[0]
 
90
            self.assertEquals('branch@identi.ty\n', whoami_email)
 
91
        finally:
 
92
            if bzr_email is not None:
 
93
                os.environ['BZR_EMAIL'] = bzr_email
 
94
 
 
95
    def test_whoami_ascii(self):
 
96
        """
 
97
        verify that whoami doesn't totally break when in utf-8, using an ascii
 
98
        encoding.
 
99
        """
 
100
        wt = self.make_branch_and_tree('.')
 
101
        b = bzrlib.branch.Branch.open('.')
 
102
        b.get_config().set_user_option('email', u'Branch Identity \u20ac ' +
 
103
                                       '<branch@identi.ty>')
 
104
        bzr_email = os.environ.get('BZR_EMAIL')
 
105
        if bzr_email is not None:
 
106
            del os.environ['BZR_EMAIL']
 
107
        try:
 
108
            whoami = self.run_bzr("whoami", encoding='ascii')[0]
 
109
            self.assertEquals('Branch Identity ? <branch@identi.ty>\n', whoami)
 
110
            whoami_email = self.run_bzr("whoami", "--email",
 
111
                                        encoding='ascii')[0]
 
112
            self.assertEquals('branch@identi.ty\n', whoami_email)
 
113
        finally:
 
114
            if bzr_email is not None:
 
115
                os.environ['BZR_EMAIL'] = bzr_email
 
116
 
 
117
    def test_warning(self):
 
118
        """verify that a warning is displayed if no email is given."""
 
119
        self.make_branch_and_tree('.')
 
120
        display = self.run_bzr('whoami', 'Branch Identity')[1]
 
121
        self.assertEquals('"Branch Identity" does not seem to contain an '
 
122
                          'email address.  This is allowed, but not '
 
123
                          'recommended.\n', display)