chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpo...@apache.org
Subject svn commit: r1500208 - in /chemistry/cmislib/trunk/src: cmislib/browser_binding.py cmislib/cmis_services.py tests/cmislibtest.py tests/settings.py
Date Sat, 06 Jul 2013 05:54:03 GMT
Author: jpotts
Date: Sat Jul  6 05:54:03 2013
New Revision: 1500208

URL: http://svn.apache.org/r1500208
Log:
Added selectable binding to cmislib unit tests. Implemented createFolder for the browser binding.

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

Modified: chemistry/cmislib/trunk/src/cmislib/browser_binding.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/trunk/src/cmislib/browser_binding.py?rev=1500208&r1=1500207&r2=1500208&view=diff
==============================================================================
--- chemistry/cmislib/trunk/src/cmislib/browser_binding.py (original)
+++ chemistry/cmislib/trunk/src/cmislib/browser_binding.py Sat Jul  6 05:54:03 2013
@@ -29,6 +29,7 @@ from util import parsePropValueByType, p
 import json
 import StringIO
 import logging
+from urllib import urlencode
 
 CMIS_FORM_TYPE = 'application/x-www-form-urlencoded;charset=utf-8'
 
@@ -69,7 +70,7 @@ class BrowserBinding(Binding):
             result = json.loads(content)
         return result
 
-    def post(self, url, username, password, payload, contentType, **kwargs):
+    def post(self, url, payload, contentType, username, password, **kwargs):
 
         """
         Does a post against the CMIS service. More than likely, you will not
@@ -91,7 +92,7 @@ class BrowserBinding(Binding):
                              username=username,
                              password=password,
                              **kwargs)
-        if resp['status'] != '200':
+        if resp['status'] != '200' and resp['status'] != '201':
             self._processCommonErrors(resp, url)
         else:
             result = json.loads(content)
@@ -1155,7 +1156,8 @@ class BrowserRepository(object):
     def createFolder(self,
                      parentFolder,
                      name,
-                     properties={}):
+                     properties={},
+                     **kwargs):
 
         """
         Creates a new :class:`Folder` object in the specified parentFolder.
@@ -1173,7 +1175,7 @@ class BrowserRepository(object):
          - removeACEs
         """
 
-        pass
+        return parentFolder.createFolder(name, properties, **kwargs)
 
     def createRelationship(self, sourceObj, targetObj, relType):
         """
@@ -1685,7 +1687,7 @@ class BrowserFolder(BrowserCmisObject):
     A container object that can hold other :class:`CmisObject` objects
     """
 
-    def createFolder(self, name, properties={}):
+    def createFolder(self, name, properties={}, **kwargs):
 
         """
         Creates a new :class:`Folder` using the properties provided.
