def test_delete_failed(self): info = self.db.put(StringIO(b"content")) with self.assertRaises(Boom), AtomicBlobs(self.db) as db: db.delete(info.identifier) raise Boom() with self.db.get(info.identifier) as fh: self.assertEqual(fh.read(), b"content")
def test_delete_failed(self): meta = self.db.put(BytesIO(b"content"), meta=new_meta()) with self.assertRaises(Boom), AtomicBlobs(self.db) as db: db.delete(key=meta.key) raise Boom() with self.db.get(meta=meta) as fh: self.assertEqual(fh.read(), b"content")
def test_expire(self): meta = self.db.put(BytesIO(b"content"), meta=new_meta()) self.assertIsNone(meta.expires_on) with AtomicBlobs(self.db) as db: db.expire(meta.parent_id, key=meta.key) meta = db.metadb.get(parent_id=meta.parent_id, key=meta.key) self.assertGreater(meta.expires_on, datetime.utcnow())
def create(cls, user_id, restore_content, comment=""): """ The method to create a new DemoUserRestore object ags: user_id: the id of the CommCareUser restore_content: a string or file-like object of user's restore XML """ restore = cls( demo_user_id=user_id, restore_comment=comment, ) with AtomicBlobs(get_blob_db()) as db: restore._write_restore_blob(restore_content, db) restore.save() return restore
def test_delete_outside_context(self): with AtomicBlobs(self.db) as db: pass with self.assertRaises(InvalidContext): db.delete(StringIO(b"content"))
def test_delete(self): info = self.db.put(StringIO(b"content")) with AtomicBlobs(self.db) as db: db.delete(info.identifier) with self.assertRaises(NotFound): self.db.get(info.identifier)
def test_put_failed(self): with self.assertRaises(Boom), AtomicBlobs(self.db) as db: info = db.put(StringIO(b"content")) raise Boom() with self.assertRaises(NotFound): self.db.get(info.identifier)
def test_put(self): with AtomicBlobs(self.db) as db: info = db.put(StringIO(b"content")) with self.db.get(info.identifier) as fh: self.assertEqual(fh.read(), b"content")
def test_put_outside_context(self): with AtomicBlobs(self.db) as db: pass with self.assertRaises(InvalidContext): db.put(StringIO(b"content"), get_id())
def test_delete(self): meta = self.db.put(BytesIO(b"content"), meta=new_meta()) with AtomicBlobs(self.db) as db: db.delete(key=meta.key) with self.assertRaises(NotFound): self.db.get(meta=meta)
def test_put_outside_context(self): with AtomicBlobs(self.db) as db: pass with self.assertRaises(InvalidContext): db.put(BytesIO(b"content"), meta=new_meta())
def test_put_failed(self): with self.assertRaises(Boom), AtomicBlobs(self.db) as db: meta = db.put(BytesIO(b"content"), meta=new_meta()) raise Boom() with self.assertRaises(NotFound): self.db.get(meta=meta)
def test_put(self): with AtomicBlobs(self.db) as db: meta = db.put(BytesIO(b"content"), meta=new_meta()) with self.db.get(meta=meta) as fh: self.assertEqual(fh.read(), b"content")
def atomic_attachments(): unsaved = self.attachments_list assert all(isinstance(a, Attachment) for a in unsaved), unsaved with AtomicBlobs(get_blob_db()) as blob_db: yield Writer(self, blob_db)