39
from ..bundle import read_mergeable_from_url
40
35
from ..bundle.apply_bundle import install_bundle, merge_bundle
41
36
from ..bundle.bundle_data import BundleTree
42
from ..directory_service import directories
43
37
from ..bundle.serializer import write_bundle, read_bundle, v09, v4
44
38
from ..bundle.serializer.v08 import BundleSerializerV08
45
39
from ..bundle.serializer.v09 import BundleSerializerV09
1847
1839
'info', None, None), record)
1848
1840
self.assertRaises(errors.BadBundle, next, record_iter)
1851
class TestReadMergeableFromUrl(tests.TestCaseWithTransport):
1853
def test_read_mergeable_skips_local(self):
1854
"""A local bundle named like the URL should not be read.
1856
out, wt = test_read_bundle.create_bundle_file(self)
1857
class FooService(object):
1858
"""A directory service that always returns source"""
1860
def look_up(self, name, url):
1862
directories.register('foo:', FooService, 'Testing directory service')
1863
self.addCleanup(directories.remove, 'foo:')
1864
self.build_tree_contents([('./foo:bar', out.getvalue())])
1865
self.assertRaises(errors.NotABundle, read_mergeable_from_url,
1868
def test_infinite_redirects_are_not_a_bundle(self):
1869
"""If a URL causes TooManyRedirections then NotABundle is raised.
1871
from .blackbox.test_push import RedirectingMemoryServer
1872
server = RedirectingMemoryServer()
1873
self.start_server(server)
1874
url = server.get_url() + 'infinite-loop'
1875
self.assertRaises(errors.NotABundle, read_mergeable_from_url, url)
1877
def test_smart_server_connection_reset(self):
1878
"""If a smart server connection fails during the attempt to read a
1879
bundle, then the ConnectionReset error should be propagated.
1881
# Instantiate a server that will provoke a ConnectionReset
1882
sock_server = DisconnectingServer()
1883
self.start_server(sock_server)
1884
# We don't really care what the url is since the server will close the
1885
# connection without interpreting it
1886
url = sock_server.get_url()
1887
self.assertRaises(errors.ConnectionReset, read_mergeable_from_url, url)
1890
class DisconnectingHandler(socketserver.BaseRequestHandler):
1891
"""A request handler that immediately closes any connection made to it."""
1894
self.request.close()
1897
class DisconnectingServer(test_server.TestingTCPServerInAThread):
1900
super(DisconnectingServer, self).__init__(
1902
test_server.TestingTCPServer,
1903
DisconnectingHandler)
1906
"""Return the url of the server"""
1907
return "bzr://%s:%d/" % self.server.server_address