def test_sync_fetch_missing(self): manager = BlobManager(self.tempdir, self.uri, self.secret, self.secret, uuid4().hex) self.addCleanup(manager.close) blob_id = 'remote_only_blob_id' yield manager._encrypt_and_upload(blob_id, BytesIO("X")) yield manager.sync() result = yield manager.local.get(blob_id) self.assertIsNotNone(result) self.assertEquals(result.getvalue(), "X")
def test_refresh_deletions_from_server(self): manager = BlobManager(self.tempdir, self.uri, self.secret, self.secret, uuid4().hex) self.addCleanup(manager.close) blob_id, content = 'delete_me', 'content' blob_id2 = 'dont_delete_me' doc1 = BlobDoc(BytesIO(content), blob_id) doc2 = BlobDoc(BytesIO(content), blob_id2) yield manager.put(doc1, len(content)) yield manager.put(doc2, len(content)) yield manager._delete_from_remote(blob_id) # remote only deletion self.assertTrue((yield manager.local.exists(blob_id))) yield manager.sync() self.assertFalse((yield manager.local.exists(blob_id))) self.assertTrue((yield manager.local.exists(blob_id2)))
def test_download_corrupted_tag_marks_blob_as_failed(self): user_id = uuid4().hex manager = BlobManager(self.tempdir, self.uri, self.secret, self.secret, user_id) self.addCleanup(manager.close) blob_id = 'corrupted' yield manager._encrypt_and_upload(blob_id, BytesIO("corrupted")) parts = ['default'] + [blob_id[0], blob_id[0:3], blob_id[0:6]] parts += [blob_id] corrupted_blob_path = os.path.join(self.tempdir, user_id, *parts) with open(corrupted_blob_path, 'r+b') as corrupted_blob: # Corrupt the tag (last 16 bytes) corrupted_blob.seek(-16, 2) corrupted_blob.write('x' * 16) with pytest.raises(MaximumRetriesError): yield manager.sync() status, retries = yield manager.local.get_sync_status(blob_id) self.assertEquals(status, SyncStatus.FAILED_DOWNLOAD) self.assertEquals(retries, 3)