46
49
InvalidStatusRequestHandler,
47
50
NoRangeRequestHandler,
48
51
SingleRangeRequestHandler,
52
TestCaseWithRedirectedWebserver,
49
53
TestCaseWithTwoWebservers,
50
54
TestCaseWithWebserver,
51
55
WallRequestHandler,
53
57
from bzrlib.transport import (
58
do_catching_redirections,
883
888
"""Test redirection between http servers.
885
890
This MUST be used by daughter classes that also inherit from
886
TestCaseWithTwoWebservers.
891
TestCaseWithRedirectedWebserver.
888
893
We can't inherit directly from TestCaseWithTwoWebservers or the
889
894
test framework will try to create an instance which cannot
902
907
super(TestHTTPRedirections, self).setUp()
903
# The redirections will point to the new server
904
new_server = self.get_readonly_server()
905
# The requests to the old server will be redirected
906
old_server = self.get_secondary_server()
908
self.build_tree_contents([('a', '0123456789')],)
910
self.old_transport = self._transport(old_server.get_url())
908
self.build_tree_contents([('a', '0123456789'),
910
'# Bazaar revision bundle v0.9\n#\n')
913
self.old_transport = self._transport(self.old_server.get_url())
912
915
def test_redirected(self):
913
916
self.assertRaises(errors.RedirectRequested, self.old_transport.get, 'a')
917
t = self._transport(self.new_server.get_url())
918
self.assertEqual('0123456789', t.get('a').read())
920
def test_read_redirected_bundle_from_url(self):
921
from bzrlib.bundle import read_bundle_from_url
922
url = self.old_transport.abspath('bundle')
923
bundle = read_bundle_from_url(url)
924
# If read_bundle_from_url was successful we get an empty bundle
925
self.assertEqual([], bundle.revisions)
916
928
class TestHTTPRedirections_urllib(TestHTTPRedirections,
917
TestCaseWithTwoWebservers):
929
TestCaseWithRedirectedWebserver):
918
930
"""Tests redirections for urllib implementation"""
920
932
_transport = HttpTransport_urllib
924
936
class TestHTTPRedirections_pycurl(TestWithTransport_pycurl,
925
937
TestHTTPRedirections,
926
TestCaseWithTwoWebservers):
938
TestCaseWithRedirectedWebserver):
927
939
"""Tests redirections for pycurl implementation"""
942
class TestDoCatchRedirections(TestCaseWithRedirectedWebserver):
943
"""Test transport.do_catching_redirections.
945
We arbitrarily choose to use urllib transports
948
_transport = HttpTransport_urllib
951
super(TestDoCatchRedirections, self).setUp()
952
self.build_tree_contents([('a', '0123456789'),],)
954
self.old_transport = self._transport(self.old_server.get_url())
956
def get_a(self, transport):
957
return transport.get('a')
959
def test_no_redirection(self):
960
t = self._transport(self.new_server.get_url())
962
# We use None for redirected so that we fail if redirected
963
self.assertEquals('0123456789',
964
do_catching_redirections(self.get_a, t, None).read())
966
def test_one_redirection(self):
967
self.redirections = 0
969
def redirected(transport, exception, redirection_notice):
970
self.redirections += 1
971
dir, file = urlutils.split(exception.target)
972
return self._transport(dir)
974
self.assertEquals('0123456789',
975
do_catching_redirections(self.get_a,
979
self.assertEquals(1, self.redirections)
981
def test_redirection_loop(self):
983
def redirected(transport, exception, redirection_notice):
984
# By using the redirected url as a base dir for the
985
# *old* transport, we create a loop: a => a/a =>
987
return self.old_transport.clone(exception.target)
989
self.assertRaises(errors.TooManyRedirections, do_catching_redirections,
990
self.get_a, self.old_transport, redirected)