[Checkins] SVN: zope.app.fssync/branches/jim-hack/src/zope/app/fssync/ Added tests for the merge command.

Amos Latteier amos at latteier.com
Fri Feb 13 10:16:01 EST 2009


Log message for revision 96491:
  Added tests for the merge command.
  

Changed:
  U   zope.app.fssync/branches/jim-hack/src/zope/app/fssync/fssync.py
  U   zope.app.fssync/branches/jim-hack/src/zope/app/fssync/ftests.py
  A   zope.app.fssync/branches/jim-hack/src/zope/app/fssync/merge.txt

-=-
Modified: zope.app.fssync/branches/jim-hack/src/zope/app/fssync/fssync.py
===================================================================
--- zope.app.fssync/branches/jim-hack/src/zope/app/fssync/fssync.py	2009-02-13 10:53:16 UTC (rev 96490)
+++ zope.app.fssync/branches/jim-hack/src/zope/app/fssync/fssync.py	2009-02-13 15:16:00 UTC (rev 96491)
@@ -473,13 +473,17 @@
 
         # make sure that we're merging from compatible directories
         if not self.metadata.getentry(target):
-            target = join(target, 'root')
+            names = self.metadata.getnames(target)
+            if len(names) == 1:
+                target = join(target, names[0])
         target_entry = self.metadata.getentry(target)
         if not target_entry:
             print 'Target must be a fssync checkout directory'
             return
         if not self.metadata.getentry(source):
-            source = join(source, 'root')
+            names = self.metadata.getnames(source)
+            if len(names) == 1:
+                source = join(source, names[0])
         source_entry = self.metadata.getentry(source)
         if not source_entry:
             print 'Source must be a fssync checkout directory'

Modified: zope.app.fssync/branches/jim-hack/src/zope/app/fssync/ftests.py
===================================================================
--- zope.app.fssync/branches/jim-hack/src/zope/app/fssync/ftests.py	2009-02-13 10:53:16 UTC (rev 96490)
+++ zope.app.fssync/branches/jim-hack/src/zope/app/fssync/ftests.py	2009-02-13 15:16:00 UTC (rev 96491)
@@ -31,6 +31,7 @@
 from zope.app.fssync.testing import TestNetwork
 
 checkoutdir = tempfile.mkdtemp(prefix='checkoutdir')