@@ -1709,7 +1711,36 @@ class BrowserFolder(BrowserCmisObject):
          - removeACEs
         """
 
-        pass
+        # get the root folder URL
+        createFolderUrl = self._repository.getRootFolderUrl()
+
+        props = {"objectId" : self.id,
+                 "cmisaction" : "createFolder",
+                 "propertyId[0]" : "cmis:name",
+                 "propertyValue[0]" : name}
+
+        props["propertyId[1]"] = "cmis:objectTypeId"
+        if properties.has_key('cmis:objectTypeId'):
+            props["propertyValue[1]"] = properties['cmis:objectTypeId']
+        else:
+            props["propertyValue[1]"] = "cmis:folder"
+
+        propCount = 2
+        for prop in properties:
+            props["propertyId[%s]" % propCount] = prop.key
+            props["propertyValue[%s]" % propCount] = prop
+            propCount += 1
+
+        # invoke the URL
+        result = self._cmisClient.binding.post(createFolderUrl.encode('utf-8'),
+                                               urlencode(props),
+                                               'application/x-www-form-urlencoded',
+                                               self._cmisClient.username,
+                                               self._cmisClient.password,
+                                               **kwargs)
+
+        # return the result set
+        return BrowserFolder(self._cmisClient, self._repository, data=result)
 
     def createDocumentFromString(self,
                                  name,

Modified: chemistry/cmislib/trunk/src/cmislib/cmis_services.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/trunk/src/cmislib/cmis_services.py?rev=1500208&r1=1500207&r2=1500208&view=diff
==============================================================================
--- chemistry/cmislib/trunk/src/cmislib/cmis_services.py (original)
+++ chemistry/cmislib/trunk/src/cmislib/cmis_services.py Sat Jul  6 05:54:03 2013
@@ -50,6 +50,8 @@ class Binding(object):
             raise UpdateConflictException(error['status'], url)
         elif error['status'] == '500':
             raise RuntimeException(error['status'], url)
+        else:
+            raise CmisException(error['status'], url)
 
 
 class RepositoryServiceIfc(object):

Modified: chemistry/cmislib/trunk/src/tests/cmislibtest.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/trunk/src/tests/cmislibtest.py?rev=1500208&r1=1500207&r2=1500208&view=diff
==============================================================================
--- chemistry/cmislib/trunk/src/tests/cmislibtest.py (original)
+++ chemistry/cmislib/trunk/src/tests/cmislibtest.py Sat Jul  6 05:54:03 2013
@@ -52,7 +52,9 @@ class CmisTestBase(unittest.TestCase):
 
     def setUp(self):
         """ Create a root test folder for the test. """
-        self._cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
**settings.EXT_ARGS)
+        self._cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
+                                      binding=settings.BINDING,
+                                      **settings.EXT_ARGS)
         self._repo = self._cmisClient.getDefaultRepository()
         self._rootFolder = self._repo.getObjectByPath(settings.TEST_ROOT_PATH)
         self._folderName = " ".join(['cmislib', self.__class__.__name__, str(time())])
@@ -72,14 +74,18 @@ class CmisClientTest(unittest.TestCase):
 
     def testCmisClient(self):
         """Instantiate a CmisClient object"""
-        cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
**settings.EXT_ARGS)
+        cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
+                                binding=settings.BINDING,
+                                **settings.EXT_ARGS)
         self.assert_(cmisClient is not None)
 
     def testGetRepositories(self):
         """Call getRepositories and make sure at least one comes back with
         an ID and a name
         """
-        cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
**settings.EXT_ARGS)
+        cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
+                                binding=settings.BINDING,
+                                **settings.EXT_ARGS)
         repoInfo = cmisClient.getRepositories()
         self.assert_(len(repoInfo) >= 1)
         self.assert_('repositoryId' in repoInfo[0])
@@ -87,14 +93,18 @@ class CmisClientTest(unittest.TestCase):
 
     def testDefaultRepository(self):
         """Get the default repository by calling the repo's service URL"""
-        cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
**settings.EXT_ARGS)
+        cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
+                                binding=settings.BINDING,
+                                **settings.EXT_ARGS)
         repo = cmisClient.getDefaultRepository()
         self.assert_(repo is not None)
         self.assert_(repo.getRepositoryId() is not None)
 
     def testGetRepository(self):
         """Get a repository by repository ID"""
-        cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
**settings.EXT_ARGS)
+        cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
+                                binding=settings.BINDING,
+                                **settings.EXT_ARGS)
         repo = cmisClient.getDefaultRepository()
         defaultRepoId = repo.getRepositoryId()
         defaultRepoName = repo.getRepositoryName()
@@ -105,12 +115,16 @@ class CmisClientTest(unittest.TestCase):
     # Error conditions
     def testCmisClientBadUrl(self):
         """Try to instantiate a CmisClient object with a known bad URL"""
-        cmisClient = CmisClient(settings.REPOSITORY_URL + 'foobar', settings.USERNAME, settings.PASSWORD,
**settings.EXT_ARGS)
+        cmisClient = CmisClient(settings.REPOSITORY_URL + 'foobar', settings.USERNAME, settings.PASSWORD,
+                                binding=settings.BINDING,
+                                **settings.EXT_ARGS)
         self.assertRaises(CmisException, cmisClient.getRepositories)
 
     def testGetRepositoryBadId(self):
         """Try to get a repository with a bad repo ID"""
-        cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
**settings.EXT_ARGS)
+        cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
+                                binding=settings.BINDING,
+                                **settings.EXT_ARGS)
         self.assertRaises(ObjectNotFoundException,
                           cmisClient.getRepository,
                           '123FOO')
@@ -1311,7 +1325,9 @@ class TypeTest(unittest.TestCase):
     def testTypeDescendants(self):
         """Get the descendant types of the repository."""
 
-        cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
**settings.EXT_ARGS)
+        cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
+                                binding=settings.BINDING,
+                                **settings.EXT_ARGS)
         repo = cmisClient.getDefaultRepository()
         typeDefs = repo.getTypeDescendants()
         folderDef = None
