def find_request_by_identifier(cls, type, id, owner): """ Find a request by the identifier, within the scope of a given owner :param type: the type of identifier (e.g. doi, pmcid, url, etc) :param id: the identifier :param owner: the owner of the request :return: The most recent request owned by that owner with that identifier """ dao = Request() results = dao.find_by_identifier(type, id, owner) # results are ordered by date, so we want the latest one if len(results) > 0: return results[0] return None
def test_05_request_dao(self): # Check the DAO methods on the Request object dao = Request() source = RequestFixtureFactory.example() req = Request(source) req.owner = "test1" req.action = "update" req.public_id = "abcdefg" req.save(blocking=True) req2 = dao.pull(req.id) assert req2 is not None # check successful queries for identifiers res = dao.find_by_identifier("doi", "10.1234/me", "test1") assert len(res) == 1 res = dao.find_by_identifier("pmcid", "PMC1234", "test1") assert len(res) == 1 res = dao.find_by_identifier("pmid", "87654321", "test1") assert len(res) == 1 res = dao.find_by_identifier("url", "http://example.com/whatever", "test1") assert len(res) == 1 # check unsuccessful ones res = dao.find_by_identifier("doi", "10.1234/you", "test1") assert len(res) == 0 res = dao.find_by_identifier("pmcid", "PMC5678", "test1") assert len(res) == 0 res = dao.find_by_identifier("pmid", "123456789", "test1") assert len(res) == 0 res = dao.find_by_identifier("url", "http://example.com/this", "test1") assert len(res) == 0 # and check using the wrong owner res = dao.find_by_identifier("doi", "10.1234/me", "test2") assert len(res) == 0 res = dao.find_by_identifier("pmcid", "PMC1234", "test2") assert len(res) == 0 res = dao.find_by_identifier("pmid", "87654321", "test2") assert len(res) == 0 res = dao.find_by_identifier("url", "http://example.com/whatever", "test2") assert len(res) == 0