~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Vincent Ladeuil
  • Date: 2007-02-12 14:02:01 UTC
  • mto: (2323.7.1 redirection)
  • mto: This revision was merged to the branch mainline in revision 2390.
  • Revision ID: v.ladeuil+lp@free.fr-20070212140201-khf5tnm6skh2ic0k
Add tests.

* bzrlib/transport/http/_urllib.py:
(HttpTransport_urllib.has): Ignores 302 error code, it is already
handled.

* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport.has): Set headers acquisition. Pass headers to
_curl_perform. Ignores 302 error code, it is already
handled.
(PyCurlTransport._get_full, PyCurlTransport._get_ranged): Pass
headers to _curl_perform.
(PyCurlTransport._post): Pass headers to _curl_perform.
(PyCurlTransport._set_curl_options): Do not follow redirections
anymore.
(PyCurlTransport._curl_perform): Handle redirections by raising

* bzrlib/tests/test_http.py:
(TestHTTPRedirections): Simplified.
(TestHTTPRedirections_pycurl): New class.

* bzrlib/tests/test_bzrdir.py:
(TestHTTPRedirectionLoop, TestHTTPRedirections_urllib,
TestHTTPRedirections_pycurl): New classes to test redirection
loops when opening bzrdirs.

* bzrlib/tests/HTTPTestUtil.py:
(HTTPServerRedirecting.redirect_to,
HTTPServerRedirecting.redirected_to_address): New methods.

* bzrlib/bzrdir.py:
(BzrDirMetaFormat1.probe_transport): Deleted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
                           UnsupportedFormatError,
36
36
                           )
37
37
import bzrlib.repository as repository
38
 
from bzrlib.tests import TestCase, TestCaseWithTransport, test_sftp_transport
 
38
from bzrlib.tests import (
 
39
    TestCase,
 
40
    TestCaseWithTransport,
 
41
    test_sftp_transport
 
42
    )
39
43
from bzrlib.tests.HttpServer import HttpServer
 
44
from bzrlib.tests.HTTPTestUtil import (
 
45
    TestCaseWithTwoWebservers,
 
46
    HTTPServerRedirecting,
 
47
    )
 
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
43
53
 
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'))
 
688
 
 
689
 
 
690
class TestHTTPRedirectionLoop(object):
 
691
    """Test redirection loop between two http servers.
 
692
 
 
693
    This MUST be used by daughter classes that also inherit from
 
694
    TestCaseWithTwoWebservers.
 
695
 
 
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. 
 
699
    """
 
700
 
 
701
    # Should be defined by daughter classes to ensure redirection
 
702
    # still use the same transport implementation
 
703
    _qualifier = None
 
704
 
 
705
    def create_transport_readonly_server(self):
 
706
        return HTTPServerRedirecting()
 
707
 
 
708
    def create_transport_secondary_server(self):
 
709
        return HTTPServerRedirecting()
 
710
 
 
711
    def setUp(self):
 
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)
 
721
 
 
722
    def _qualified_url(self, host, port):
 
723
        return 'http+%s://%s:%s' % (self._qualifier, host, port)
 
724
 
 
725
    def test_loop(self):
 
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)
 
737
 
 
738
 
 
739
class TestHTTPRedirections_urllib(TestHTTPRedirectionLoop,
 
740
                                  TestCaseWithTwoWebservers):
 
741
    """Tests redirections for urllib implementation"""
 
742
 
 
743
    _qualifier = 'urllib'
 
744
    _transport = HttpTransport_urllib
 
745
 
 
746
 
 
747
 
 
748
class TestHTTPRedirections_pycurl(TestWithTransport_pycurl,
 
749
                                  TestHTTPRedirectionLoop,
 
750
                                  TestCaseWithTwoWebservers):
 
751
    """Tests redirections for pycurl implementation"""
 
752
 
 
753
    _qualifier = 'pycurl'