A reviewer's answer holds when more records join a person
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
"""A reviewer's "they are different people" is about the persons: it holds when more records
|
||||
join one of them, whichever record the person is known by afterwards."""
|
||||
|
||||
import json
|
||||
import sqlite3
|
||||
|
||||
PEOPLE = [("1001", "ANA LOPEZ RUIZ", "1980-01-01"), ("2002", "BEATRIZ MORA DIAZ", "1980-01-01")]
|
||||
PEOPLE += [(f"9{k:03d}", f"PERSONA {k} DE RELLENO", f"19{50 + k}-0{1 + k % 9}-11")
|
||||
for k in range(30)] # fmt: skip
|
||||
|
||||
|
||||
def graph(db) -> dict:
|
||||
fields = {"record_number": "num", "full_name": "nombre", "birth_date": "nac", "nss": "nss"}
|
||||
return {"nodes": [
|
||||
{"id": "people", "kind": "source", "source": "dlt.sources.sql_database:sql_table",
|
||||
"args": {"credentials": f"sqlite:///{db}", "table": "people"}},
|
||||
{"id": "identity", "kind": "map", "inputs": ["people"], "fields": fields},
|
||||
{"id": "persons", "kind": "link", "inputs": ["identity"], "fields": list(fields)},
|
||||
]} # fmt: skip
|
||||
|
||||
|
||||
def insert(db, rows) -> None:
|
||||
with sqlite3.connect(db) as con:
|
||||
con.execute(
|
||||
"create table if not exists people "
|
||||
"(id integer primary key, num text, nombre text, nac text, nss text)"
|
||||
)
|
||||
con.executemany("insert into people (num, nombre, nac, nss) values (?, ?, ?, ?)", rows)
|
||||
|
||||
|
||||
def test_an_answer_outlives_the_record_a_person_was_known_by(platform, tmp_path):
|
||||
db, drawn = tmp_path / "people.db", tmp_path / "pipeline.json"
|
||||
insert(db, [(*p, None) for p in PEOPLE])
|
||||
drawn.write_text(json.dumps(graph(db)))
|
||||
platform.save("pipelines", "site", drawn)
|
||||
platform.ingest()
|
||||
queue = "select person, candidate from bronze.n__site__persons__review"
|
||||
((a, b),) = platform.query(queue)
|
||||
platform.run("python", "-c", "from persistance import nodes; "
|
||||
f"nodes.decide_persons({a!r}, {b!r}, False, 'reviewer')") # fmt: skip
|
||||
platform.ingest()
|
||||
assert platform.query(queue) == []
|
||||
|
||||
# Forty more documents of each woman: whichever of her records her person was known by,
|
||||
# one of these is (almost surely) it now.
|
||||
insert(db, [(num, None, None, f"{num}{k:07d}") for num in ("1001", "2002") for k in range(40)])
|
||||
platform.ingest()
|
||||
lowest = "select min(_record) from bronze.n__site__persons where record_number = '{}'"
|
||||
known = {platform.query(lowest.format(n))[0][0] for n in ("1001", "2002")}
|
||||
assert known != {a, b}
|
||||
assert platform.query(queue) == []
|
||||
Reference in New Issue
Block a user