Rev 6: Really use the transports and test against all targeted protocols. in file:///v/home/vila/.bazaar/plugins/upload/

Vincent Ladeuil v.ladeuil+lp at free.fr
Sat Mar 15 10:11:46 GMT 2008


At file:///v/home/vila/.bazaar/plugins/upload/

------------------------------------------------------------
revno: 6
revision-id:v.ladeuil+lp at free.fr-20080315101145-lz3r7xdekx2mspbv
parent: v.ladeuil+lp at free.fr-20080312111235-7yr279ulz001uy6p
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: upload
timestamp: Sat 2008-03-15 11:11:45 +0100
message:
  Really use the transports and test against all targeted protocols.
  
  * test_upload.py:
  (TransportAdapter._test_permutations, load_tests): Parametrized
  tests by transport.
  (TestUpload.test_full_upload, TestUpload.test_incremental_upload,
  TestUpload.test_invalid_revspec): Use the transport instead of
  cheating by accessing disk behind the scenes.
  
  * __init__.py:
  (cmd_upload.upload_full_tree): Use the transport to put the bytes.
modified:
  __init__.py                    __init__.py-20080307145942-xx1xgifrreovahgz-1
  test_upload.py                 test_upload.py-20080307145942-xx1xgifrreovahgz-2
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2008-03-12 11:12:35 +0000
+++ b/__init__.py	2008-03-15 10:11:45 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2007 Canonical Ltd
+# Copyright (C) 2008 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -14,7 +14,13 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-"""Upload a working tree, incrementally"""
+"""Upload a working tree, incrementally.
+
+The only bzr-related info uploaded with the working tree is the corrseponding
+revision id. The uploaded working tree is not linked to any other bzr data.
+
+The intended use is for web sites.
+"""
 
 from bzrlib import (
     commands,
@@ -70,7 +76,6 @@
     def upload_full_tree(self):
         self.dest.ensure_base() # XXX: Handle errors
         self.tree.lock_read()
-        dpath = self.dest.local_abspath('.')
         try:
             inv = self.tree.inventory
             entries = inv.iter_entries()
@@ -81,7 +86,7 @@
                 if dp == ".bzrignore":
                     continue
 
-                ie.put_on_disk(dpath, dp, self.tree)
+                self.dest.put_bytes(dp, self.tree.get_file_text(ie.file_id))
             self.set_uploaded_revid(self.rev_id)
         finally:
             self.tree.unlock()

=== modified file 'test_upload.py'
--- a/test_upload.py	2008-03-12 11:12:35 +0000
+++ b/test_upload.py	2008-03-15 10:11:45 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2007 Canonical Ltd
+# Copyright (C) 2008 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -22,10 +22,49 @@
     revisionspec,
     tests,
     )
+from bzrlib.tests import test_transport_implementations
 
 from bzrlib.plugins.upload import cmd_upload
 
 
+class TransportAdapter(
+    test_transport_implementations.TransportTestProviderAdapter):
+    """A tool to generate a suite testing all transports for a single test.
+
+    We restrict the transports to the ones we want to support.
+    """
+
+    def _test_permutations(self):
+        """Return a list of the klass, server_factory pairs to test."""
+        result = []
+        transport_modules =['bzrlib.transport.ftp',
+                            'bzrlib.transport.sftp']
+        for module in transport_modules:
+            try:
+                permutations = self.get_transport_test_permutations(
+                    reduce(getattr, (module).split('.')[1:],
+                           __import__(module)))
+                for (klass, server_factory) in permutations:
+                    scenario = (server_factory.__name__,
+                        {"transport_class":klass,
+                         "transport_server":server_factory})
+                    result.append(scenario)
+            except errors.DependencyNotPresent, e:
+                # Continue even if a dependency prevents us 
+                # from adding this test
+                pass
+        return result
+
+
+def load_tests(standard_tests, module, loader):
+    """Multiply tests for tranport implementations."""
+    result = loader.suiteClass()
+    adapter = TransportAdapter()
+    for test in tests.iter_suite_tests(standard_tests):
+        result.addTests(adapter.adapt(test))
+    return result
+
+
 class TestUpload(tests.TestCaseWithTransport):
 
     def _create_branch(self):
@@ -45,8 +84,9 @@
 
         os.chdir('branch')
         upload = cmd_upload()
+        up_url = self.get_transport('upload').external_url()
 
-        upload.run('../upload', full=True)
+        upload.run(up_url, full=True)
 
         self.assertFileEqual('bar', '../upload/hello')
         self.assertFileEqual('baz', '../upload/goodbye')
@@ -56,16 +96,17 @@
 
         os.chdir('branch')
         upload = cmd_upload()
+        up_url = self.get_transport('upload').external_url()
 
         # Upload revision 1 only
         revspec = revisionspec.RevisionSpec.from_string('1')
-        upload.run('../upload', revision=[revspec], full=True)
+        upload.run(up_url, revision=[revspec], full=True)
 
         self.assertFileEqual('foo', '../upload/hello')
         self.failIfExists('../upload/goodbye')
 
         # Upload current revision
-        upload.run('../upload')
+        upload.run(up_url)
 
         self.assertFileEqual('bar','../upload/hello')
         self.assertFileEqual('baz', '../upload/goodbye')
@@ -75,6 +116,7 @@
         rev1 = revisionspec.RevisionSpec.from_string('1')
         rev2 = revisionspec.RevisionSpec.from_string('2')
         upload = cmd_upload()
+        up_url = self.get_transport('upload').external_url()
         self.assertRaises(errors.BzrCommandError, upload.run,
-                          '../upload', revision=[rev1, rev2])
+                          up_url, revision=[rev1, rev2])
 



More information about the bazaar-commits mailing list