35
35
UnsupportedFormatError,
37
37
import bzrlib.repository as repository
38
from bzrlib.tests import TestCase, TestCaseWithTransport, test_sftp_transport
38
from bzrlib.tests import (
40
TestCaseWithTransport,
39
43
from bzrlib.tests.HttpServer import HttpServer
44
from bzrlib.tests.HTTPTestUtil import (
45
TestCaseWithTwoWebservers,
46
HTTPServerRedirecting,
48
from bzrlib.tests.test_http import TestWithTransport_pycurl
40
49
from bzrlib.transport import get_transport
50
from bzrlib.transport.http._urllib import HttpTransport_urllib
41
51
from bzrlib.transport.memory import MemoryServer
42
52
import bzrlib.workingtree as workingtree
675
685
def test_open_containing_tree_or_branch(self):
676
686
tree = self.make_branch_and_tree('tree')
677
687
bzrdir.BzrDir.open_containing_tree_or_branch(self.get_url('tree'))
690
class TestHTTPRedirectionLoop(object):
691
"""Test redirection loop between two http servers.
693
This MUST be used by daughter classes that also inherit from
694
TestCaseWithTwoWebservers.
696
We can't inherit directly from TestCaseWithTwoWebservers or the
697
test framework will try to create an instance which cannot
698
run, its implementation being incomplete.
701
# Should be defined by daughter classes to ensure redirection
702
# still use the same transport implementation
705
def create_transport_readonly_server(self):
706
return HTTPServerRedirecting()
708
def create_transport_secondary_server(self):
709
return HTTPServerRedirecting()
712
# Both servers redirect to each server creating a loop
713
super(TestHTTPRedirectionLoop, self).setUp()
714
# The redirections will point to the new server
715
self.new_server = self.get_readonly_server()
716
# The requests to the old server will be redirected
717
self.old_server = self.get_secondary_server()
718
# Configure the redirections
719
self.old_server.redirect_to(self.new_server.host, self.new_server.port)
720
self.new_server.redirect_to(self.old_server.host, self.old_server.port)
722
def _qualified_url(self, host, port):
723
return 'http+%s://%s:%s' % (self._qualifier, host, port)
726
# Starting from either server should loop
727
old_url = self._qualified_url(self.old_server.host,
728
self.old_server.port)
729
oldt = self._transport(old_url)
730
self.assertRaises(errors.NotBranchError,
731
bzrdir.BzrDir.open_from_transport, oldt)
732
new_url = self._qualified_url(self.new_server.host,
733
self.new_server.port)
734
newt = self._transport(new_url)
735
self.assertRaises(errors.NotBranchError,
736
bzrdir.BzrDir.open_from_transport, newt)
739
class TestHTTPRedirections_urllib(TestHTTPRedirectionLoop,
740
TestCaseWithTwoWebservers):
741
"""Tests redirections for urllib implementation"""
743
_qualifier = 'urllib'
744
_transport = HttpTransport_urllib
748
class TestHTTPRedirections_pycurl(TestWithTransport_pycurl,
749
TestHTTPRedirectionLoop,
750
TestCaseWithTwoWebservers):
751
"""Tests redirections for pycurl implementation"""
753
_qualifier = 'pycurl'