@@ -1329,7 +1345,9 @@ class TypeTest(unittest.TestCase):
         #This test would be more interesting if there was a standard way to
         #deploy a custom model. Then we could look for custom types.
 
-        cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
**settings.EXT_ARGS)
+        cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
+                                binding=settings.BINDING,
+                                **settings.EXT_ARGS)
         repo = cmisClient.getDefaultRepository()
         typeDefs = repo.getTypeChildren()
         folderDef = None
@@ -1342,7 +1360,9 @@ class TypeTest(unittest.TestCase):
 
     def testTypeDefinition(self):
         """Get the cmis:document type and test a few props of the type."""
-        cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
**settings.EXT_ARGS)
+        cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
+                                binding=settings.BINDING,
+                                **settings.EXT_ARGS)
         repo = cmisClient.getDefaultRepository()
         docTypeDef = repo.getTypeDefinition('cmis:document')
         self.assertEquals('cmis:document', docTypeDef.getTypeId())
@@ -1350,7 +1370,9 @@ class TypeTest(unittest.TestCase):
 
     def testTypeProperties(self):
         """Get the properties for a type."""
-        cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
**settings.EXT_ARGS)
+        cmisClient = CmisClient(settings.REPOSITORY_URL, settings.USERNAME, settings.PASSWORD,
+                                binding=settings.BINDING,
+                                **settings.EXT_ARGS)
         repo = cmisClient.getDefaultRepository()
         docTypeDef = repo.getTypeDefinition('cmis:document')
         self.assertEquals('cmis:document', docTypeDef.getTypeId())

Modified: chemistry/cmislib/trunk/src/tests/settings.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/trunk/src/tests/settings.py?rev=1500208&r1=1500207&r2=1500208&view=diff
==============================================================================
--- chemistry/cmislib/trunk/src/tests/settings.py (original)
+++ chemistry/cmislib/trunk/src/tests/settings.py Sat Jul  6 05:54:03 2013
@@ -16,18 +16,25 @@
 #      specific language governing permissions and limitations
 #      under the License.
 #
+from cmislib.atompub_binding import AtomPubBinding
+from cmislib.browser_binding import BrowserBinding
 
 #
 # Override these settings with values to match your environment.
 #
 # CMIS repository's service URL
 #REPOSITORY_URL = 'http://cmis.alfresco.com/s/cmis' # Alfresco demo
-REPOSITORY_URL = 'http://localhost:8080/chemistry/atom' # Apache Chemistry
-#REPOSITORY_URL = 'http://localhost:8080/alfresco/cmisatom'  # Alfresco 4.0
+#REPOSITORY_URL = 'http://localhost:8080/chemistry/atom' # Apache Chemistry AtomPub
+REPOSITORY_URL = 'http://localhost:8080/chemistry/browser' # Apache Chemistry Browser
+#REPOSITORY_URL = 'http://localhost:8080/alfresco/cmisatom'  # Alfresco 4.0 AtomPub
 #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
 
+# Choose a binding. The AtomPubBinding is the only one you should really be using right now
+#BINDING = AtomPubBinding()
+BINDING = BrowserBinding()
+
 # CMIS repository credentials
 USERNAME = 'admin'  # Alfresco
 PASSWORD = 'admin'  # Alfresco
@@ -49,6 +56,7 @@ TEST_BINARY_2 = 'sample-a.pdf'
 # principal ID to add to the ACL of a test object. Some repositories care
 # if this ID doesn't exist. Some repositories don't.
 TEST_PRINCIPAL_ID = 'anyone'
+#TEST_PRINCIPAL_ID = 'admin'
 # For repositories that may index test content asynchronously, the number of
 # times a query is retried before giving up.
 MAX_FULL_TEXT_TRIES = 10
@@ -56,5 +64,6 @@ MAX_FULL_TEXT_TRIES = 10
 FULL_TEXT_WAIT = 10
 # Specify the type ID of a versionable type. If all types are versionable,
 # specify cmis:document
-VERSIONABLE_TYPE_ID = 'cmis:document'
-#VERSIONABLE_TYPE_ID = 'VersionableType'
+#VERSIONABLE_TYPE_ID = 'cmis:document'
+#VERSIONABLE_TYPE_ID = 'cmisbook:pdf'
+VERSIONABLE_TYPE_ID = 'VersionableType'



Mime
View raw message