chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpo...@apache.org
Subject svn commit: r1205506 - in /chemistry/cmislib/trunk/src: cmislib/model.py tests/cmislibtest.py tests/settings.py
Date Wed, 23 Nov 2011 17:41:13 GMT
Author: jpotts
Date: Wed Nov 23 17:41:12 2011
New Revision: 1205506

URL: http://svn.apache.org/viewvc?rev=1205506&view=rev
Log:
Support for change tokens, updated tests that do a checkout, to check for the canCheckOut
allowable action

Modified:
    chemistry/cmislib/trunk/src/cmislib/model.py
    chemistry/cmislib/trunk/src/tests/cmislibtest.py
    chemistry/cmislib/trunk/src/tests/settings.py

Modified: chemistry/cmislib/trunk/src/cmislib/model.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/trunk/src/cmislib/model.py?rev=1205506&r1=1205505&r2=1205506&view=diff
==============================================================================
--- chemistry/cmislib/trunk/src/cmislib/model.py (original)
+++ chemistry/cmislib/trunk/src/cmislib/model.py Wed Nov 23 17:41:12 2011
@@ -182,7 +182,7 @@ class CmisClient(object):
 
         """
         Does a get against the CMIS service. More than likely, you will not
-        need to call this method. Instead, let the other objects to it for you.
+        need to call this method. Instead, let the other objects do it for you.
 
         For example, if you need to get a specific object by object id, try
         :class:`Repository.getObject`. If you have a path instead of an object
@@ -209,7 +209,7 @@ class CmisClient(object):
 
         """
         Does a delete against the CMIS service. More than likely, you will not
-        need to call this method. Instead, let the other objects to it for you.
+        need to call this method. Instead, let the other objects do it for you.
 
         For example, to delete a folder you'd call :class:`Folder.delete` and
         to delete a document you'd call :class:`Document.delete`.
@@ -233,7 +233,7 @@ class CmisClient(object):
 
         """
         Does a post against the CMIS service. More than likely, you will not
-        need to call this method. Instead, let the other objects to it for you.
+        need to call this method. Instead, let the other objects do it for you.
 
         For example, to update the properties on an object, you'd call
         :class:`CmisObject.updateProperties`. Or, to check in a document that's
@@ -262,7 +262,7 @@ class CmisClient(object):
 
         """
         Does a put against the CMIS service. More than likely, you will not
-        need to call this method. Instead, let the other objects to it for you.
+        need to call this method. Instead, let the other objects do it for you.
 
         For example, to update the properties on an object, you'd call
         :class:`CmisObject.updateProperties`. Or, to check in a document that's
@@ -1909,21 +1909,25 @@ class CmisObject(object):
         >>> folder.getName()
         u'someFolderFoo'
 
-        The optional changeToken is not yet supported.
         """
 
-        # TODO need to support the changeToken
 
         # get the self link
         selfUrl = self._getSelfLink()
 
+        # if we have a change token, we must pass it back, per the spec
+        args = {}        
+        if self.properties.has_key('cmis:changeToken'):
+            args = {"changeToken": self.properties['cmis:changeToken']}
+
         # build the entry based on the properties provided
         xmlEntryDoc = getEntryXmlDoc(properties)
 
         # do a PUT of the entry
         updatedXmlDoc = self._cmisClient.put(selfUrl.encode('utf-8'),
                                              xmlEntryDoc.toxml(encoding='utf-8'),
-                                             ATOM_XML_TYPE)
+                                             ATOM_XML_TYPE,
+                                             **args)
 
         # reset the xmlDoc for this object with what we got back from
         # the PUT, then call initData we dont' want to call
@@ -2488,8 +2492,7 @@ class Document(CmisObject):
         See CMIS specification document 2.2.4.16 setContentStream
 
         The following optional arguments are not yet supported:
-         - overwriteFlag=None,
-         - changeToken=None
+         - overwriteFlag=None
         """
 
         # get this object's content stream link
@@ -2513,8 +2516,17 @@ class Document(CmisObject):
         if not mimetype:
             mimetype = 'application/binary'
 
+        # if we have a change token, we must pass it back, per the spec
+        args = {}        
+        if self.properties.has_key('cmis:changeToken'):
+            args = {"changeToken": self.properties['cmis:changeToken']}
+
         # put the content file
-        result = self._cmisClient.put(srcUrl.encode('utf-8'), contentFile.read(), mimetype)
+        result = self._cmisClient.put(srcUrl.encode('utf-8'),
+                                      contentFile.read(),
+                                      mimetype,
+                                      **args)
+
         if type(result) == HTTPError:
             raise CmisException(result.code)
 
@@ -2524,7 +2536,7 @@ class Document(CmisObject):
         # then return it
         return Document(self._cmisClient, self._repository, xmlDoc=result)
 
