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
1836
1828
self.assertEqual((None, {b'foo': b'bar', b'storage_kind': b'header'},
1837
1829
'info', None, None), record)
1838
1830
self.assertRaises(errors.BadBundle, next, record_iter)
1841
class TestReadMergeableFromUrl(tests.TestCaseWithTransport):
1843
def test_read_mergeable_skips_local(self):
1844
"""A local bundle named like the URL should not be read.
1846
out, wt = test_read_bundle.create_bundle_file(self)
1848
class FooService(object):
1849
"""A directory service that always returns source"""
1851
def look_up(self, name, url, purpose=None):
1853
directories.register('foo:', FooService, 'Testing directory service')
1854
self.addCleanup(directories.remove, 'foo:')
1855
self.build_tree_contents([('./foo:bar', out.getvalue())])
1856
self.assertRaises(errors.NotABundle, read_mergeable_from_url,
1859
def test_infinite_redirects_are_not_a_bundle(self):
1860
"""If a URL causes TooManyRedirections then NotABundle is raised.
1862
from .blackbox.test_push import RedirectingMemoryServer
1863
server = RedirectingMemoryServer()
1864
self.start_server(server)
1865
url = server.get_url() + 'infinite-loop'
1866
self.assertRaises(errors.NotABundle, read_mergeable_from_url, url)
1868
def test_smart_server_connection_reset(self):
1869
"""If a smart server connection fails during the attempt to read a
1870
bundle, then the ConnectionReset error should be propagated.
1872
# Instantiate a server that will provoke a ConnectionReset
1873
sock_server = DisconnectingServer()
1874
self.start_server(sock_server)
1875
# We don't really care what the url is since the server will close the
1876
# connection without interpreting it
1877
url = sock_server.get_url()
1878
self.assertRaises(errors.ConnectionReset, read_mergeable_from_url, url)
1881
class DisconnectingHandler(socketserver.BaseRequestHandler):
1882
"""A request handler that immediately closes any connection made to it."""
1885
self.request.close()
1888
class DisconnectingServer(test_server.TestingTCPServerInAThread):
1891
super(DisconnectingServer, self).__init__(
1893
test_server.TestingTCPServer,
1894
DisconnectingHandler)
1897
"""Return the url of the server"""
1898
return "bzr://%s:%d/" % self.server.server_address