~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: v.ladeuil+lp at free
  • Date: 2007-02-04 17:41:12 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-20070204174112-iv6gxzinnjddlaxj
Add tests for redirection. Preserve transport decorations.

* bzrlib/tests/test_http.py:
(TestRedirections): new tests.

* bzrlib/tests/HttpServer.py:
(HttpServer): Make server host and port public once the socket
have been established.

* bzrlib/tests/HTTPTestUtil.py:
(RedirectRequestHandler, HTTPServerRedirecting): New http test
server for redirections. Only a whole host can be redirected, so
far.

* bzrlib/errors.py:
(RedirectRequested.__init__): Add a 'qual_proto' oso that
transport decorations can be transmitted to redirected transport.
(RedirectRequested._requalify_url,
RedirectRequested.get_source_url,
RedirectRequested.get_target_url): New methods providing fully
decorated urls.

* bzrlib/bzrdir.py:
(BzrDir.open_from_transport): The redirection should preserve
transport decorations.
(BzrDirMetaFormat1): To be able to specialize bzr branches from
foreign branches, we need to register BzrDirMetaFormat1 as the
default control format (instead of BzrDirMetaFormat which is
abstract and can still be used by foreign branches).

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
    BadStatusRequestHandler,
43
43
    FakeProxyRequestHandler,
44
44
    ForbiddenRequestHandler,
 
45
    HTTPServerRedirecting,
45
46
    InvalidStatusRequestHandler,
46
47
    NoRangeRequestHandler,
47
48
    SingleRangeRequestHandler,
814
815
                        TestRanges,
815
816
                        TestCaseWithWebserver):
816
817
    """Test the Range header in GET methods for pycurl implementation"""
 
818
 
 
819
 
 
820
class TestRedirections(object):
 
821
    """Test redirection from the 'old' server to the 'new' server.
 
822
 
 
823
    This MUST be used by daughter classes that also inherit from
 
824
    TestCaseWithTwoWebservers.
 
825
 
 
826
    We can't inherit directly from TestCaseWithTwoWebservers or the
 
827
    test framework will try to create an instance which cannot
 
828
    run, its implementation being incomplete. 
 
829
    """
 
830
 
 
831
    def create_transport_secondary_server(self):
 
832
        """Create the secondary server redirecting to the primary server"""
 
833
        new = self.get_new_server()
 
834
 
 
835
        return HTTPServerRedirecting(new.host, new.port)
 
836
 
 
837
    def get_old_server(self):
 
838
        """The redirected server"""
 
839
        return self.get_secondary_server()
 
840
 
 
841
    def get_new_server(self):
 
842
        """The redirected to server"""
 
843
        return self.get_readonly_server()
 
844
 
 
845
    def setUp(self):
 
846
        super(TestRedirections, self).setUp()
 
847
        new = self.get_new_server()
 
848
        old = self.get_old_server()
 
849
 
 
850
        self.build_tree_contents([('a', '0123456789')],)
 
851
 
 
852
        self.new_transport = self._transport(new.get_url())
 
853
        self.old_transport = self._transport(old.get_url())
 
854
 
 
855
    def test_redirected(self):
 
856
        old = self.old_transport
 
857
        hints = old.create_get_hints(follow_redirections=False)
 
858
        self.assertRaises(errors.RedirectRequested, old.get, 'a', **hints)
 
859
 
 
860
    def test_redirection_loop(self):
 
861
        pass
 
862
 
 
863
 
 
864
class TestRedirections_urllib(TestRedirections,
 
865
                              TestCaseWithTwoWebservers):
 
866
    """Tests redirections for urllib implementation"""
 
867
 
 
868
    _transport = HttpTransport_urllib
 
869