def testDifferentSearchFallback(self): baseConf = SimpleMock() baseConf.uriScheme = _VALID_URI_SCHEME searchBaseConf = SimpleMock() searchBaseConf.uriScheme = "invalid_search_interface" fileSystem = FileSystem(baseConf, baseSearchConfiguration=searchBaseConf) self.assertEquals(len(fileSystem.search("*", "/")), 0)
def testDifferentSearch(self): baseConf = SimpleMock() baseConf.uriScheme = _VALID_URI_SCHEME searchBaseConf = SimpleMock() searchBaseConf.uriScheme = _VALID_SEARCH_SCHEME fileSystem = FileSystem(baseConf, baseSearchConfiguration=searchBaseConf) self.assertEquals(len(fileSystem.search("*", "/")), 2)
def testDifferentPrincipalSearchFallback(self): baseConf = SimpleMock() baseConf.uriScheme = _VALID_URI_SCHEME principalSearchBaseConf = SimpleMock() principalSearchBaseConf.uriScheme = "invalid_principal_scheme" fileSystem = FileSystem(baseConf, principalSearchBaseConf) self.assertEquals( len(fileSystem.searchPrincipal("pattern", "searchMode")), 0)
def testDifferentPrincipalSearch(self): baseConf = SimpleMock() baseConf.uriScheme = _VALID_URI_SCHEME principalSearchBaseConf = SimpleMock() principalSearchBaseConf.uriScheme = _VALID_PRINCIPAL_SEARCH_SCHEME fileSystem = FileSystem(baseConf, principalSearchBaseConf) self.assertEquals( len(fileSystem.searchPrincipal("pattern", "searchMode")), 2)
def _ensureReadableSystem(self): """ Make sure, self._archiveFileSystem contains a valid readable file system. If none is present, the corresponding ZIP file will be downloaded. """ if self._fileSystem is None: key = self._rootItem.path + str(self._index) if key in _temporaryFileMap: self._fileSystem = _temporaryFileMap[key][1] else: fd, path = mkstemp() fileHandle = os.fdopen(fd, "w+b") inStream = self._rootItem.dataPersister.retrieveData( self._index) try: block = inStream.read(_BLOCK_SIZE) while len(block) > 0: fileHandle.write(block) block = inStream.read(_BLOCK_SIZE) while len(block) > 0: fileHandle.write(block) block = inStream.read(_BLOCK_SIZE) fileHandle.close() except (OSError, IOError), error: reason = os.strerror(error.errno or 0) raise ItemError("Cannot retrieve archive.\nReason: '%s'" % reason) else: config = BaseConfiguration('arch:' + path) _log.debug("Downloaded %s to %s." % (self._rootItem.path, path)) self._fileSystem = FileSystem(config) _temporaryFileMap[key] = (path, self._fileSystem)
def setUp(self): """ Creates the object under test. """ self._nullFileSystem = FileSystem(None) self._dataStorer = NullDataStorer("/identifier") self._metadataStorer = NullMetadataStorer("/identifier") self._privilegeStorer = NullPrivilegeStorer("/identifier") self._fileStorer = filestorer.FileStorer(self._nullFileSystem, "/identifier", self._dataStorer, self._metadataStorer, self._privilegeStorer) self._destFileStorer = filestorer.FileStorer(self._nullFileSystem, "/identifier", self._dataStorer, self._metadataStorer, self._privilegeStorer)
def _createFileSystem(fileSystemConfiguration): return FileSystem(fileSystemConfiguration)
def testValidInterfaceType(self): baseConf = SimpleMock() baseConf.uriScheme = _VALID_URI_SCHEME fileSystem = FileSystem(baseConf) fileStorer = fileSystem.createFileStorer("identifier") self.assertFalse(fileStorer is None) self.assertFalse(fileStorer.dataStorer is None) self.assertFalse(fileStorer.metadataStorer is None) self.assertFalse(fileStorer.privilegeStorer is None) self.assertTrue(fileSystem.hasCustomMetadataSupport) self.assertTrue(fileSystem.hasMetadataSearchSupport) self.assertTrue(fileSystem.hasPrivilegeSupport) self.assertEquals(fileSystem.determineFreeDiskSpace(), 200) self.assertNotEquals(fileSystem.baseUri, None) self.assertNotEquals(fileSystem.baseConfiguration, None) self.assertEquals(fileSystem.isAccessible, True) self.assertEquals( len(fileSystem.searchPrincipal("pattern", "searchMode")), 0) fileSystem.updateCredentials(dict()) fileSystem.updatePrincipalSearchCredentials(dict()) fileSystem.release()
def testNullFactory(self): nullFileSystem = FileSystem() self.assertEquals( nullFileSystem.searchPrincipal("pattern", "searchMode"), list()) self.assertTrue( not nullFileSystem.createFileStorer("identifier") is None) self.assertFalse(nullFileSystem.hasCustomMetadataSupport) self.assertFalse(nullFileSystem.hasMetadataSearchSupport) self.assertFalse(nullFileSystem.hasPrivilegeSupport) self.assertTrue(nullFileSystem.determineFreeDiskSpace() > 1) self.assertEquals(nullFileSystem.baseUri, None) self.assertEquals(nullFileSystem.baseConfiguration, None) self.assertEquals(nullFileSystem.isAccessible, False) nullFileSystem.updateCredentials(dict()) nullFileSystem.updatePrincipalSearchCredentials(dict()) nullFileSystem.release()