/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/transport/fakenfs.py

Better (but still incomplete) design for bogus servers.

* bzrlib/transport/http/_urllib2_wrappers.py:
(AbstractHTTPHandler): Add 'Accept: */*' again to default headers
until I fully understand why and when it's needed or not (curl add
it if no Accept header is present).

* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport._curl_perform): CURLE_GOT_NOTHING may be
considered as a ConnectionError, inspection of curl code reveals
that the case is sufficiently rare and low level related to not be
considered an http error per se.

* bzrlib/transport/http/__init__.py:
(WallHttpServer): Deleted.

* bzrlib/tests/test_http.py:
(TestBogusServer): Factor out the tests common to the bogus
servers.

* bzrlib/tests/__init__.py:
(TestCaseWithTransport.create_transport_server,
TestCaseWithTransport.create_transport_readonly_server): New
methods, allows test cases to specify the transport servers
without defining useless classes.
(TestCaseWithTransport.get_readonly_server): Use
create_transport_readonly_server.
(TestCaseWithTransport.get_server): Use create_transport_server.

* bzrlib/tests/HTTPTestUtil.py:
(TestCaseWithWebserver): Fix typo in doc string.
(TestCaseWithWallserver): Deleted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006 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
"""Transport implementation that adapts another transport to look like NFS.
 
18
 
 
19
Currently this means that the rename() call will raise ResourceBusy when a
 
20
target path is a directory.
 
21
 
 
22
To get a fake nfs transport use get_transport('fakenfs+' + real_url)
 
23
"""
 
24
 
 
25
from stat import S_ISDIR
 
26
 
 
27
import bzrlib.errors as errors
 
28
from bzrlib.transport.decorator import TransportDecorator, DecoratorServer
 
29
 
 
30
 
 
31
class FakeNFSTransportDecorator(TransportDecorator):
 
32
    """A transport that behaves like NFS, for testing"""
 
33
 
 
34
    @classmethod
 
35
    def _get_url_prefix(self):
 
36
        """FakeNFS transports are identified by 'fakenfs+'"""
 
37
        return 'fakenfs+'
 
38
 
 
39
    def rename(self, rel_from, rel_to):
 
40
        """See Transport.rename().
 
41
 
 
42
        This variation on rename converts DirectoryNotEmpty and FileExists
 
43
        errors into ResourceBusy if the target is a directory.
 
44
        """
 
45
        try:
 
46
            self._decorated.rename(rel_from, rel_to)
 
47
        except (errors.DirectoryNotEmpty, errors.FileExists), e:
 
48
            # if this is a directory rename, raise
 
49
            # resourcebusy rather than DirectoryNotEmpty
 
50
            stat = self._decorated.stat(rel_to)
 
51
            if S_ISDIR(stat.st_mode):
 
52
                raise errors.ResourceBusy(rel_to)
 
53
            else:
 
54
                raise
 
55
 
 
56
 
 
57
class FakeNFSServer(DecoratorServer):
 
58
    """Server for the FakeNFSTransportDecorator for testing with."""
 
59
 
 
60
    def get_decorator_class(self):
 
61
        return FakeNFSTransportDecorator
 
62
 
 
63
 
 
64
def get_test_permutations():
 
65
    """Return the permutations to be used in testing."""
 
66
    return [(FakeNFSTransportDecorator, FakeNFSServer),
 
67
            ]