def test_write_content(self): content = open(os.path.join(curdir, 'sample.tar.gz')) locker.write_content(self.target, content) # make sure it does the job for real wanted = open(os.path.join(curdir, 'sample.tar.gz')).read() res = open(self.target).read() self.assertEquals(wanted, res)
def _write_file(file, path, index): if not hasattr(file, 'getDownloadableFile'): return # getting the file to push there file = file.getDownloadableFile() if file is None: return # let's get the data data = file.get_data() if data == '': return None if index == path: raise IOError('Cannot use the same name than the index file') # if the MD5 is equal, we don't do anything if os.path.exists(path): if file_hash(path, index) == string_hash(data): return try: write_content(path, data, index) except AlreadyLocked: raise ConflictError('%s is locked' % path)