+checkoutdir2 = tempfile.mkdtemp(prefix='checkoutdir2')
 
 checker = renormalizing.RENormalizing([
     (re.compile(r"\\"), r"/"),
@@ -40,10 +41,13 @@
     module.setUp(test, 'zope.app.fssync.fssync_txt')
     if not os.path.exists(checkoutdir):
         os.mkdir(checkoutdir)
+    if not os.path.exists(checkoutdir2):
+        os.mkdir(checkoutdir2)
 
 def tearDown(test):
     module.tearDown(test, 'zope.app.fssync.fssync_txt')
     shutil.rmtree(checkoutdir)
+    shutil.rmtree(checkoutdir2)
 
 def cleanUpTree(dir):
     if os.path.exists(dir):
@@ -51,11 +55,12 @@
     os.mkdir(dir)
 
 def test_suite():
-    
+
     globs = {'os': os,
             'zope':zope,
             'pprint': doctestunit.pprint,
             'checkoutdir':checkoutdir,
+            'checkoutdir2': checkoutdir2,
             'cleanUpTree': cleanUpTree,
             'PublisherConnection': PublisherConnection,
             'TestNetwork': TestNetwork,
@@ -63,14 +68,14 @@
 
     suite = unittest.TestSuite()
 
-    for file in 'fssync.txt', 'security.txt', 'fssite.txt':
+    for file in 'fssync.txt', 'security.txt', 'fssite.txt', 'merge.txt':
         test = functional.FunctionalDocFileSuite(file,
                     setUp=setUp, tearDown=tearDown,
                     globs=globs, checker=checker,
                     optionflags=doctest.NORMALIZE_WHITESPACE+doctest.ELLIPSIS)
         test.layer = AppFSSyncLayer
         suite.addTest(test)
-        
+
     if sys.platform != 'win32':
         test = functional.FunctionalDocFileSuite('fsmerge.txt',
                     setUp=setUp, tearDown=tearDown,

Added: zope.app.fssync/branches/jim-hack/src/zope/app/fssync/merge.txt
===================================================================
--- zope.app.fssync/branches/jim-hack/src/zope/app/fssync/merge.txt	                        (rev 0)
+++ zope.app.fssync/branches/jim-hack/src/zope/app/fssync/merge.txt	2009-02-13 15:16:00 UTC (rev 96491)
@@ -0,0 +1,158 @@
+Merge Command
+=============
+
+The merge command copies changes from one checkout to another. It only
+copies changes and additions; it doesn't copy deletions. Its purpose
+is to allow changes on one server to be moved to another via
+fssync. For example, it could be used to move changes from a
+development to a production instance.
+
+Let's begin by creating a server with some data.
+
+    >>> root = getRootFolder()
+    >>> from zope.app.folder import Folder
+    >>> from zope.lifecycleevent import ObjectCreatedEvent
+    >>> serverfolder = root[u'test'] = Folder()
+    >>> from zope.app.file import File
+    >>> serverfile1 = File('A\nB\nC', 'text/plain')
+    >>> zope.event.notify(ObjectCreatedEvent(serverfile1))
+    >>> serverfolder[u'file1.txt'] = serverfile1
+    >>> serverfile2 = File('A\nB\nC', 'text/plain')
+    >>> zope.event.notify(ObjectCreatedEvent(serverfile2))
+    >>> serverfolder[u'file2.txt'] = serverfile2
+
+Now let's create two checkouts.
+
+    >>> os.path.exists(checkoutdir)
+    True
+    >>> os.path.exists(checkoutdir2)
+    True
+
+Now let's do the checkouts.
+
+    >>> from zope.app.fssync.fssync import FSSync
+    >>> rooturl = 'http://globalmgr:globalmgrpw@localhost/test'
+    >>> network = TestNetwork(handle_errors=True)
+    >>> zsync = FSSync(network=network, rooturl=rooturl)
+
+    >>> zsync.checkout(checkoutdir)
+    N .../test/
+    U .../test/file1.txt
+    N .../test/@@Zope/Extra/file1.txt/
+    U .../test/@@Zope/Extra/file1.txt/contentType
+    N .../test/@@Zope/Annotations/file1.txt/
+    U .../test/@@Zope/Annotations/file1.txt/zope.app.dublincore.ZopeDublinCore
+    U .../test/file2.txt
+    N .../test/@@Zope/Extra/file2.txt/
+    U .../test/@@Zope/Extra/file2.txt/contentType
+    N .../test/@@Zope/Annotations/file2.txt/
+    U .../test/@@Zope/Annotations/file2.txt/zope.app.dublincore.ZopeDublinCore
+    N .../@@Zope/Annotations/test/
+    U .../@@Zope/Annotations/test/zope.app.dublincore.ZopeDublinCore
+    All done.
+
+    >>> zsync.checkout(checkoutdir2)
+    N .../test/
+    U .../test/file1.txt
+    N .../test/@@Zope/Extra/file1.txt/
+    U .../test/@@Zope/Extra/file1.txt/contentType
+    N .../test/@@Zope/Annotations/file1.txt/
+    U .../test/@@Zope/Annotations/file1.txt/zope.app.dublincore.ZopeDublinCore
+    U .../test/file2.txt
+    N .../test/@@Zope/Extra/file2.txt/
+    U .../test/@@Zope/Extra/file2.txt/contentType
+    N .../test/@@Zope/Annotations/file2.txt/
+    U .../test/@@Zope/Annotations/file2.txt/zope.app.dublincore.ZopeDublinCore
+    N .../@@Zope/Annotations/test/
+    U .../@@Zope/Annotations/test/zope.app.dublincore.ZopeDublinCore
+    All done.
+
+Now we'll make some changes to one of the checkouts.
+
+    >>> localfile1 = os.path.join(checkoutdir, 'test', 'file1.txt')
+    >>> fp = open(localfile1, 'w')
+    >>> fp.write('A modified text file')
+    >>> fp.close()
+
+An addition.
+
+    >>> localfile3 = os.path.join(checkoutdir, 'test', 'file3.txt')
+    >>> fp = open(localfile3, 'w')
+    >>> fp.write('A new text file')
+    >>> fp.close()
+    >>> zsync.add(localfile3)
+    A .../test/file3.txt
+
+Here's a deletion.
+
+    >>> os.unlink(os.path.join(checkoutdir, 'test', 'file2.txt'))
+    >>> zsync.remove(os.path.join(checkoutdir, 'test', 'file2.txt'))
+    R .../test/file2.txt
+
+Now we commit our changes.
+
+    >>> zsync.commit(os.path.join(checkoutdir, 'test'))
+    U .../test/file1.txt
+    U .../test/@@Zope/Annotations/file1.txt/zope.app.dublincore.ZopeDublinCore
+    D .../test/file2.txt
+    D .../test/@@Zope/Extra/file2.txt/contentType
+    D .../test/@@Zope/Extra/file2.txt/
+    D .../test/@@Zope/Annotations/file2.txt/zope.app.dublincore.ZopeDublinCore
+    D .../test/@@Zope/Annotations/file2.txt/
+    U .../test/file3.txt
+    N .../test/@@Zope/Extra/file3.txt/
+    U .../test/@@Zope/Extra/file3.txt/contentType
+    N .../test/@@Zope/Annotations/file3.txt/
+    U .../test/@@Zope/Annotations/file3.txt/zope.app.dublincore.ZopeDublinCore
+    All done.
+
+At this point the two checkouts are not in sync.
+
+    >>> f1 = open(os.path.join(checkoutdir, 'test', 'file1.txt'))
+    >>> f2 = open(os.path.join(checkoutdir2, 'test', 'file1.txt'))
+    >>> f1.read() == f2.read()
+    False
+
+    >>> f1.close()
+    >>> f2.close()
+
+Now we'll merge changes from one checkout to the other.
+
+    >>> zsync.merge((checkoutdir, checkoutdir2))
+    M .../test/file1.txt
+    A .../test/file3.txt
+    All done.
+
+The status command reflects the local changes.
+
+    >>> zsync.status(os.path.join(checkoutdir2, 'test'))
+    / .../test/
+    M .../test/file1.txt
+    = .../test/file2.txt
+    A .../test/file3.txt
+
+The change and the addition were picked up, but the deletion wasn't.
+
+Let's confirm that the changed and added files made it.
+
+    >>> f1 = open(os.path.join(checkoutdir, 'test', 'file1.txt'))
+    >>> f2 = open(os.path.join(checkoutdir2, 'test', 'file1.txt'))
+    >>> f1.read() == f2.read()
+    True
+
+    >>> f1.close()
+    >>> f2.close()
+
+    >>> f1 = open(os.path.join(checkoutdir, 'test', 'file3.txt'))
+    >>> f2 = open(os.path.join(checkoutdir2, 'test', 'file3.txt'))
+    >>> f1.read() == f2.read()
+    True
+
+    >>> f1.close()
+    >>> f2.close()
+
+Let's make sure that extras were also copied over.
+
+    >>> open(os.path.join(checkoutdir2, 'test', '@@Zope', 'Extra',
+    ...     'file3.txt', 'contentType')).read()
+    '<?xml version="1.0" encoding="utf-8" ?>\n<pickle> <string>text/plain</string> </pickle>\n'



More information about the Checkins mailing list