예제 #1
0
    def testRetrieve(self):
        # Success
        expectedResult = self._initValidRetrieveResult()
        connectionMock = SimpleMock(methodNameResultMap=\
            {"getProperty": ('{"name": "me"}', None),
            "info": ({"lastChangedDate": "", "owner": "", "size": "10", "creationDate": ""}, None)})
        defaultAdapter = adapter.MetadataSubversionAdapter(
            "identifier", SimpleMock(connectionMock))
        self.assertEquals(defaultAdapter.retrieve(),
                          expectedResult)  # Filter nothing
        self.assertEquals(defaultAdapter.retrieve(list()),
                          expectedResult)  # Filter nothing
        self.assertEquals(defaultAdapter.retrieve([const.SIZE]),
                          {const.SIZE: MetadataValue("10")})  # Filter size

        # Error access system properties
        connectionMock.methodNameResultMap = {
            "info": (None, SubversionError(""))
        }
        self.assertRaises(PersistenceError, defaultAdapter.retrieve)

        # Error accessing custom properties
        connectionMock.methodNameResultMap = {
            "getProperty": (None, SubversionError(""))
        }
        self.assertRaises(PersistenceError, defaultAdapter.retrieve)
예제 #2
0
    def testCreateCollection(self):
        # Success
        self._adapter.createCollection()
        self._osPathMock.value = True
        self._adapter.createCollection(True)
        # Local not versioned file exists but gets removed
        self._osPathMock.methodNameResultMap = {
            "exists": (True, None),
            "isdir": (False, None)
        }
        self._adapter.createCollection()

        # Error
        # Problem to commit directory
        self._connectionMock.error = SubversionError("")
        self.assertRaises(PersistenceError, self._adapter.createCollection)

        # Problem creating local directory
        self._connectionMock.error = None
        self._osModuleMock.error = OSError("")
        self.assertRaises(PersistenceError, self._adapter.createCollection)

        # Local directory cannot be removed
        self._osPathMock.methodNameResultMap = {
            "exists": (True, None),
            "isdir": (False, None)
        }
        self.assertRaises(PersistenceError, self._adapter.createCollection)
예제 #3
0
    def getChildren(self, path):
        """ Determines the direct children of the given directory. In prior an
        update is performed. The retrieved information are cached. This method 
        is synchronized among different connections. """

        self._sharedState.lock.acquire()
        try:
            try:
                self.update(path)
                children = list()
                entries = self._client.list(self._workingCopyPath + path,
                                            recurse=False)
                for entry in entries:
                    entryPath = entry[0].path[self._workingPathLength:]
                    formerEntry = self._sharedState.getFromCache(path)
                    if formerEntry is None:
                        newEntry = _Info(entry[0])
                    else:
                        newEntry = _Info(entry[0])
                        newEntry.logMessage = formerEntry.logMessage  # creation date and owner do not change
                    self._sharedState.addToCache(entryPath, newEntry)
                    children.append(entryPath)
                del children[0]  # First item is always the queried path
                return children
            except ClientError, error:
                raise SubversionError(error)
        finally:
            self._sharedState.lock.release()
예제 #4
0
    def getProperty(self, path, name):
        """
        Gets the property value of a file or directory.
        
        @param name: Name of the property.
        @type name: C{unicode}
        
        @rtype: C{unicode}
        """
        # pylint: disable=E1101
        # E1101: pylint could not resolve the Revision attribute.

        result = None
        fullWorkingPath = (self._workingCopyPath + path).encode(constants.UTF8)

        try:
            propertyValues = self._client.propget(
                name,
                fullWorkingPath,
                revision=pysvn.Revision(pysvn.opt_revision_kind.working),
                depth=pysvn.depth.empty)
            if fullWorkingPath in propertyValues:
                result = unicode(propertyValues[fullWorkingPath],
                                 constants.UTF8)
        except ClientError, error:
            raise SubversionError(error)
예제 #5
0
    def testDelete(self):
        # Success
        self._adapter.delete()

        # Error
        self._connectionMock.error = SubversionError("")
        self.assertRaises(PersistenceError, self._adapter.delete)
예제 #6
0
    def add(self, path):
        """ Adds a new file/directory to the working copy. """

        try:
            self._client.add(self._workingCopyPath + path, recurse=True)
        except ClientError, error:
            raise SubversionError(error)
예제 #7
0
    def testCreateResource(self):
        # Success
        self._adapter.createResource()
        # Local not versioned directory exists but gets removed
        self._osPathMock.methodNameResultMap = {
            "exists": (True, None),
            "isdir": (True, None)
        }
        self._adapter.createResource()

        # Error
        # Problem to commit resource
        self._connectionMock.error = SubversionError("")
        self.assertRaises(PersistenceError, self._adapter.createResource)

        # Local file cannot be created
        self._connectionMock.error = None
        self._openMock.error = True
        self.assertRaises(PersistenceError, self._adapter.createResource)

        # Local directory cannot be removed
        self._osPathMock.methodNameResultMap = {
            "exists": (True, None),
            "isdir": (True, None)
        }
        self._shutilMock.error = OSError("")
        self.assertRaises(PersistenceError, self._adapter.createResource)
