def test_update(): coll_name = uuid.uuid4().hex coll = Collection.create('/', coll_name) myFactory = Faker() content = myFactory.text() chk = hashlib.sha224(content.encode()).hexdigest() metadata = {"test": "val", "test_json": '["t", "e", "s", "t"]'} # Simple update do = DataObject.create(content.encode()) resc_name = uuid.uuid4().hex resc = Resource.create(coll.path, resc_name, url="{}{}".format(cfg.protocol_cassandra, do.uuid)) resc.update(mimetype="text/plain") resc = Resource.find(resc.path) assert resc.get_mimetype() == "text/plain" resc.delete() # update with metadata and a username for notification do = DataObject.create(content.encode()) resc_name = uuid.uuid4().hex resc = Resource.create(coll.path, resc_name, url="{}{}".format(cfg.protocol_cassandra, do.uuid)) resc.update(username="******", metadata=metadata) resc = Resource.find(resc.path) assert resc.get_cdmi_user_meta()['test'] == metadata['test'] resc.delete() # Update with a change of url (new dataObject) do = DataObject.create(content.encode()) resc_name = uuid.uuid4().hex resc = Resource.create(coll.path, resc_name, url="{}{}".format(cfg.protocol_cassandra, do.uuid)) DataObject.delete_id(do.uuid) do = DataObject.create(content.encode()) resc.update(object_url="{}{}".format(cfg.protocol_cassandra, do.uuid)) resc = Resource.find(resc.path) assert resc.get_size() == len(content) resc.delete() # Update for a reference resc = Resource.create(coll.path, resc_name, url="http://www.google.fr") resc.update(mimetype="text/plain") resc = Resource.find(resc.path) # Mimetype stored in the tree entry assert resc.get_mimetype() == "text/plain" resc.delete() coll.delete()
def test_append(): do = DataObject.create(TEST_CONTENT1) DataObject.append_chunk(do.uuid, 1, TEST_CONTENT2) DataObject.append_chunk(do.uuid, 2, TEST_CONTENT3) DataObject.append_chunk(do.uuid, 3, TEST_CONTENT4) do = DataObject.find(do.uuid) data = [] for chk in do.chunk_content(): data.append(chk) assert b"".join(data) == b'This is a test.' DataObject.delete_id(do.uuid) do = DataObject.create(TEST_CONTENT1, compressed=True) DataObject.append_chunk(do.uuid, 1, TEST_CONTENT2, True) DataObject.append_chunk(do.uuid, 2, TEST_CONTENT3, True) DataObject.append_chunk(do.uuid, 3, TEST_CONTENT4, True) do = DataObject.find(do.uuid) data = [] for chk in do.chunk_content(): data.append(chk) assert b"".join(data) == b'This is a test.' DataObject.delete_id(do.uuid)
def test_delete_id(): do = DataObject.create(TEST_CONTENT) DataObject.delete_id(do.uuid) do = DataObject.find(do.uuid) assert do == None
def delete_data_objects(self): """ Delete all blobs of the corresponding uuid """ DataObject.delete_id(self.obj_id)