Example #1
0
 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")
Example #2
0
 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")
Example #3
0
 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())
Example #4
0
 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
Example #5
0
 def test_delete_outside_context(self):
     with AtomicBlobs(self.db) as db:
         pass
     with self.assertRaises(InvalidContext):
         db.delete(StringIO(b"content"))
Example #6
0
 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)
Example #7
0
 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)
Example #8
0
 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")
Example #9
0
 def test_put_outside_context(self):
     with AtomicBlobs(self.db) as db:
         pass
     with self.assertRaises(InvalidContext):
         db.put(StringIO(b"content"), get_id())
Example #10
0
 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)
Example #11
0
 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())
Example #12
0
 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)
Example #13
0
 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")
Example #14
0
 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)