~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

(mbp) integrated 0.15 fixes: http redirection, dirstate validation, move in dirstate

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
                           UnknownFormatError,
37
37
                           UnsupportedFormatError,
38
38
                           )
39
 
from bzrlib.tests import TestCase, TestCaseWithTransport, test_sftp_transport
 
39
from bzrlib.tests import (
 
40
    TestCase,
 
41
    TestCaseWithTransport,
 
42
    test_sftp_transport
 
43
    )
40
44
from bzrlib.tests.HttpServer import HttpServer
 
45
from bzrlib.tests.HTTPTestUtil import (
 
46
    TestCaseWithTwoWebservers,
 
47
    HTTPServerRedirecting,
 
48
    )
 
49
from bzrlib.tests.test_http import TestWithTransport_pycurl
41
50
from bzrlib.transport import get_transport
 
51
from bzrlib.transport.http._urllib import HttpTransport_urllib
42
52
from bzrlib.transport.memory import MemoryServer
43
53
from bzrlib.repofmt import knitrepo, weaverepo
44
54
 
765
775
    def test_open_containing_tree_or_branch(self):
766
776
        tree = self.make_branch_and_tree('tree')
767
777
        bzrdir.BzrDir.open_containing_tree_or_branch(self.get_url('tree'))
 
778
 
 
779
 
 
780
class TestHTTPRedirectionLoop(object):
 
781
    """Test redirection loop between two http servers.
 
782
 
 
783
    This MUST be used by daughter classes that also inherit from
 
784
    TestCaseWithTwoWebservers.
 
785
 
 
786
    We can't inherit directly from TestCaseWithTwoWebservers or the
 
787
    test framework will try to create an instance which cannot
 
788
    run, its implementation being incomplete. 
 
789
    """
 
790
 
 
791
    # Should be defined by daughter classes to ensure redirection
 
792
    # still use the same transport implementation (not currently
 
793
    # enforced as it's a bit tricky to get right (see the FIXME
 
794
    # in BzrDir.open_from_transport for the unique use case so
 
795
    # far)
 
796
    _qualifier = None
 
797
 
 
798
    def create_transport_readonly_server(self):
 
799
        return HTTPServerRedirecting()
 
800
 
 
801
    def create_transport_secondary_server(self):
 
802
        return HTTPServerRedirecting()
 
803
 
 
804
    def setUp(self):
 
805
        # Both servers redirect to each server creating a loop
 
806
        super(TestHTTPRedirectionLoop, self).setUp()
 
807
        # The redirections will point to the new server
 
808
        self.new_server = self.get_readonly_server()
 
809
        # The requests to the old server will be redirected
 
810
        self.old_server = self.get_secondary_server()
 
811
        # Configure the redirections
 
812
        self.old_server.redirect_to(self.new_server.host, self.new_server.port)
 
813
        self.new_server.redirect_to(self.old_server.host, self.old_server.port)
 
814
 
 
815
    def _qualified_url(self, host, port):
 
816
        return 'http+%s://%s:%s' % (self._qualifier, host, port)
 
817
 
 
818
    def test_loop(self):
 
819
        # Starting from either server should loop
 
820
        old_url = self._qualified_url(self.old_server.host, 
 
821
                                      self.old_server.port)
 
822
        oldt = self._transport(old_url)
 
823
        self.assertRaises(errors.NotBranchError,
 
824
                          bzrdir.BzrDir.open_from_transport, oldt)
 
825
        new_url = self._qualified_url(self.new_server.host, 
 
826
                                      self.new_server.port)
 
827
        newt = self._transport(new_url)
 
828
        self.assertRaises(errors.NotBranchError,
 
829
                          bzrdir.BzrDir.open_from_transport, newt)
 
830
 
 
831
 
 
832
class TestHTTPRedirections_urllib(TestHTTPRedirectionLoop,
 
833
                                  TestCaseWithTwoWebservers):
 
834
    """Tests redirections for urllib implementation"""
 
835
 
 
836
    _qualifier = 'urllib'
 
837
    _transport = HttpTransport_urllib
 
838
 
 
839
 
 
840
 
 
841
class TestHTTPRedirections_pycurl(TestWithTransport_pycurl,
 
842
                                  TestHTTPRedirectionLoop,
 
843
                                  TestCaseWithTwoWebservers):
 
844
    """Tests redirections for pycurl implementation"""
 
845
 
 
846
    _qualifier = 'pycurl'