예제 #1
0
    def test_02_find_public_record(self):
        # Find a public record with a variety of identifiers

        source = PublicAPCFixtureFactory.example()
        pub = PublicAPC(source)
        pub.save(blocking=True)

        # document to form the basis of the queries
        source2 = RequestFixtureFactory.example()

        # create sources with one of each kind of identifier, then look them up using the
        # find_public_record and find_public_record_by_identifier methods
        pid = deepcopy(source2)
        del pid["record"]["dc:identifier"]
        req = Request(pid)
        req.public_id = pub.id
        pub1 = PublicApi.find_public_record(req)
        assert pub1 is not None

        doi = deepcopy(source2)
        doi["record"]["dc:identifier"] = [{"type": "doi", "id": "10.1234/me"}]
        req = Request(doi)
        pub1 = PublicApi.find_public_record(req)
        assert pub1 is not None
        pub11 = PublicApi.find_public_record_by_identifier("doi", "10.1234/me")
        assert pub11 is not None

        pmid = deepcopy(source2)
        pmid["record"]["dc:identifier"] = [{"type": "pmid", "id": "87654321"}]
        req = Request(pmid)
        pub1 = PublicApi.find_public_record(req)
        assert pub1 is not None
        pub11 = PublicApi.find_public_record_by_identifier("pmid", "87654321")
        assert pub11 is not None

        pmcid = deepcopy(source2)
        pmcid["record"]["dc:identifier"] = [{"type": "pmcid", "id": "PMC1234"}]
        req = Request(pmcid)
        pub1 = PublicApi.find_public_record(req)
        assert pub1 is not None
        pub11 = PublicApi.find_public_record_by_identifier("pmcid", "PMC1234")
        assert pub11 is not None

        url = deepcopy(source2)
        url["record"]["dc:identifier"] = [{"type": "url", "id": "http://example.com/whatever"}]
        req = Request(url)
        pub1 = PublicApi.find_public_record(req)
        assert pub1 is not None
        pub11 = PublicApi.find_public_record_by_identifier("url", "http://example.com/whatever")
        assert pub11 is not None

        # finally, ensure that you don't get a match when you shouldn't
        null = deepcopy(source2)
        null["record"]["dc:identifier"] = [{"type": "doi", "id": "10.1234/another"}]
        req = Request(null)
        pub1 = PublicApi.find_public_record(req)
        assert pub1 is None
        pub11 = PublicApi.find_public_record_by_identifier("doi", "10.1234/another")
        assert pub11 is None
예제 #2
0
    def pull(cls, id, account=None):
        """
        Pull a record with the given id, in the context of the supplied account (response content may vary slightly
        if the user owns the record)

        The id may be one of 2 things, in order of preference:

        1. The DOI
        2. The public id

        :param id:
        :param account:
        :return:
        """
        # if this is a DOI, do the DOI queries
        if id.startswith("10."):
            pub = PublicApi.find_public_record_by_identifier("doi", id)
            if pub is not None:
                return ApiRequest._make_from_public(pub, account)

        else:
            dao = PublicAPC()
            pub = dao.pull(id)
            if pub is not None:
                return ApiRequest._make_from_public(pub, account)

        return None