예제 #8
0
    def copy(self, path, destinationPath):
        """ The copying process is directly performed on the SVN server. """

        try:
            self._client.copy(self._getEncodedUri(path),
                              self._getEncodedUri(destinationPath))
        except ClientError, error:
            raise SubversionError(error)
예제 #9
0
    def update(self, path):
        """ Updates the working copy. """

        try:
            self._svnUpdateClient.doUpdate(self._repoWorkingCopyFile + path,
                                           SVNRevision.HEAD, True)
        except SVNException, error:
            raise SubversionError(error)
예제 #10
0
    def testGetChildren(self):
        # Success
        self._connectionMock.value = ["/trunk/test/test.txt"]
        self.assertEquals(self._adapter.getChildren(),
                          ["/trunk/test/test.txt"])

        # Error
        self._connectionMock.error = SubversionError("")
        self.assertRaises(PersistenceError, self._adapter.getChildren)
예제 #11
0
    def testCopy(self):
        destination = SimpleMock(identifier="/")

        # Success
        self._adapter.copy(destination)

        # Error
        self._connectionMock.error = SubversionError("")
        self.assertRaises(PersistenceError, self._adapter.copy, destination)
예제 #12
0
    def testReadData(self):
        # Success
        self._adapter.readData()

        # Error
        self._openMock.error = True
        self.assertRaises(PersistenceError, self._adapter.readData)
        self._connectionMock.error = SubversionError("")
        self.assertRaises(PersistenceError, self._adapter.readData)
예제 #13
0
    def checkin(self, path):
        """ Commits changes of the item identified with C{path}. It also
        ensures that existing conflicts are resolved.
        """

        try:
            self._client.checkin(self._workingCopyPath + path, "")
        except ClientError, error:
            raise SubversionError(error)
예제 #14
0
    def testCreateLink(self):
        # Success
        self._adapter.createLink(SimpleMock(identifier="/destPath"))

        # Error
        self._connectionMock.methodNameResultMap = \
            {"setProperty": (None, SubversionError(""))}
        self.assertRaises(PersistenceError, self._adapter.createLink,
                          SimpleMock(identifier="/destPath"))
예제 #15
0
    def delete(self, path):
        """ Removes a file or directory from the repository. It works
        directly on the server, i.e. no call to C{checkin} is required.
        The cached information of the item all removed as well.
        """

        try:
            self._client.remove(self._getEncodedUri(path), force=True)
        except ClientError, error:
            raise SubversionError(error)
예제 #16
0
    def testWriteData(self):
        # Success
        self._adapter.writeData(io.StringIO(u"test"))

        # Error
        self._openMock.error = True
        self.assertRaises(PersistenceError, self._adapter.writeData,
                          io.StringIO(u""))
        self._connectionMock.error = SubversionError("")
        self.assertRaises(PersistenceError, self._adapter.writeData,
                          io.StringIO(u""))
예제 #17
0
    def delete(self, path):
        """
        Removes a file or directory from the working copy.
        
        @param path: Path to remove.
        @type path: C{unicode}
        """

        try:
            self._svnWorkingCopyClient.doDelete(File(path), True, False)
        except SVNException, error:
            raise SubversionError(error)
예제 #18
0
    def testLinkTarget(self):
        # Is a link
        self._connectionMock.methodNameResultMap = \
            {"getProperty": ("/thelinkTargetPath", None)}
        self.assertEquals(self._adapter.linkTarget, "/thelinkTargetPath")
        self.assertTrue(self._adapter.isLink)

        # No link
        self._connectionMock.methodNameResultMap = None
        self._connectionMock.error = SubversionError("")
        self.assertEquals(self._adapter.linkTarget, None)
        self.assertFalse(self._adapter.isLink)
예제 #19
0
    def checkin(self, _):
        """ 
        Checkins to the repository.
        
        @param path: Path to checkin.
        @type path: C{unicode} 
        """

        try:
            self._svnCommitClient.doCommit([self._repoWorkingCopyFile], False,
                                           "", False, True)
        except SVNException, error:
            raise SubversionError(error)
예제 #20
0
    def getChildren(self, path):
        """ @see L{NullDataStorer<datafinder.persistence.data.datastorer.NullDataStorer>} """

        try:
            result = list()
            entryList = self._repository.getDir(path[1:], -1, None, None)
            for entry in entryList:
                entryPath = entry.getURL().toString()
                entryPath = entryPath.replace(self._repoPath, "")
                result.append(entryPath)
            return result
        except SVNException, error:
            raise SubversionError(error)
