Пример #1
0
    def test_DeleteUnreferencedAliases(self):
        self.ztm.begin()

        # Confirm that our sample files are there.
        f1 = LibraryFileAlias.get(self.f1_id)
        f2 = LibraryFileAlias.get(self.f2_id)
        # Grab the content IDs related to these
        # unreferenced LibraryFileAliases
        c1_id = f1.contentID
        c2_id = f2.contentID
        del f1, f2
        self.ztm.abort()

        # Delete unreferenced aliases
        librariangc.delete_unreferenced_aliases(self.con)

        # This should have committed
        self.ztm.begin()

        # Confirm that the LibaryFileContents are still there.
        LibraryFileContent.get(c1_id)
        LibraryFileContent.get(c2_id)

        # But the LibraryFileAliases should be gone
        self.assertRaises(SQLObjectNotFound, LibraryFileAlias.get, self.f1_id)
        self.assertRaises(SQLObjectNotFound, LibraryFileAlias.get, self.f2_id)
Пример #2
0
def fillLibrarianFile(fileid, content=None):
    """Write contents in disk for a librarian sampledata."""
    if content is None:
        content = 'x' * LibraryFileContent.get(fileid).filesize

    filepath = os.path.join(
        config.librarian_server.root, _relFileLocation(fileid))

    if not os.path.exists(os.path.dirname(filepath)):
        os.makedirs(os.path.dirname(filepath))

    with open(filepath, 'wb') as libfile:
        libfile.write(content)
Пример #3
0
    def test_hashes(self):
        # Check that the MD5, SHA1 and SHA256 hashes are correct.
        data = 'i am some data'
        md5 = hashlib.md5(data).hexdigest()
        sha1 = hashlib.sha1(data).hexdigest()
        sha256 = hashlib.sha256(data).hexdigest()

        newfile = self.storage.startAddFile('file', len(data))
        newfile.append(data)
        lfc_id, lfa_id = newfile.store()
        lfc = LibraryFileContent.get(lfc_id)
        self.assertEqual(md5, lfc.md5)
        self.assertEqual(sha1, lfc.sha1)
        self.assertEqual(sha256, lfc.sha256)
Пример #4
0
    def test_hashes(self):
        # Check that the MD5, SHA1 and SHA256 hashes are correct.
        data = 'i am some data'
        md5 = hashlib.md5(data).hexdigest()
        sha1 = hashlib.sha1(data).hexdigest()
        sha256 = hashlib.sha256(data).hexdigest()

        newfile = self.storage.startAddFile('file', len(data))
        newfile.append(data)
        lfc_id, lfa_id = newfile.store()
        lfc = LibraryFileContent.get(lfc_id)
        self.assertEqual(md5, lfc.md5)
        self.assertEqual(sha1, lfc.sha1)
        self.assertEqual(sha256, lfc.sha256)