← back to Paul Conrad Archive

tests/test_dpla_authority.py

32 lines

"""DPLA: records pinned to Paul Conrad (b. 27 Jun 1924) by name authority are kept even without a cartoon keyword
(NPG Time-cover originals); a same-authority SOUND record and a different Paul Conrad are still dropped."""
import json

from conftest import FakeHttp
from conrad.crawlers import discovery
from conrad.crawlers.base import Blocked

NPG_DESC = ("In 1978, Time magazine donated approximately eight hundred works of original cover art to the National "
            "Portrait Gallery.")


def _doc(i, title, creators, types, prov="National Portrait Gallery", desc=NPG_DESC, obj=None):
    return {"id": f"id{i}", "isShownAt": f"http://n2t.net/ark:/{i}", "object": obj, "dataProvider": {"name": prov},
            "sourceResource": {"title": [title], "creator": creators, "type": types, "description": [desc],
                               "date": [{"displayDate": "1967"}]}}


def test_dpla_authority_keeps_npg_time_covers(tmpdb, monkeypatch):
    from conrad import config
    monkeypatch.setattr(config, "secret", lambda name: "k" if name == "DPLA_API_KEY" else None)
    docs = [_doc(1, "Weighing in for '68", ["Paul Conrad, born 27 Jun 1924", "Lyndon Baines Johnson"], ["image"],
                 obj="https://ids.si.edu/ids/deliveryService?id=NPG-NPG_78_TC179-000005"),
            _doc(2, "Paul Conrad cartoons and drawings", ["Conrad, Paul, 1924-2010"], ["sound"], prov="LACMA"),
            _doc(3, "Die Reformation", ["Conrad, Paul, 1865-1927"], ["text"], prov="SRLF", desc="Festschrift")]
    http = FakeHttp({"api.dp.la": (200, json.dumps({"count": 3, "docs": docs})), "http": Blocked("probe blocked")})
    discovery.CRAWLER(conn=tmpdb, http=http).run()
    rows = tmpdb.execute("SELECT c.title, c.publication, cs.thumbnail_url FROM cartoons c "
                         "JOIN cartoon_sources cs ON cs.cartoon_id=c.id").fetchall()
    assert [tuple(r) for r in rows] == [("Weighing in for '68", "Time",
                                         "https://ids.si.edu/ids/deliveryService?id=NPG-NPG_78_TC179-000005")]