~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Martin Pool
  • Date: 2007-04-04 01:22:11 UTC
  • mfrom: (2393.1.1 bzr.docs)
  • mto: This revision was merged to the branch mainline in revision 2397.
  • Revision ID: mbp@sourcefrog.net-20070404012211-sq269me6bai9m6xk
merge trunk and doc fix from elliot

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
    # Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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
 
335
345
 
336
346
    def test_create_branch_convenience_root(self):
337
347
        """Creating a branch at the root of a fs should work."""
338
 
        self.transport_server = MemoryServer
 
348
        self.vfs_transport_factory = MemoryServer
339
349
        # outside a repo the default convenience output is a repo+branch_tree
340
350
        format = bzrdir.format_registry.make_bzrdir('knit')
341
351
        branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(), 
413
423
 
414
424
    def setUp(self):
415
425
        super(ChrootedTests, self).setUp()
416
 
        if not self.transport_server == MemoryServer:
 
426
        if not self.vfs_transport_factory == MemoryServer:
417
427
            self.transport_readonly_server = HttpServer
418
428
 
419
429
    def test_open_containing(self):
454
464
                         local_branch_path(branch))
455
465
        self.assertIs(tree.bzrdir, branch.bzrdir)
456
466
        self.assertEqual('foo', relpath)
 
467
        # opening from non-local should not return the tree
 
468
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
 
469
            self.get_readonly_url('topdir/foo'))
 
470
        self.assertEqual(None, tree)
 
471
        self.assertEqual('foo', relpath)
 
472
        # without a tree:
457
473
        self.make_branch('topdir/foo')
458
474
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
459
475
            'topdir/foo')
716
732
 
717
733
    def setUp(self):
718
734
        super(NonLocalTests, self).setUp()
719
 
        self.transport_server = MemoryServer
 
735
        self.vfs_transport_factory = MemoryServer
720
736
    
721
737
    def test_create_branch_convenience(self):
722
738
        # outside a repo the default convenience output is a repo+branch_tree
760
776
                              workingtree.WorkingTreeFormat3)
761
777
 
762
778
 
763
 
class TestRemoteSFTP(test_sftp_transport.TestCaseWithSFTPServer):
764
 
 
765
 
    def test_open_containing_tree_or_branch(self):
766
 
        tree = self.make_branch_and_tree('tree')
767
 
        bzrdir.BzrDir.open_containing_tree_or_branch(self.get_url('tree'))
 
779
class TestHTTPRedirectionLoop(object):
 
780
    """Test redirection loop between two http servers.
 
781
 
 
782
    This MUST be used by daughter classes that also inherit from
 
783
    TestCaseWithTwoWebservers.
 
784
 
 
785
    We can't inherit directly from TestCaseWithTwoWebservers or the
 
786
    test framework will try to create an instance which cannot
 
787
    run, its implementation being incomplete. 
 
788
    """
 
789
 
 
790
    # Should be defined by daughter classes to ensure redirection
 
791
    # still use the same transport implementation (not currently
 
792
    # enforced as it's a bit tricky to get right (see the FIXME
 
793
    # in BzrDir.open_from_transport for the unique use case so
 
794
    # far)
 
795
    _qualifier = None
 
796
 
 
797
    def create_transport_readonly_server(self):
 
798
        return HTTPServerRedirecting()
 
799
 
 
800
    def create_transport_secondary_server(self):
 
801
        return HTTPServerRedirecting()
 
802
 
 
803
    def setUp(self):
 
804
        # Both servers redirect to each server creating a loop
 
805
        super(TestHTTPRedirectionLoop, self).setUp()
 
806
        # The redirections will point to the new server
 
807
        self.new_server = self.get_readonly_server()
 
808
        # The requests to the old server will be redirected
 
809
        self.old_server = self.get_secondary_server()
 
810
        # Configure the redirections
 
811
        self.old_server.redirect_to(self.new_server.host, self.new_server.port)
 
812
        self.new_server.redirect_to(self.old_server.host, self.old_server.port)
 
813
 
 
814
    def _qualified_url(self, host, port):
 
815
        return 'http+%s://%s:%s' % (self._qualifier, host, port)
 
816
 
 
817
    def test_loop(self):
 
818
        # Starting from either server should loop
 
819
        old_url = self._qualified_url(self.old_server.host, 
 
820
                                      self.old_server.port)
 
821
        oldt = self._transport(old_url)
 
822
        self.assertRaises(errors.NotBranchError,
 
823
                          bzrdir.BzrDir.open_from_transport, oldt)
 
824
        new_url = self._qualified_url(self.new_server.host, 
 
825
                                      self.new_server.port)
 
826
        newt = self._transport(new_url)
 
827
        self.assertRaises(errors.NotBranchError,
 
828
                          bzrdir.BzrDir.open_from_transport, newt)
 
829
 
 
830
 
 
831
class TestHTTPRedirections_urllib(TestHTTPRedirectionLoop,
 
832
                                  TestCaseWithTwoWebservers):
 
833
    """Tests redirections for urllib implementation"""
 
834
 
 
835
    _qualifier = 'urllib'
 
836
    _transport = HttpTransport_urllib
 
837
 
 
838
 
 
839
 
 
840
class TestHTTPRedirections_pycurl(TestWithTransport_pycurl,
 
841
                                  TestHTTPRedirectionLoop,
 
842
                                  TestCaseWithTwoWebservers):
 
843
    """Tests redirections for pycurl implementation"""
 
844
 
 
845
    _qualifier = 'pycurl'