Rev 2169: Make branch_implementations/test_http.py a little clearer. in sftp://bazaar.launchpad.net/%7Ebzr/bzr/hpss/

Andrew Bennetts andrew.bennetts at canonical.com
Wed Mar 21 05:47:37 GMT 2007


At sftp://bazaar.launchpad.net/%7Ebzr/bzr/hpss/

------------------------------------------------------------
revno: 2169
revision-id: andrew.bennetts at canonical.com-20070321054214-zri3jrjvxiepvhl6
parent: andrew.bennetts at canonical.com-20070316034056-2htzztjob2i4wsrt
committer: Andrew Bennetts <andrew.bennetts at canonical.com>
branch nick: hpss
timestamp: Wed 2007-03-21 16:42:14 +1100
message:
  Make branch_implementations/test_http.py a little clearer.
modified:
  BRANCH.TODO                    BRANCH.TODO-20060103052123-79ac4969351c03a9
  bzrlib/tests/branch_implementations/test_http.py test_http.py-20060731224648-2eef7ae5yja95rya-1
=== modified file 'BRANCH.TODO'
--- a/BRANCH.TODO	2007-03-13 06:55:43 +0000
+++ b/BRANCH.TODO	2007-03-21 05:42:14 +0000
@@ -21,3 +21,5 @@
 Implement RemoteBzrDir.find_repository directly for performance.
 
 decide what to do when operating on a branch on a server that is bound to another.
+
+urlutils.* operations on URLS which are obtained from a chrooted transport may be used to escape the chroot.

=== modified file 'bzrlib/tests/branch_implementations/test_http.py'
--- a/bzrlib/tests/branch_implementations/test_http.py	2007-03-16 01:44:06 +0000
+++ b/bzrlib/tests/branch_implementations/test_http.py	2007-03-21 05:42:14 +0000
@@ -14,59 +14,64 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-"""Test branch responses when accessed over http"""
+"""Test branches with inaccessible parents."""
 
 import os
 
 from bzrlib import branch, errors
 from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
 from bzrlib.tests.HttpServer import HttpServer
-
-
-class HTTPBranchTests(TestCaseWithBranch):
-    """Tests that use an HTTP server against each branch implementation"""
+from bzrlib.transport.local import LocalURLServer
+from bzrlib.transport.chroot import ChrootServer
+
+
+class InaccessibleParentTests(TestCaseWithBranch):
+    """Tests with branches with "inaccessible" parents.
+    
+    An "inaccessible" parent location is one that cannot be represented, e.g. if
+    a child branch says its parent is at "../../my-parent", but that child is at
+    "http://host/one" then that parent location is inaccessible.  These
+    branches' get_parent method will raise InaccessibleParent.
+    """
 
     def setUp(self):
-        super(HTTPBranchTests, self).setUp()
-        self.transport_readonly_server = HttpServer
-
-    def get_parent_and_child(self):
-        os.makedirs('parent/path/to')
-        wt_a = self.make_branch_and_tree('parent/path/to/a')
-        self.build_tree(['parent/path/to/a/one'])
-        wt_a.add(['one'])
-        wt_a.commit('commit one', rev_id='1')
-
-        os.makedirs('child/path/to')
-        branch_b = wt_a.bzrdir.sprout('child/path/to/b', revision_id='1').open_branch()
-        self.assertEqual(wt_a.branch.base, branch_b.get_parent())
-
-        return wt_a.branch, branch_b
+        super(InaccessibleParentTests, self).setUp()
+        if self.vfs_transport_factory is LocalURLServer:
+            self.vfs_transport_factory = ChrootServer
+
+    def get_branch_with_invalid_parent(self):
+        """Get a branch whose get_parent will raise InaccessibleParent."""
+        self.build_tree(
+            ['parent/', 'parent/path/', 'parent/path/to/',
+             'child/', 'child/path/', 'child/path/to/'],
+            transport=self.get_transport())
+        self.make_branch('parent/path/to/a').bzrdir.sprout(self.get_url('child/path/to/b'))
+
+        # The child branch internally will have recorded that its parent is at
+        # "../../../../parent/path/to/a" or similar.  So we move the child
+        # branch up several directories, so that its parent path will point to
+        # somewhere outside the directory served by the HTTP server.  Thus its
+        # parent is now inaccessible.
+        self.get_transport().rename('child/path/to/b', 'b')
+        branch_b = branch.Branch.open(self.get_readonly_url('b'))
+        return branch_b
 
     def test_get_parent_invalid(self):
-        self.get_parent_and_child()
-
-        # Now change directory, and access the child through http
-        os.chdir('child/path/to')
-        branch_b = branch.Branch.open(self.get_readonly_url('b'))
+        # When you have a branch whose parent URL cannot be calculated, this
+        # exception will be raised.
+        branch_b = self.get_branch_with_invalid_parent()
         self.assertRaises(errors.InaccessibleParent, branch_b.get_parent)
 
     def test_clone_invalid_parent(self):
-        self.get_parent_and_child()
-
-        # Now change directory, and access the child through http
-        os.chdir('child/path/to')
-        branch_b = branch.Branch.open(self.get_readonly_url('b'))
-
+        # If clone can't determine the location of the parent of the branch
+        # being cloned, then the new branch will have no parent set.
+        branch_b = self.get_branch_with_invalid_parent()
         branch_c = branch_b.bzrdir.clone('c').open_branch()
         self.assertEqual(None, branch_c.get_parent())
 
     def test_sprout_invalid_parent(self):
-        self.get_parent_and_child()
-
-        # Now change directory, and access the child through http
-        os.chdir('child/path/to')
-        branch_b = branch.Branch.open(self.get_readonly_url('b'))
-
+        # A sprouted branch will have a parent of the branch it was sprouted
+        # from, even if that branch has an invalid parent.
+        branch_b = self.get_branch_with_invalid_parent()
         branch_c = branch_b.bzrdir.sprout('c').open_branch()
         self.assertEqual(branch_b.base, branch_c.get_parent())




More information about the bazaar-commits mailing list