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 find_public_record_by_identifier(cls, type, id): """ Find a single public record which corresponds to the given identifier. If more than one record are present, this will return the first one encountered, which is essentially random. :param type: the identifier type (e.g. doi, pmid, pmcid, url) :param id: the identifier :return: a PublicAPC record if one is found otherwise None """ dao = PublicAPC() if type == "doi": pubs = dao.find_by_doi(id) if len(pubs) > 1: app.logger.warn(u"Multiple public records found for DOI {x}".format(x=id)) return None if len(pubs) > 0: return pubs[0] if type == "pmid": pubs = dao.find_by_pmid(id) if len(pubs) > 1: app.logger.warn(u"Multiple public records found for PMID {x}".format(x=id)) return None if len(pubs) > 0: return pubs[0] if type == "pmcid": pubs = dao.find_by_pmcid(id) if len(pubs) > 1: app.logger.warn(u"Multiple public records found for PMCID {x}".format(x=id)) return None if len(pubs) > 0: return pubs[0] if type == "url": pubs = dao.find_by_url(id) if len(pubs) > 1: app.logger.warn(u"Multiple public records found for URL {x}".format(x=id)) return None if len(pubs) > 0: return pubs[0]