예제 #21
0
    def _determineInfo(self, path):
        """ Retrieves the entry information and puts it into the 
        cache or uses the cached information. """

        entry = self._sharedState.getFromCache(path)
        if entry is None:
            try:
                entry = self._client.list(self._workingCopyPath + path,
                                          recurse=False)[0][0]
                entry = _Info(entry)
                self._sharedState.addToCache(path, entry)
                return entry
            except ClientError, error:
                raise SubversionError(error)
예제 #22
0
    def add(self, _):
        """ 
        Marks changes in the working copy for checking in. 
        
        @param path: Path to add.
        @type path: C{unicode}
        """

        try:
            self._svnWorkingCopyClient.doAdd(self._repoWorkingCopyFile, True,
                                             False, False, SVNDepth.INFINITY,
                                             False, False, False)
        except SVNException, error:
            raise SubversionError(error)
예제 #23
0
    def setProperty(self, path, key, value):
        """
        Sets the property of a file or directory.
        
        @param key: Name of the property.
        @type key: C{unicode}
        @param value: Value of the property.
        @type value: C{unicode}
        """

        try:
            self._client.propset(key, value, self._workingCopyPath + path)
            self.checkin(path)
        except ClientError, error:
            raise SubversionError(error)
예제 #24
0
    def testIsLeaf(self):
        # Success
        self._connectionMock.value = True
        self.assertTrue(self._adapter.isLeaf)

        self._connectionMock.value = False
        self.assertFalse(self._adapter.isLeaf)

        # Error
        self._connectionMock.error = SubversionError("")
        try:
            isLeaf = self._adapter.isLeaf
            self.fail("No PersistenceError. Get '%s' instead." % str(isLeaf))
        except PersistenceError:
            self.assertTrue(True)
예제 #25
0
    def copy(self, path, destinationPath):
        """
        Copies a file or directory within the working copy.
        
        @param path: Path to copy.
        @type path: C{unicode}
        @param destinationPath: Path to the destination.
        @type destinationPath: C{unicode}
        """

        try:
            self._svnCopyClient.doCopy([SVNCopySource(SVNRevision.HEAD, SVNRevision.HEAD, File(path))], \
                                       File(destinationPath), False, True, True)
        except SVNException, error:
            raise SubversionError(error)
예제 #26
0
    def getProperty(self, path, key):
        """
        Gets the property of a file or directory.
        
        @param path: Path where the property should be retrieved.
        @type path: C{unicode}
        @param key: Name of the property.
        @type key: C{unicode}
        """

        try:
            propertyData = self._svnWorkingCopyClient.doGetProperty(
                File(path), key, SVNRevision.HEAD, SVNRevision.HEAD)
            return propertyData.getValue().getString()
        except SVNException, error:
            raise SubversionError(error)
예제 #27
0
    def setProperty(self, path, key, value):
        """
        Sets the property of a file or directory.
        
        @param path: Path where the property should be set.
        @type path: C{unicode}
        @param key: Name of the property.
        @type key: C{unicode}
        @param value: Value of the property.
        @type value: C{unicode}
        """

        try:
            self._svnWorkingCopyClient.doSetProperty(File(path), key, SVNPropertyValue.create(value), False, \
                                                     SVNDepth.EMPTY, ISVNPropertyHandler, None)
        except SVNException, error:
            raise SubversionError(error)
예제 #28
0
    def _determineItemKind(self, path, kind):
        """
        Determines the item type.
        
        @param path: Path to determine.
        @type path: C{unicode}
        @param kind: Kind that should be determined. 
        """

        try:
            nodeKind = self._repository.checkPath(path[1:], -1)
            if nodeKind == kind:
                return True
            else:
                return False
        except SVNException, error:
            raise SubversionError(error)
예제 #29
0
    def testIsCollection(self):
        # Success
        self._connectionMock.value = True
        self.assertTrue(self._adapter.isCollection)
        self.assertTrue(self._adapter.canAddChildren)

        self._connectionMock.value = False
        self.assertFalse(self._adapter.isCollection)
        self.assertFalse(self._adapter.canAddChildren)

        # Error
        self._connectionMock.error = SubversionError("")
        try:
            isCollection = self._adapter.isCollection
            self.fail("No PersistenceError. Get '%s' instead." %
                      str(isCollection))
        except PersistenceError:
            self.assertTrue(True)
예제 #30
0
    def info(self, _):
        """
        Gets the information about a file or directory.
        
        @param path: Path to the file or directory information is needed.
        @type path: C{unicode}
        """

        try:
            result = dict()
            self._svnUpdateClient.doUpdate(self._repoWorkingCopyFile,
                                           SVNRevision.HEAD, True)
            result["lastChangedDate"] = ""
            result["size"] = ""
            result["owner"] = ""
            result["creationDate"] = ""
            return result
        except SVNException, error:
            raise SubversionError(error)