103
def SmartTCPServer_for_testing():
104
"""Get a readwrite server for testing."""
105
return ReadWriteLocalSmartTCPServer(
106
transport.get_transport(urlutils.local_path_to_url('/')))
109
def ReadonlySmartTCPServer_for_testing():
110
"""Get a readonly server for testing."""
111
return ReadWriteLocalSmartTCPServer(
112
transport.get_transport('readonly+' + urlutils.local_path_to_url('/')))
115
class ReadWriteLocalSmartTCPServer(SmartTCPServer):
103
class SmartTCPServer_for_testing(SmartTCPServer):
116
104
"""Server suitable for use by transport tests.
118
106
This server has a _homedir of the current cwd.
121
def __init__(self, transport):
122
self._homedir = urlutils.local_path_to_url(os.getcwd())[7:]
123
# The server is set up by default like for ssh access: the client
124
# passes filesystem-absolute paths; therefore the server must look
125
# them up relative to the root directory. it might be better to act
126
# a public server and have the server rewrite paths into the test
128
SmartTCPServer.__init__(self, transport)
110
# The server is set up by default like for inetd access: the backing
111
# transport is connected to a local path that is not '/'.
112
SmartTCPServer.__init__(self, None)
114
def get_backing_transport(self, backing_transport_server):
115
"""Get a backing transport from a server we are decorating."""
116
return transport.get_transport('chroot+' + backing_transport_server.get_url())
118
def setUp(self, backing_transport_server):
131
119
"""Set up server for testing"""
120
self.backing_transport = self.get_backing_transport(backing_transport_server)
132
121
self.start_background_thread()
134
123
def tearDown(self):
137
126
def get_url(self):
138
127
"""Return the url of the server"""
139
128
host, port = self._server_socket.getsockname()
140
return "bzr://%s:%d%s" % (host, port, urlutils.escape(self._homedir))
129
return "bzr://%s:%d/" % (host, port)
142
131
def get_bogus_url(self):
143
132
"""Return a URL which will fail to connect"""
144
133
return 'bzr://127.0.0.1:1/'
136
class ReadonlySmartTCPServer_for_testing(SmartTCPServer_for_testing):
137
"""Get a readonly server for testing."""
139
def get_backing_transport(self, backing_transport_server):
140
"""Get a backing transport from a server we are decorating."""
141
url = 'chroot+readonly+' + backing_transport_server.get_url()
142
return transport.get_transport(url)