def test_09_remove_permanent(self): # Separate an incoming Request from its corresponding PublicAPC, leaving no owners, thus deleting the record source = RequestFixtureFactory.example() req = Request(source) req.owner = "test" # create a record with 2 distinct apcs from different owners source2 = PublicAPCFixtureFactory.example() pub = PublicAPC(source2) pub.remove_apcs_by_owner("abcdefg") # clear the existing apc record apc_record = PublicAPCFixtureFactory.apc_record() del apc_record["ref"] # do this so that the ref gets created correctly later pub.add_apc_for_owner("test", apc_record) # add a new, known one pub.save(blocking=True) # now request the removal PublicApi.remove(req) time.sleep(2) dao = PublicAPC() pub2 = dao.pull(pub.id) assert pub2 is None
def test_03_publish_new(self): # Publish a new request source = RequestFixtureFactory.example() req = Request(source) pub = PublicApi.publish(req) dao = PublicAPC() pub2 = dao.pull(pub.id) assert pub2 is not None
def test_06_publish_update(self): # Publish an update to an existing PublicAPC merge_source = PublicAPCFixtureFactory.record_merge_source() merge_target = PublicAPCFixtureFactory.record_merge_target() apc_record = PublicAPCFixtureFactory.apc_record() result = PublicAPCFixtureFactory.record_merge_result() del merge_source["jm:apc"] del merge_target["jm:apc"] del result["jm:apc"] first = deepcopy(apc_record) second = deepcopy(apc_record) third = deepcopy(apc_record) first["organisation_name"] = "First" del first["ref"] second["organisation_name"] = "Second" del second["ref"] third["organisation_name"] = "Third" del third["ref"] req = Request() req.record = merge_source req.add_apc_record(first) req.owner = "11111" pub = PublicAPC() pub.record = merge_target pub.add_apc_for_owner("22222", second) pub.add_apc_for_owner("11111", third) pub.save(blocking=True) PublicApi.publish(req) dao = PublicAPC() pub2 = dao.pull(pub.id) # first check that the apcs are as we would expect one = pub2.get_apcs_by_owner("11111") two = pub2.get_apcs_by_owner("22222") assert len(one) == 1 assert len(two) == 1 assert one[0]["organisation_name"] == "First" assert two[0]["organisation_name"] == "Second" # now check that the metadata merge proceeded correctly record = pub2.record del record["jm:apc"] assert record == result
def find_public_record(cls, req): """ Find a single public record which could be considered the same as the document in the supplied request. This will look at identifiers in the following order of precedence: 1. by public id 2. By DOI 3. By PMID 4. By PMCID 5. By URL If more than one match is made at any point, a warning will be written to the logs, and the first result (which is basically arbitrary) will be returned. :param req: Request object containing data to be used to find the public record :return: The public record, or None if no candidate found """ dao = PublicAPC() if req.public_id is not None: pub = dao.pull(req.public_id) if pub is not None: return pub if req.doi is not None: pub = PublicApi.find_public_record_by_identifier("doi", req.doi) if pub is not None: return pub if req.pmid is not None: pub = PublicApi.find_public_record_by_identifier("pmid", req.pmid) if pub is not None: return pub if req.pmcid is not None: pub = PublicApi.find_public_record_by_identifier("pmcid", req.pmcid) if pub is not None: return pub if req.url is not None: pub = PublicApi.find_public_record_by_identifier("url", req.url) if pub is not None: return pub # if we get to here, there is no record for this id return None
def test_06_public_dao(self): # Check all the DAO methods on the PublicAPC object dao = PublicAPC() source = PublicAPCFixtureFactory.example() pub = PublicAPC(source) pub.set_apc_ref("test1", "1111111111") pub.save(blocking=True) # first try the straight-forward pull pub2 = dao.pull(pub.id) assert pub2 is not None # now do the successful queries res = dao.find_by_doi("10.1234/me") assert len(res) == 1 res = dao.find_by_pmid("87654321") assert len(res) == 1 res = dao.find_by_pmcid("PMC1234") assert len(res) == 1 res = dao.find_by_url("http://example.com/whatever") assert len(res) == 1 # now to check those queries don't always return, make sure we can get 0 results res = dao.find_by_doi("10.1234/whatever") assert len(res) == 0 res = dao.find_by_pmid("88888888") assert len(res) == 0 res = dao.find_by_pmcid("PMC1111") assert len(res) == 0 res = dao.find_by_url("http://example.com/another") assert len(res) == 0 gen = dao.list_by_owner("abcdefg") count = 0 for apc in gen: count += 1 assert count == 1
def test_08_remove_separate(self): # Separate an incoming Request from its corresponding PublicAPC, leaving only one owner behind source = RequestFixtureFactory.example() req = Request(source) req.owner = "test" # create a record with 2 distinct apcs from different owners source2 = PublicAPCFixtureFactory.example() apc_record = PublicAPCFixtureFactory.apc_record() del apc_record["ref"] # do this so that the ref gets created correctly later pub = PublicAPC(source2) pub.add_apc_for_owner("test", apc_record) pub.save(blocking=True) # now request the removal PublicApi.remove(req) time.sleep(2) dao = PublicAPC() pub2 = dao.pull(pub.id) assert len(pub2.get_apcs_by_owner("test")) == 0 assert len(pub2.get_apcs_by_owner("abcdefg")) == 1