def test_dmf_update(): tmp_dir = Path(scratch_dir) / "dmf_update" dmf = DMF(path=tmp_dir, create=True) ids = add_resources(dmf, 2) r1 = dmf.fetch_one(ids[0]) r1.v[r1.TYPE_FIELD] = "test" r1.v["desc"] = "Updated description" dmf.update(r1) r1b = dmf.fetch_one(ids[0]) assert r1b.v["desc"] == "Updated description" r2 = dmf.fetch_one(ids[1]) assert r2.v["desc"] != "Updated description"
def test_dmf_find(): tmp_dir = Path(scratch_dir) / "dmf_find" dmf = DMF(path=tmp_dir, create=True) # populate with batches of records # they all have the tag 'all', each batch has 'batch<N>' as well # All resources in a batch are given version 1.0.<N> # Individual resources will have data of {i: 0..<batchsz-1>} batchsz, numbatches = 10, 9 all_ids = [] for i in range(numbatches): n = batchsz batch = "batch{:d}".format(i + 1) version = resource.version_list([1, 0, i + 1]) ids = add_resources(dmf, num=n, tags=["all", batch], version_info={"version": version}) all_ids.extend(ids) if _log.isEnabledFor(logging.DEBUG): r = dmf.fetch_one(all_ids[0]) _log.debug("First resource:\n{}".format(r)) # Find all records, 2 ways total_num = batchsz * numbatches result = list(dmf.find()) assert len(result) == total_num result = list(dmf.find({"tags": ["all"]})) assert len(result) == total_num # Find with 'all' result = list(dmf.find({"tags!": ["all", "batch1"]})) assert len(result) == batchsz
def test_dmf_update_newtype(): tmp_dir = Path(scratch_dir) / "dmf_update_newtype" dmf = DMF(path=tmp_dir, create=True) ids = add_resources(dmf, 1) r1 = dmf.fetch_one(ids[0]) r1.v[r1.TYPE_FIELD] = "this type is different" try: dmf.update(r1) except errors.DMFError: pass else: assert False, "DMFError expected for update() with new type"