-    def deleteContentStream(self, changeToken=None):
+    def deleteContentStream(self):
 
         """
         See CMIS specification document 2.2.4.17 deleteContentStream
@@ -2543,8 +2555,13 @@ class Document(CmisObject):
         # delete the content stream when that is the case
         assert(srcUrl), 'Unable to determine content stream URL.'
 
+        # if we have a change token, we must pass it back, per the spec
+        args = {}        
+        if self.properties.has_key('cmis:changeToken'):
+            args = {"changeToken": self.properties['cmis:changeToken']}
+
         # delete the content stream
-        result = self._cmisClient.delete(srcUrl.encode('utf-8'))
+        result = self._cmisClient.delete(srcUrl.encode('utf-8'), **args)
         if type(result) == HTTPError:
             raise CmisException(result.code)
 
@@ -4049,4 +4066,4 @@ def getEntryXmlDoc(properties=None, cont
                 propElement.appendChild(valElement)
             propsElement.appendChild(propElement)
 
-    return entryXmlDoc
\ No newline at end of file
+    return entryXmlDoc

Modified: chemistry/cmislib/trunk/src/tests/cmislibtest.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/trunk/src/tests/cmislibtest.py?rev=1205506&r1=1205505&r2=1205506&view=diff
==============================================================================
--- chemistry/cmislib/trunk/src/tests/cmislibtest.py (original)
+++ chemistry/cmislib/trunk/src/tests/cmislibtest.py Wed Nov 23 17:41:12 2011
@@ -295,11 +295,20 @@ class RepositoryTest(CmisTestBase):
         f = open(settings.TEST_BINARY_1, 'rb')
         doc10 = self._testFolder.createDocument(settings.TEST_BINARY_1, contentFile=f)
         doc10Id = doc10.getObjectId()
+        if (not doc10.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         pwc = doc10.checkout()
         doc11 = pwc.checkin(major='false')  # checkin a minor version, 1.1
+        if (not doc11.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         pwc = doc11.checkout()
         doc20 = pwc.checkin()  # checkin a major version, 2.0
         doc20Id = doc20.getObjectId()
+        if (not doc20.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         pwc = doc20.checkout()
         doc21 = pwc.checkin(major='false')  # checkin a minor version, 2.1
         doc21Id = doc21.getObjectId()
@@ -359,7 +368,12 @@ class RepositoryTest(CmisTestBase):
         newDoc = testFolder.createDocument('testdoc')
 
         # make sure the new doc isn't in the unfiled collection
-        self.assertFalse(isInResultSet(self._repo.getUnfiledDocs(), newDoc))
+        try:
+            rs = self._repo.getUnfiledDocs()
+            self.assertFalse(isInResultSet(rs, newDoc))
+        except NotSupportedException:
+            print 'This repository does not support read access to the unfiled collection...skipping'
+            return
 
         # delete the test folder and tell it to unfile the testdoc
         objId = newDoc.getObjectId()
@@ -778,6 +792,9 @@ class DocumentTest(CmisTestBase):
     def testCheckout(self):
         '''Create a document in a test folder, then check it out'''
         newDoc = self._testFolder.createDocument('testDocument')
+        if (not newDoc.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         pwcDoc = newDoc.checkout()
         try:
             self.assertTrue(newDoc.isCheckedOut())
@@ -795,6 +812,9 @@ class DocumentTest(CmisTestBase):
         testDoc = self._testFolder.createDocument(testFilename, contentFile=contentFile)
         contentFile.close()
         self.assertEquals(testFilename, testDoc.getName())
+        if (not testDoc.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         pwcDoc = testDoc.checkout()
 
         try:
@@ -814,6 +834,9 @@ class DocumentTest(CmisTestBase):
         testDoc = self._testFolder.createDocument(testFilename, contentFile=contentFile)
         contentFile.close()
         self.assertEquals(testFilename, testDoc.getName())
+        if (not testDoc.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         pwcDoc = testDoc.checkout()
 
         try:
@@ -839,6 +862,9 @@ class DocumentTest(CmisTestBase):
         self.assertEquals(testFilename, testDoc.getName())
         # Alfresco has a bug where if you get the PWC this way
         # the checkin will not be successful
+        if (not testDoc.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         testDoc.checkout()
         pwcDoc = testDoc.getPrivateWorkingCopy()
         try:
@@ -855,6 +881,9 @@ class DocumentTest(CmisTestBase):
         '''Create a document in a test folder, check it out, then cancel
         checkout'''
         newDoc = self._testFolder.createDocument('testDocument')
+        if (not newDoc.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         pwcDoc = newDoc.checkout()
         try:
             self.assertTrue(newDoc.isCheckedOut())
@@ -881,11 +910,20 @@ class DocumentTest(CmisTestBase):
         '''Get latest version of an object'''
         f = open(settings.TEST_BINARY_1, 'rb')
         doc10 = self._testFolder.createDocument(settings.TEST_BINARY_1, contentFile=f)
+        if (not doc10.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         pwc = doc10.checkout()
         doc11 = pwc.checkin(major='false')  # checkin a minor version, 1.1
+        if (not doc11.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         pwc = doc11.checkout()
         doc20 = pwc.checkin()  # checkin a major version, 2.0
         doc20Id = doc20.getObjectId()
+        if (not doc20.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         pwc = doc20.checkout()
         doc21 = pwc.checkin(major='false')  # checkin a minor version, 2.1
         doc21Id = doc21.getObjectId()
@@ -900,13 +938,26 @@ class DocumentTest(CmisTestBase):
         '''Get properties of latest version of an object'''
         f = open(settings.TEST_BINARY_1, 'rb')
         doc10 = self._testFolder.createDocument(settings.TEST_BINARY_1, contentFile=f)
+        if (not doc10.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         pwc = doc10.checkout()
         doc11 = pwc.checkin(major='false')  # checkin a minor version, 1.1
+        if (not doc11.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         pwc = doc11.checkout()
         doc20 = pwc.checkin()  # checkin a major version, 2.0
+        # what comes back from a checkin may not include all props, so reload
+        doc20.reload()
         doc20Label = doc20.getProperties()['cmis:versionLabel']
+        if (not doc20.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         pwc = doc20.checkout()
         doc21 = pwc.checkin(major='false')  # checkin a minor version, 2.1
+        # what comes back from a checkin may not include all props, so reload
+        doc21.reload()
         doc21Label = doc21.getProperties()['cmis:versionLabel']
 
         propsLatest = doc10.getPropertiesOfLatestVersion()
@@ -932,7 +983,7 @@ class DocumentTest(CmisTestBase):
         '''Create a document in a test folder, then update its properties'''
         newDoc = self._testFolder.createDocument('testDocument')
         self.assertEquals('testDocument', newDoc.getName())
-        props = {'cmis:name': 'testDocument2', 'cmis:versionLabel': 'foo'}
+        props = {'cmis:name': 'testDocument2'}
         newDoc.updateProperties(props)
         self.assertEquals('testDocument2', newDoc.getName())
 
@@ -966,6 +1017,9 @@ class DocumentTest(CmisTestBase):
         self.assertEquals(testFile1Size, os.path.getsize(exportFile1))
 
         # checkout the file
+        if (not newDoc.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         pwc = newDoc.checkout()
 
         # update the PWC with a new file
@@ -1003,6 +1057,9 @@ class DocumentTest(CmisTestBase):
         contentFile.close()
 
         # checkout the file
+        if (not newDoc.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         pwc = newDoc.checkout()
 
         # update the PWC with a new file
@@ -1077,7 +1134,9 @@ class DocumentTest(CmisTestBase):
         contentFile = open(settings.TEST_BINARY_1, 'rb')
         newDoc = self._testFolder.createDocument(settings.TEST_BINARY_1, contentFile=contentFile)
         contentFile.close()
-
+        if (not newDoc.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         pwc = newDoc.checkout()
         pwc.deleteContentStream()
         self.assertRaises(CmisException, pwc.getContentStream)
@@ -1145,10 +1204,18 @@ class DocumentTest(CmisTestBase):
     def testGetAllVersions(self):
         '''Get all versions of an object'''
         testDoc = self._testFolder.createDocument('testdoc')
+        if (not testDoc.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         pwc = testDoc.checkout()
         doc = pwc.checkin()  # 2.0
+        if (not doc.allowableActions['canCheckOut']):
+            print 'The test doc cannot be checked out...skipping'
+            return
         pwc = doc.checkout()
         doc = pwc.checkin()  # 3.0
+        # what comes back from a checkin may not include all props, so reload
+        doc.reload()
         self.assertEquals('3.0', doc.getProperties()['cmis:versionLabel'])
         rs = doc.getAllVersions()
         self.assertEquals(3, len(rs.getResults()))

Modified: chemistry/cmislib/trunk/src/tests/settings.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/trunk/src/tests/settings.py?rev=1205506&r1=1205505&r2=1205506&view=diff
==============================================================================
--- chemistry/cmislib/trunk/src/tests/settings.py (original)
+++ chemistry/cmislib/trunk/src/tests/settings.py Wed Nov 23 17:41:12 2011
@@ -22,10 +22,11 @@
 #
 # CMIS repository's service URL
 #REPOSITORY_URL = 'http://cmis.alfresco.com/s/cmis'
-#REPOSITORY_URL = 'http://localhost:8080/cmis/repository' # Apache Chemistry
+REPOSITORY_URL = 'http://localhost:8081/chemistry/atom' # Apache Chemistry
 #REPOSITORY_URL = 'http://cmis.dnsdojo.com:8080/p8cmis/resources/DaphneA/Service'
 #REPOSITORY_URL = 'http://cmis.dnsdojo.com:8080/p8cmis/'
-REPOSITORY_URL = 'http://localhost:8080/alfresco/s/api/cmis'  # Alfresco
+#REPOSITORY_URL = 'http://localhost:8080/alfresco/cmisatom'  # Alfresco >= 4.0
+#REPOSITORY_URL = 'http://localhost:8080/alfresco/s/api/cmis'  # Alfresco
 #REPOSITORY_URL = 'http://cmis.demo.nuxeo.org/nuxeo/atom/cmis' # Nuxeo demo
 #REPOSITORY_URL = 'http://localhost:8080/nuxeo/atom/cmis' # Nuxeo local
 #REPOSITORY_URL = 'http://localhost:8080/opencmis/atom'  # OpenCMIS from the OpenText guys



Mime
View raw message