def test_03_public(self): # Check we can instantiate and work with a PublicAPC # first make a blank one pub = PublicAPC() # now make one around the fixture source = PublicAPCFixtureFactory.example() pub = PublicAPC(source) # make one with a broken source broken = {"whatever" : "broken"} with self.assertRaises(dataobj.DataStructureException): pub = PublicAPC(broken) # now make one bit by bit pub = PublicAPC() pub.record = source.get("record") pub.set_apc_ref("test1", "1111111111") apc_refs = pub.get_apc_refs("test1") assert len(apc_refs) == 1 assert apc_refs[0] == "1111111111" # now make it broken pub = PublicAPC() with self.assertRaises(dataobj.DataStructureException): pub.record = {"random" : "stuff"}
def test_05_enhance_metadata(self): # Enhance the bibliographic metadata on a PublicAPC record merge_source = PublicAPCFixtureFactory.record_merge_source() merge_target = PublicAPCFixtureFactory.record_merge_target() result = PublicAPCFixtureFactory.record_merge_result() source = PublicAPC() source.record = merge_source source.set_apc_ref("22222", "bbbbb") target = PublicAPC() target.record = merge_target target.set_apc_ref("11111", "aaaaa") PublicApi.enhance_metadata(source, target) assert target.record == result assert target.get_apc_refs("11111") == ["aaaaa"] assert target.get_apc_refs("22222") == []
def test_09_merge_records(self): # Check the merge of PublicAPC records merge_source = PublicAPCFixtureFactory.record_merge_source() merge_target = PublicAPCFixtureFactory.record_merge_target() result = PublicAPCFixtureFactory.record_merge_result() source = PublicAPC() source.record = merge_source source.set_apc_ref("22222", "bbbbb") target = PublicAPC() target.record = merge_target target.set_apc_ref("11111", "aaaaa") target.merge_records(source) assert target.record == result assert target.get_apc_refs("11111") == ["aaaaa"] assert target.get_apc_refs("22222") == [] # now just try some basic error cases with self.assertRaises(ModelException): target.merge_records({"random" : "data"})
def test_08_public_apc_methods(self): # Check all the PublcAPC object methods pub = PublicAPC() assert len(pub.get_apc_refs("11111")) == 0 pub.set_apc_ref("11111", "aaaaa") assert pub.get_apc_refs("11111")[0] == "aaaaa" pub.set_apc_ref("22222", "bbbbb") assert len(pub.get_apc_refs("22222")) == 1 pub.remove_apc_refs("11111") assert len(pub.get_apc_refs("22222")) == 1 assert len(pub.get_apc_refs("11111")) == 0 assert "11111" not in pub.list_owners() assert "22222" in pub.list_owners() pub.remove_apc_refs("22222") assert len(pub.get_apcs_by_owner("11111")) == 0 apc_record = PublicAPCFixtureFactory.apc_record() first = deepcopy(apc_record) first["ref"] = "aaaaa" pub.add_apc_for_owner("11111", first) assert len(pub.get_apc_refs("11111")) == 1 assert pub.get_apc_refs("11111")[0] == "aaaaa" assert len(pub.get_apcs_by_owner("11111")) == 1 assert pub.get_apcs_by_owner("11111")[0]["ref"] == "aaaaa" second = deepcopy(apc_record) second["ref"] = "bbbbb" pub.add_apc_for_owner("22222", second) assert len(pub.get_apc_refs("22222")) == 1 assert pub.get_apc_refs("22222")[0] == "bbbbb" assert len(pub.get_apcs_by_owner("22222")) == 1 assert pub.get_apcs_by_owner("22222")[0]["ref"] == "bbbbb" assert len(pub.apc_records) == 2 pub.remove_apcs_by_owner("11111") assert len(pub.apc_records) == 1 assert pub.apc_records[0]["ref"] == "bbbbb" assert len(pub.get_apc_refs("22222")) == 1 assert pub.get_apc_refs("22222")[0] == "bbbbb" assert len(pub.get_apcs_by_owner("22222")) == 1 assert pub.get_apcs_by_owner("22222")[0]["ref"] == "bbbbb" pub.remove_apcs_by_owner("22222") assert len(pub.apc_records) == 0 assert len(pub.get_apc_refs("11111")) == 0 assert len(pub.get_apc_refs("22222")) == 0