def test_insert(dataspace): # noqa: F811 """Can we insert new elements""" primary_key = dataspace.store_taskmanager( "taskmanager3", "33333333-3333-3333-3333-333333333333" ) assert primary_key > 1 header = Header(primary_key) metadata = Metadata(primary_key) dataspace.insert( primary_key, 1, "sample_test_key", "sample_test_value".encode(), header, metadata, ) result1 = dataspace.get_dataproducts(taskmanager_id=primary_key) assert result1 == [ { "key": "sample_test_key", "taskmanager_id": primary_key, "generation_id": 1, "value": b"sample_test_value", } ] result2 = dataspace.get_dataproducts( taskmanager_id=primary_key, key="sample_test_key" ) assert result1 == result2
def test_get_dataproducts(dataspace): # noqa: F811 """Can we get the dataproducts by uuid and uuid with key""" result1 = dataspace.get_dataproducts(taskmanager_id=1) assert len(result1) == 2 assert result1[0] == { "taskmanager_id": 1, "generation_id": 1, "key": "my_test_key", "value": b"my_test_value", } assert result1[1] == { "taskmanager_id": 1, "generation_id": 1, "key": "a_test_key", "value": b"a_test_value", } result2 = dataspace.get_dataproducts(taskmanager_id="2", key="other_test_key") assert result2 == [ { "taskmanager_id": 2, "generation_id": 2, "key": "other_test_key", "value": b"other_test_value", }, ]
def test_get_dataproducts_not_exist(dataspace): # noqa: F811 """Does it error out if we ask for bogus information?""" result = dataspace.get_dataproducts(taskmanager_id=100) assert result == [] result = dataspace.get_dataproducts(taskmanager_id=2, key="no_such_key") assert result == []
def test_DataBlock_to_str(dataspace): # noqa: F811 my_tm = dataspace.get_taskmanagers()[0] # fetch one of our loaded examples expected = { "taskmanager_id": my_tm["taskmanager_id"], "generation_id": dataspace.get_last_generation_id(my_tm["name"], my_tm["taskmanager_id"]), "sequence_id": len(dataspace.get_dataproducts(my_tm["sequence_id"])) + 1, "keys": [ "example_test_key", ], "dataproducts": { "example_test_key": "example_test_value" }, } header = datablock.Header(my_tm["taskmanager_id"]) dblock = datablock.DataBlock(dataspace, my_tm["name"], my_tm["taskmanager_id"]) dblock.put("example_test_key", "example_test_value", header) result = ast.literal_eval(str(dblock)) assert result == expected
def test_duplicate_datablock(dataspace): # noqa: F811 """Can we duplicate taskmanager1 and all its entries""" result1 = dataspace.get_last_generation_id( taskmanager_name="taskmanager1", taskmanager_id="11111111-1111-1111-1111-111111111111", ) assert result1 == 1 result1 = dataspace.get_dataproducts(taskmanager_id=1, ) assert len(result1) == 2 dataspace.duplicate_datablock(1, 1, 90) result1 = dataspace.get_last_generation_id( taskmanager_name="taskmanager1", taskmanager_id="11111111-1111-1111-1111-111111111111", ) assert result1 == 90