The OSINT investigator's workbench. One case, one folder, every tool. Local-first: your media and your investigations never leave your machine.
JavaScript
"""Proofs: save spec+PNG, list, reload, entity upsert, delete."""
import base64
import graph_read
import io
import pytest
from PIL import Image
from azimut import layout
from azimut.workspace import Case
def _png_b64() -> str:
buf = io.BytesIO()
Image.new("RGB", (80, 50), (40, 40, 60)).save(buf, "PNG")
return base64.b64encode(buf.getvalue()).decode()
SPEC = {
"templateId": "dark-house",
"captionSize": 24,
"legendSize": 22,
"footerSize": 18,
"footer": "Custom footer line",
"panels": [
{"id": "p1", "src": "media/frame.png", "caption": "Frame", "row": 0, "natural": [1280, 720], "meta": {}},
{"id": "p2", "src": "satellite/sat.png", "caption": "Esri", "row": 1, "natural": [1000, 700],
"meta": {"kind": "satellite", "attribution": "Esri", "lat": 1.0, "lon": 2.0}},
],
"shapes": [
{"id": "s1", "panel": "p1", "kind": "rect", "x": 10, "y": 10, "w": 100, "h": 50,
"color": "#ff5252", "strokeWidth": 4, "comment": "blue roof"},
],
"coords": {"lat": 1.0, "lon": 2.0},
"notes": {"#ff5252": "blue roof matches"},
}
def test_save_load_roundtrip(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
saved = client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Kharkiv strike proof", "spec": SPEC, "png_base64": _png_b64()},
).json()
assert saved["name"] == "Kharkiv strike proof"
assert saved["png"] == "proofs/Kharkiv strike proof.png"
listed = client.get(f"/api/cases/{cid}/proofs").json()
assert len(listed) == 1
assert listed[0]["panels"] == 2 and listed[0]["shapes"] == 1
spec = client.get(f"/api/cases/{cid}/proofs/{saved['name']}").json()
assert spec["title"] == "Kharkiv strike proof"
assert spec["shapes"][0]["comment"] == "blue roof"
assert spec["notes"] == {"#ff5252": "blue roof matches"} # legend text is per color
assert spec["panels"][0]["id"] == "p1" # panel ids survive → shapes stay bound
# multi-row layout + text sizes + custom footer survive the round-trip
assert [p["row"] for p in spec["panels"]] == [0, 1]
assert spec["captionSize"] == 24
assert spec["legendSize"] == 22
assert spec["footerSize"] == 18
assert spec["footer"] == "Custom footer line"
assert spec["templateId"] == "dark-house"
# PNG served
assert client.get(f"/files/{cid}/{saved['png']}").status_code == 200
# proof entity filed once, updated on resave
client.post(
f"/api/cases/{cid}/proofs",
json={"rename_from": saved["name"], "title": "Kharkiv strike proof", "spec": SPEC},
)
entities = [e for e in graph_read.entities(cid) if e["type"] == "proof"]
assert len(entities) == 1
assert entities[0]["label"] == "Kharkiv strike proof"
def test_resave_with_png_adds_the_path_to_the_entity(client):
cid = client.post("/api/cases", json={"name": "SpecFirst"}).json()["id"]
# first save is spec-only: no PNG, so the entity has no path
saved = client.post(
f"/api/cases/{cid}/proofs", json={"title": "Draft proof", "spec": SPEC}
).json()
entity = next(
e for e in graph_read.entities(cid) if e["type"] == "proof"
)
assert "path" not in entity["attrs"]
# exporting later re-saves with the PNG — the entity must gain the path,
# or the sidebar preview and delete_by_path can't see the file
client.post(
f"/api/cases/{cid}/proofs",
json={
"rename_from": saved["name"],
"title": "Draft proof",
"spec": SPEC,
"png_base64": _png_b64(),
},
)
entity = next(
e for e in graph_read.entities(cid) if e["type"] == "proof"
)
assert entity["attrs"]["path"] == layout.proof_export_rel(saved['name'])
def test_invalid_png_rejected(client):
cid = client.post("/api/cases", json={"name": "Bad"}).json()["id"]
res = client.post(
f"/api/cases/{cid}/proofs",
json={"title": "x", "spec": SPEC, "png_base64": "not-base64!!!"},
)
assert res.status_code == 422
def test_rename_moves_the_spec_and_the_export(client):
# The name in the composer header is the filename. Renaming a saved proof
# takes its spec, its PNG and its entity along, so nothing is orphaned and
# the proof keeps its folder and links.
cid = client.post("/api/cases", json={"name": "RenameProof"}).json()["id"]
saved = client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Proof 1", "spec": SPEC, "png_base64": _png_b64()},
).json()
before = next(e for e in graph_read.entities(cid) if e["type"] == "proof")
client.patch(f"/api/cases/{cid}/entities/{before['id']}", json={"attrs": {"folder": "Reports"}})
renamed = client.post(
f"/api/cases/{cid}/proofs",
json={
"rename_from": saved["name"],
"title": "Rooftop angle",
"spec": SPEC,
"png_base64": _png_b64(),
},
).json()
assert renamed["name"] == "Rooftop angle"
assert renamed["png"] == "proofs/Rooftop angle.png"
assert client.get(f"/api/cases/{cid}/proofs/{saved['name']}").status_code == 404
assert client.get(f"/files/{cid}/proofs/{saved['name']}.png").status_code == 404
assert client.get(f"/files/{cid}/proofs/{renamed['name']}.png").status_code == 200
proofs = [e for e in graph_read.entities(cid) if e["type"] == "proof"]
assert len(proofs) == 1
assert proofs[0]["id"] == before["id"]
assert proofs[0]["attrs"]["spec"] == "proofs/.meta/Rooftop angle.json"
assert proofs[0]["attrs"]["path"] == "proofs/Rooftop angle.png"
assert proofs[0]["attrs"]["folder"] == "Reports"
def test_rename_without_fresh_pixels_carries_the_export_along(client):
# A save that ships no PNG (spec-only) must not strand the export under the
# old name — the proof would lose its picture on a pure rename.
cid = client.post("/api/cases", json={"name": "CarryPng"}).json()["id"]
saved = client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Proof 1", "spec": SPEC, "png_base64": _png_b64()},
).json()
renamed = client.post(
f"/api/cases/{cid}/proofs",
json={"rename_from": saved["name"], "title": "Carried", "spec": SPEC},
).json()
assert renamed["png"] == "proofs/Carried.png"
assert client.get(f"/files/{cid}/proofs/Carried.png").status_code == 200
assert client.get(f"/files/{cid}/proofs/{saved['name']}.png").status_code == 404
entity = next(e for e in graph_read.entities(cid) if e["type"] == "proof")
assert entity["attrs"]["path"] == "proofs/Carried.png"
def test_rename_onto_a_taken_name_is_refused(client):
cid = client.post("/api/cases", json={"name": "ClashProof"}).json()["id"]
client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Proof 1", "spec": SPEC, "png_base64": _png_b64()},
)
second = client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Proof 2", "spec": SPEC, "png_base64": _png_b64()},
).json()
res = client.post(
f"/api/cases/{cid}/proofs",
json={
"rename_from": second["name"],
"title": "Proof 1",
"spec": SPEC,
"png_base64": _png_b64(),
},
)
assert res.status_code == 409
listed = sorted(p["name"] for p in client.get(f"/api/cases/{cid}/proofs").json())
assert listed == ["Proof 1", "Proof 2"]
assert client.get(f"/files/{cid}/proofs/{second['name']}.png").status_code == 200
def test_rename_keeps_the_creation_date(client):
cid = client.post("/api/cases", json={"name": "BornProof"}).json()["id"]
saved = client.post(
f"/api/cases/{cid}/proofs", json={"title": "Proof 1", "spec": SPEC}
).json()
born = client.get(f"/api/cases/{cid}/proofs/{saved['name']}").json()["created_at"]
client.post(
f"/api/cases/{cid}/proofs",
json={"rename_from": saved["name"], "title": "Renamed", "spec": SPEC},
)
assert client.get(f"/api/cases/{cid}/proofs/Renamed").json()["created_at"] == born
def test_delete_proof(client):
cid = client.post("/api/cases", json={"name": "DelProof"}).json()["id"]
saved = client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Temp", "spec": SPEC, "png_base64": _png_b64()},
).json()
client.delete(f"/api/cases/{cid}/proofs/{saved['name']}")
assert client.get(f"/api/cases/{cid}/proofs").json() == []
assert client.get(f"/api/cases/{cid}/proofs/{saved['name']}").status_code == 404
assert [e for e in graph_read.entities(cid) if e["type"] == "proof"] == []
def _big_png_b64(size=(2400, 1600)) -> str:
buf = io.BytesIO()
Image.new("RGB", size, (30, 90, 140)).save(buf, "PNG")
return base64.b64encode(buf.getvalue()).decode()
def test_save_produces_a_thumbnail_of_the_export(client):
from azimut.api.cases import get_case
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
saved = client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Wide proof", "spec": SPEC, "png_base64": _big_png_b64()},
).json()
assert saved["thumb"] and saved["thumb"] != saved["png"]
case = get_case(cid)
thumb, png = case.resolve_inside(saved["thumb"]), case.resolve_inside(saved["png"])
assert thumb.stat().st_size < png.stat().st_size
assert client.get(f"/files/{cid}/{saved['thumb']}").status_code == 200
# the listing hands it to the open dialog, so the row never loads the export
assert client.get(f"/api/cases/{cid}/proofs").json()[0]["thumb"] == saved["thumb"]
# and the entity carries it too, so a surface drawing a few hundred entities at
# once — the graph — reads a preview off the row it already has instead of
# opening one spec file per proof
entity = case.find_entity(attr="spec", value=saved["spec_path"])
assert entity["attrs"]["thumb"] == saved["thumb"]
node = next(
row
for row in client.get(f"/api/cases/{cid}/graph").json()["nodes"]
if row["id"] == entity["id"]
)
assert node["thumb"] == saved["thumb"]
def test_listing_backfills_a_proof_saved_before_thumbnails(client):
import json
from azimut.api.cases import get_case
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
saved = client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Old proof", "spec": SPEC, "png_base64": _big_png_b64()},
).json()
# roll the proof back to what an older save left on disk: a spec with no
# thumbnail recorded, and nothing in the cache
case = get_case(cid)
spec_path = case.resolve_inside(saved["spec_path"])
spec = json.loads(spec_path.read_text(encoding="utf-8"))
del spec["thumb"]
spec_path.write_text(json.dumps(spec), encoding="utf-8")
case.resolve_inside(saved["thumb"]).unlink()
listed = client.get(f"/api/cases/{cid}/proofs").json()[0]
assert listed["thumb"] == saved["thumb"]
assert case.resolve_inside(listed["thumb"]).is_file()
# recorded, so the next listing costs nothing
assert json.loads(spec_path.read_text(encoding="utf-8"))["thumb"] == saved["thumb"]
def test_the_graph_adopts_a_thumbnail_a_proof_only_recorded_in_its_spec(client):
"""The migration has to cover the ordinary proof, not only the broken one.
A proof saved before the entity recorded a thumbnail still has a perfectly good
one in its spec, so nothing about it needs repairing — and it would draw as a
glyph forever if the only thing that copied the path across were the repair of a
missing thumbnail. The graph adopts it on the first view, then reads the row."""
from azimut.api.cases import get_case
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
saved = client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Older proof", "spec": SPEC, "png_base64": _big_png_b64()},
).json()
case = get_case(cid)
entity = case.find_entity(attr="spec", value=saved["spec_path"])
# what an older save left behind: the spec knows its thumbnail, the entity does not
case.update_entity(entity["id"], {"attrs": {"thumb": ""}})
node = next(
row
for row in client.get(f"/api/cases/{cid}/graph").json()["nodes"]
if row["id"] == entity["id"]
)
assert node["thumb"] == saved["thumb"]
# recorded on the entity, so no later view opens the spec file again
assert case.get_entity(entity["id"])["attrs"]["thumb"] == saved["thumb"]
hood = client.get(
f"/api/cases/{cid}/graph/neighborhood", params={"root": entity["id"]}
).json()
assert hood["nodes"][0]["thumb"] == saved["thumb"]
def test_listing_falls_back_to_the_export_when_no_thumbnail_can_be_made(client):
from azimut.api.cases import get_case
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
saved = client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Broken proof", "spec": SPEC, "png_base64": _png_b64()},
).json()
case = get_case(cid)
case.resolve_inside(saved["thumb"]).unlink()
case.resolve_inside(saved["png"]).write_bytes(b"not an image")
# rewrite the spec so the recorded thumbnail is not simply reused
spec_path = case.resolve_inside(saved["spec_path"])
spec_path.write_text(spec_path.read_text(encoding="utf-8").replace(saved["thumb"], ""), encoding="utf-8")
listed = client.get(f"/api/cases/{cid}/proofs").json()[0]
assert not listed["thumb"]
assert listed["png"] == saved["png"] # the row still shows something
def test_cache_repair_keeps_proof_thumbnails(client):
from azimut.api.cases import get_case
from azimut.engine import thumbnails
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
saved = client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Kept proof", "spec": SPEC, "png_base64": _big_png_b64()},
).json()
case = get_case(cid)
thumbnails.repair(case) # no media sidecar references it, but a proof does
assert case.resolve_inside(saved["thumb"]).is_file()
# -- the proofs index: proofs placed on the map ---------------------------------------
# A proof carries no coordinates of its own (ONTOLOGY: `spec` + `path`), so the
# map reads them one hop back through `derived-from`. What must hold: the point
# is inherited, a proof composed of panels from two places is at both, and one
# with no located source still lists.
@pytest.fixture()
def sat_tiles(monkeypatch):
"""Captures without the network: every tile is a solid green square."""
from azimut.engine import tiles
monkeypatch.setattr(
tiles, "_default_fetch", lambda client, url: Image.new("RGB", (256, 256), (10, 120, 10))
)
def _panels(*srcs):
return {"panels": [{"id": f"p{i}", "src": s} for i, s in enumerate(srcs)]}
def _sat(client, cid, lat, lon):
"""A saved capture — the only kind of panel that carries a point."""
return client.post(
f"/api/cases/{cid}/satellite/capture",
json={"lat": lat, "lon": lon, "zoom": 16, "width": 256, "height": 256},
).json()
# -- the place a proof files (engine/satellite.place_for_proof) -----------------
#
# A geolocation is concluded in the composer, so the point becomes a node here
# rather than on every capture taken while looking for it.
def _depicts(cid):
return graph_read.links(cid, "depicts")
def _places(cid):
return [e for e in graph_read.entities(cid) if e["type"] == "place"]
def _save(client, cid, title, spec):
return client.post(f"/api/cases/{cid}/proofs", json={"title": title, "spec": spec}).json()
def _with_coords(text=None, point=None, *srcs, pov=False):
spec = _panels(*srcs)
if text is not None:
spec["coordsText"] = text
if point is not None:
spec["coords"] = point
if pov:
spec["pov"] = True
return spec
def _located_at(cid):
return graph_read.links(cid, "located-at")
def test_saving_a_proof_files_the_point_it_carries(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
saved = _save(client, cid, "Roof match", _with_coords("50.4501, 30.5234"))
places = _places(cid)
assert len(places) == 1
assert (places[0]["attrs"]["lat"], places[0]["attrs"]["lon"]) == (50.4501, 30.5234)
# the analyst's own answer, so there is nothing left to review
assert places[0]["provenance"]["status"] == "confirmed"
assert saved["place"] == {
"filed": [{"id": places[0]["id"], "label": places[0]["label"]}],
"asking": [],
}
# and the proof says it shows that place
edges = _depicts(cid)
assert len(edges) == 1
assert edges[0]["to"] == places[0]["id"]
assert edges[0]["provenance"]["status"] == "confirmed"
def test_a_proof_with_no_point_files_nothing(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
assert _save(client, cid, "No point", _panels("media/frame.png"))["place"] is None
assert _places(cid) == []
def test_the_typed_point_wins_over_the_one_the_panels_gave(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
_save(client, cid, "Corrected", _with_coords("50.4501, 30.5234", {"lat": 1.0, "lon": 2.0}))
# the composer's field is the analyst's correction; the frozen panel point loses
assert [(p["attrs"]["lat"], p["attrs"]["lon"]) for p in _places(cid)] == [(50.4501, 30.5234)]
def test_a_point_the_case_already_holds_is_neither_filed_twice_nor_asked_about(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
client.post(
f"/api/cases/{cid}/satellite/place", json={"lat": 50.4501, "lon": 30.5234}
)
saved = _save(client, cid, "Same point", _with_coords("50.4501, 30.5234"))
assert saved["place"] is None # nothing to file, so nothing to ask
assert len(_places(cid)) == 1
# the pin was already there, so it is reused rather than minted again — but the
# proof still says it concludes there, or the point it states would be unreadable
assert [lk["to"] for lk in _depicts(cid)] == [_places(cid)[0]["id"]]
def test_resaving_a_proof_stays_silent(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
spec = _with_coords("50.4501, 30.5234")
assert len(_save(client, cid, "Roof match", spec)["place"]["filed"]) == 1
# the point is in the case now: saving again must not ask, nor pin it twice
assert _save(client, cid, "Roof match", spec)["place"] is None
assert len(_places(cid)) == 1
def test_the_composer_is_asked_when_the_setting_is_off(client):
client.put("/api/settings/prefs", json={"proof_place_auto": False})
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
saved = _save(client, cid, "Roof match", _with_coords("50.4501, 30.5234"))
assert saved["place"] == {
"filed": [],
"asking": [{"lat": 50.4501, "lon": 30.5234, "label": "", "pov": False}],
}
assert _places(cid) == [] # nothing is written until the analyst says yes
filed = client.post(f"/api/cases/{cid}/proofs/Roof match/place").json()
assert len(filed) == 1
assert _depicts(cid)[0]["from"] == graph_read.entity(cid, spec=layout.proof_spec_rel("Roof match"))["id"]
def test_answering_twice_files_one_place(client):
"""Two tabs answering the same question must not pin the point twice."""
client.put("/api/settings/prefs", json={"proof_place_auto": False})
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
_save(client, cid, "Roof match", _with_coords("50.4501, 30.5234"))
first = client.post(f"/api/cases/{cid}/proofs/Roof match/place").json()
second = client.post(f"/api/cases/{cid}/proofs/Roof match/place").json()
# the second answer finds the point standing and joins it: nothing new to file
assert first[0]["id"] == _places(cid)[0]["id"]
assert second == []
assert len(_places(cid)) == 1
def test_the_material_the_proof_composes_states_the_same_point(client, sat_tiles):
"""The video the proof was built from says it too, and says it confirmed.
Putting a frame beside a capture and writing the coordinates *is* the
geolocation, so there is nothing left to review: asking the analyst to accept
their own act is the click that teaches people to click through the ones that
matter.
"""
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
case = Case.open(cid)
video = case.add_entity(
"media", "clip.mp4", {"path": "media/clip.mp4", "kind": "video"}, by="user"
)
frame = case.add_entity(
"media", "frame.png", {"path": "media/frame.png", "kind": "image"}, by="user"
)
case.add_link(frame["id"], video["id"], "derived-from", by="inspect")
cap = _sat(client, cid, 50.4501, 30.5234)
_save(client, cid, "Roof match", _with_coords(
"50.4501, 30.5234", None, "media/frame.png", cap["path"]
))
place = _places(cid)[0]
stated = {
lk["from"]: lk["provenance"]["status"]
for lk in _depicts(cid)
if lk["to"] == place["id"]
}
# the frame, the capture, and the video two hops up
assert stated[frame["id"]] == "confirmed"
assert stated[video["id"]] == "confirmed"
assert stated[graph_read.entity(cid, path=cap["path"])["id"]] == "confirmed"
def test_a_proof_rests_on_material_it_never_composed(client, sat_tiles):
"""The clip under the photos, the second angle nobody cropped: files a geolocation
rests on without laying them out.
A thread states its point in the post that published it and hangs the material off
the ones after it. The composer can now bring those in from a stated source address,
and what it brings in is the proof's `material` — in the chain, and therefore on the
point, without ever being a panel.
Restated on every save like the panels are, so an address taken off the list takes
its edge with it rather than leaving a claim nothing on screen still makes.
"""
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
case = Case.open(cid)
case.add_entity("media", "frame.png", {"path": "media/frame.png", "kind": "image"}, by="user")
clip = case.add_entity(
"media", "clip.mp4", {"path": "media/clip.mp4", "kind": "video"}, by="user"
)
angle = case.add_entity(
"media", "angle.jpg", {"path": "media/angle.jpg", "kind": "image"}, by="user"
)
cap = _sat(client, cid, 50.4501, 30.5234)
spec = _with_coords("50.4501, 30.5234", None, "media/frame.png", cap["path"])
spec["material"] = ["media/clip.mp4", "media/angle.jpg"]
_save(client, cid, "Roof match", spec)
proof = graph_read.entity(cid, spec=layout.proof_spec_rel("Roof match"))
chain = {lk["to"] for lk in case.links_of(proof["id"]) if lk["type"] == "derived-from"}
assert {clip["id"], angle["id"]} <= chain
# And the point reaches them through that chain, with no second rule for it.
place = _places(cid)[0]
posed = {lk["from"] for lk in _depicts(cid) if lk["to"] == place["id"]}
assert {clip["id"], angle["id"]} <= posed
# A second save with one address dropped drops its edge, panels untouched.
spec["material"] = ["media/clip.mp4"]
_save(client, cid, "Roof match", spec)
chain = {lk["to"] for lk in case.links_of(proof["id"]) if lk["type"] == "derived-from"}
assert clip["id"] in chain
assert angle["id"] not in chain
def test_a_source_the_verb_does_not_accept_is_skipped(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
case = Case.open(cid)
audio = case.add_entity(
"media", "call.mp3", {"path": "media/call.mp3", "kind": "audio"}, by="user"
)
case.add_entity("media", "frame.png", {"path": "media/frame.png", "kind": "image"}, by="user")
_save(client, cid, "Roof match", _with_coords(
"50.4501, 30.5234", None, "media/frame.png", "media/call.mp3"
))
# `shows` is about pixels: an audio file in the chain is skipped, not refused
assert audio["id"] not in {lk["from"] for lk in _depicts(cid)}
def test_pov_says_the_footage_was_recorded_there(client, sat_tiles):
"""The one thing a composition cannot deduce, so the composer asks it.
Recorded-at and shows are independent claims — a rooftop shot is recorded
somewhere it never shows — and a match between a frame and an imagery says
only that they meet, not whether the camera or its subject was located.
"""
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
case = Case.open(cid)
video = case.add_entity(
"media", "clip.mp4", {"path": "media/clip.mp4", "kind": "video"}, by="user"
)
cap = _sat(client, cid, 50.4501, 30.5234)
_save(client, cid, "From the roof", _with_coords(
"50.4501, 30.5234", None, "media/clip.mp4", cap["path"], pov=True
))
place = _places(cid)[0]
assert [lk["from"] for lk in _located_at(cid)] == [video["id"]]
# the capture is orbital imagery and the proof was composed: neither was
# recorded anywhere, so both keep saying they show the place
shows = {lk["from"] for lk in _depicts(cid) if lk["to"] == place["id"]}
assert graph_read.entity(cid, path=cap["path"])["id"] in shows
assert video["id"] not in shows
def test_without_pov_the_footage_only_shows_the_place(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
case = Case.open(cid)
video = case.add_entity(
"media", "clip.mp4", {"path": "media/clip.mp4", "kind": "video"}, by="user"
)
_save(client, cid, "Skyline", _with_coords("50.4501, 30.5234", None, "media/clip.mp4"))
assert _located_at(cid) == []
assert [lk["from"] for lk in _depicts(cid) if lk["from"] == video["id"]] == [video["id"]]
def test_pov_reaches_a_recording_the_other_verb_refuses(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
case = Case.open(cid)
audio = case.add_entity(
"media", "call.mp3", {"path": "media/call.mp3", "kind": "audio"}, by="user"
)
_save(client, cid, "Where it was taped", _with_coords(
"50.4501, 30.5234", None, "media/call.mp3", pov=True
))
# a recording has a place it was made, though it shows nothing
assert [lk["from"] for lk in _located_at(cid)] == [audio["id"]]
def test_the_answer_to_the_question_reads_pov_off_the_saved_proof(client):
client.put("/api/settings/prefs", json={"proof_place_auto": False})
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
case = Case.open(cid)
video = case.add_entity(
"media", "clip.mp4", {"path": "media/clip.mp4", "kind": "video"}, by="user"
)
saved = _save(client, cid, "From the roof", _with_coords(
"50.4501, 30.5234", None, "media/clip.mp4", pov=True
))
# so the question can say what the point will mean
assert saved["place"]["asking"][0]["pov"] is True
client.post(f"/api/cases/{cid}/proofs/From the roof/place")
# POV is a property of the point, not of the answer: the request carries nothing
assert [lk["from"] for lk in _located_at(cid)] == [video["id"]]
# -- re-saving restates the point (engine/satellite.restate_proof_point) --------
#
# A proof states one point, and a save is the restatement of it — the rule its
# panels already follow. Correcting the coordinates moves the edges rather than
# leaving the case holding two answers, and POV changes the verb it wrote before.
def _proof(cid):
return [e for e in graph_read.entities(cid) if e["type"] == "proof"][0]
def _video(cid, name="clip.mp4"):
return Case.open(cid).add_entity(
"media", name, {"path": f"media/{name}", "kind": "video"}, by="user"
)
def _place_by_lat(cid, lat):
return [p for p in _places(cid) if p["attrs"]["lat"] == lat][0]
def test_correcting_the_coordinates_moves_the_point_instead_of_adding_one(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
video = _video(cid)
_save(client, cid, "Roof match", _with_coords("50.4501, 30.5234", None, "media/clip.mp4"))
_save(client, cid, "Roof match", _with_coords("48.8584, 2.2945", None, "media/clip.mp4"))
# the proof and the footage state the corrected point, and only it: a
# withdrawn answer is not a second geolocation
corrected = _place_by_lat(cid, 48.8584)
assert {lk["to"] for lk in _depicts(cid)} == {corrected["id"]}
assert {lk["from"] for lk in _depicts(cid)} == {_proof(cid)["id"], video["id"]}
def test_the_point_it_moved_off_is_offered_for_deletion(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
_save(client, cid, "Roof match", _with_coords("50.4501, 30.5234"))
abandoned = _places(cid)[0]
saved = _save(client, cid, "Roof match", _with_coords("48.8584, 2.2945"))
# a point nobody points at is the analyst's leftover to keep or drop: the save
# names it and stops there rather than sweeping it
assert saved["orphans"] == [{"id": abandoned["id"], "label": abandoned["label"]}]
assert abandoned["id"] in {p["id"] for p in _places(cid)}
def test_a_point_something_else_still_holds_is_neither_stripped_nor_offered(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
case = Case.open(cid)
photo = case.add_entity(
"media", "roof.jpg", {"path": "media/roof.jpg", "kind": "image"}, by="user"
)
_save(client, cid, "Roof match", _with_coords("50.4501, 30.5234"))
stays = _places(cid)[0]
# the analyst's own statement about the same point, made in Details
case.add_link(photo["id"], stays["id"], "depicts", by="user")
saved = _save(client, cid, "Roof match", _with_coords("48.8584, 2.2945"))
assert saved["orphans"] == [] # something still holds it, so there is nothing to ask
# and a claim the composer did not write is not the composer's to withdraw
assert [lk["from"] for lk in _depicts(cid) if lk["to"] == stays["id"]] == [photo["id"]]
def test_toggling_pov_restates_the_verb_on_the_footage(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
video = _video(cid)
_save(client, cid, "Roof match", _with_coords("50.4501, 30.5234", None, "media/clip.mp4"))
assert [lk["from"] for lk in _depicts(cid)] == [_proof(cid)["id"], video["id"]]
_save(client, cid, "Roof match", _with_coords(
"50.4501, 30.5234", None, "media/clip.mp4", pov=True
))
# the point still stands and was never filed twice; what changed is what it means
assert len(_places(cid)) == 1
assert [lk["from"] for lk in _located_at(cid)] == [video["id"]]
# the proof itself was composed, so it shows the place either way
assert [lk["from"] for lk in _depicts(cid)] == [_proof(cid)["id"]]
_save(client, cid, "Roof match", _with_coords("50.4501, 30.5234", None, "media/clip.mp4"))
assert _located_at(cid) == [] # and the answer can be taken back
assert {lk["from"] for lk in _depicts(cid)} == {_proof(cid)["id"], video["id"]}
def test_turning_pov_off_drops_the_edge_the_other_verb_refuses(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
case = Case.open(cid)
case.add_entity("media", "call.mp3", {"path": "media/call.mp3", "kind": "audio"}, by="user")
spec = _with_coords("50.4501, 30.5234", None, "media/call.mp3", pov=True)
_save(client, cid, "Where it was taped", spec)
assert len(_located_at(cid)) == 1
_save(client, cid, "Where it was taped", _with_coords(
"50.4501, 30.5234", None, "media/call.mp3"
))
# a recording shows nothing, so withdrawing "recorded there" leaves it unplaced
assert _located_at(cid) == []
assert [lk["from"] for lk in _depicts(cid)] == [_proof(cid)["id"]]
def test_clearing_the_coordinates_withdraws_the_point(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
_video(cid)
_save(client, cid, "Roof match", _with_coords("50.4501, 30.5234", None, "media/clip.mp4"))
filed = _places(cid)[0]
saved = _save(client, cid, "Roof match", _panels("media/clip.mp4"))
# an emptied coordinate field is an answer taken back, not the last one frozen
assert _depicts(cid) == []
assert saved["orphans"] == [{"id": filed["id"], "label": filed["label"]}]
def test_swapping_the_footage_takes_the_point_off_the_clip_it_dropped(client):
"""The point stays, the material under it does not: a proof re-composed on another
clip must stop saying the old one was filmed there.
Read off the chain alone, nothing reached the dropped clip — the point was kept,
so it was never withdrawn, and the walk that restates it only ever visits the
material the proof rests on *now*. The video stayed on the map under a proof that
no longer rested on it, and the mark counted two.
"""
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
old = _video(cid)
new = _video(cid, "angle.mp4")
_save(client, cid, "Roof match", _with_coords("50.4501, 30.5234", None, "media/clip.mp4"))
place = _places(cid)[0]
assert old["id"] in {lk["from"] for lk in _depicts(cid) if lk["to"] == place["id"]}
_save(client, cid, "Roof match", _with_coords("50.4501, 30.5234", None, "media/angle.mp4"))
posed = {lk["from"] for lk in _depicts(cid) if lk["to"] == place["id"]}
assert new["id"] in posed
assert old["id"] not in posed
assert len(_places(cid)) == 1 # the point itself was kept, not re-filed
def test_footage_dropped_as_the_point_moves_is_left_on_neither(client):
"""The same save corrects the coordinates and swaps the clip. The withdrawal walked
the material the proof rests on now, so the clip it had just dropped kept its edge —
and held the abandoned point alive, which is worse than a stale mark: nothing owned
it any more, and it was never offered for deletion."""
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
old = _video(cid)
new = _video(cid, "angle.mp4")
_save(client, cid, "Roof match", _with_coords("50.4501, 30.5234", None, "media/clip.mp4"))
left = _places(cid)[0]
saved = _save(client, cid, "Roof match", _with_coords("48.8584, 2.2945", None, "media/angle.mp4"))
assert [lk["from"] for lk in _depicts(cid) if lk["to"] == left["id"]] == []
assert saved["orphans"] == [{"id": left["id"], "label": left["label"]}]
moved = _place_by_lat(cid, 48.8584)
assert new["id"] in {lk["from"] for lk in _depicts(cid) if lk["to"] == moved["id"]}
assert old["id"] not in {lk["from"] for lk in _depicts(cid)}
def test_a_point_another_proof_still_concludes_on_keeps_its_material(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
video = _video(cid)
spec = _with_coords("50.4501, 30.5234", None, "media/clip.mp4")
_save(client, cid, "First", spec)
_save(client, cid, "Second", spec)
shared = _places(cid)[0]
saved = _save(client, cid, "Second", _with_coords("48.8584, 2.2945", None, "media/clip.mp4"))
# the edges two proofs wrote on one video are indistinguishable, so moving one
# off must not undo the conclusion the other still states
assert saved["orphans"] == []
holding = {lk["from"] for lk in _depicts(cid) if lk["to"] == shared["id"]}
assert video["id"] in holding
assert graph_read.entity(cid, spec=layout.proof_spec_rel("First"))["id"] in holding
# -- a proof states several points (engine/satellite.spec_points) ---------------
#
# Three impacts, a building, the camera that filmed it: each is a point the
# analyst concluded on, and the first one is the conclusion every surface that
# can hold a single answer reads.
def _points(*entries):
"""A spec stating these points, `(coords, label, pov)` per entry."""
return {
"panels": [],
"points": [
{"coords": coords, "label": label, "pov": pov}
for coords, label, pov in entries
],
}
def test_a_spec_with_no_list_still_states_its_one_point(client):
"""Nothing migrates: a proof written before the list reads as one point."""
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
_save(client, cid, "Old shape", _with_coords("50.4501, 30.5234", None, pov=True))
[place] = _places(cid)
assert (place["attrs"]["lat"], place["attrs"]["lon"]) == (50.4501, 30.5234)
def test_every_point_becomes_a_place(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
saved = _save(client, cid, "Harbour strike", _points(
("64.1466, -21.9426", "impact 1", False),
("64.1481, -21.9401", "impact 2", False),
("64.1502, -21.9350", "caméra", True),
))
# one place per point: the map is about places, and that is where a proof's
# three points are read from
assert sorted(p["attrs"]["lat"] for p in _places(cid)) == [64.1466, 64.1481, 64.1502]
# and the label names the ground, since a place is otherwise called by its numbers
assert sorted(p["label"] for p in _places(cid)) == ["caméra", "impact 1", "impact 2"]
assert len(saved["place"]["filed"]) == 3
def test_the_first_point_is_the_conclusion_whatever_pov_says(client):
"""POV does not reorder: it would move a coordinate out of a tweet in silence."""
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
_save(client, cid, "Harbour strike", _points(
("64.1466, -21.9426", "impact 1", False),
("64.1502, -21.9350", "caméra", True),
))
spec = client.get(f"/api/cases/{cid}/proofs/Harbour strike").json()
from azimut.engine import satellite
conclusion = satellite.spec_points(spec)[0]
assert (conclusion["lat"], conclusion["lon"]) == (64.1466, -21.9426)
assert conclusion["pov"] is False # the camera is the second row, and stays there
def test_pov_is_carried_by_its_own_point(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
video = _video(cid)
spec = _points(
("64.1466, -21.9426", "impact 1", False),
("64.1502, -21.9350", "caméra", True),
)
spec["panels"] = _panels("media/clip.mp4")["panels"]
_save(client, cid, "Harbour strike", spec)
camera = _place_by_lat(cid, 64.1502)
impact = _place_by_lat(cid, 64.1466)
# the camera stood in one place; it shows the impact from there
assert [lk["to"] for lk in _located_at(cid)] == [camera["id"]]
assert [lk["from"] for lk in _located_at(cid)] == [video["id"]]
assert {lk["from"] for lk in _depicts(cid) if lk["to"] == impact["id"]} == {
_proof(cid)["id"], video["id"]
}
# a proof was composed, never recorded: it shows the camera's point too
assert _proof(cid)["id"] in {lk["from"] for lk in _depicts(cid) if lk["to"] == camera["id"]}
def test_a_second_pov_is_refused_because_a_camera_stood_in_one_place(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
video = _video(cid)
spec = _points(
("64.1466, -21.9426", "one", True),
("64.1502, -21.9350", "two", True),
)
spec["panels"] = _panels("media/clip.mp4")["panels"]
_save(client, cid, "Two cameras", spec)
# the first to claim it keeps it, whatever a hand-written spec asked for
assert [lk["from"] for lk in _located_at(cid)] == [video["id"]]
assert [lk["to"] for lk in _located_at(cid)] == [_place_by_lat(cid, 64.1466)["id"]]
def test_moving_pov_to_another_point_restates_both_verbs(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
video = _video(cid)
first = _points(("64.1466, -21.9426", "a", True), ("64.1502, -21.9350", "b", False))
first["panels"] = _panels("media/clip.mp4")["panels"]
_save(client, cid, "Harbour strike", first)
assert [lk["to"] for lk in _located_at(cid)] == [_place_by_lat(cid, 64.1466)["id"]]
moved = _points(("64.1466, -21.9426", "a", False), ("64.1502, -21.9350", "b", True))
moved["panels"] = _panels("media/clip.mp4")["panels"]
_save(client, cid, "Harbour strike", moved)
# the old reading goes rather than piling up beside the new one
assert [lk["to"] for lk in _located_at(cid)] == [_place_by_lat(cid, 64.1502)["id"]]
assert video["id"] in {lk["from"] for lk in _depicts(cid)
if lk["to"] == _place_by_lat(cid, 64.1466)["id"]}
def test_taking_a_point_off_the_list_rends_its_place(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
_save(client, cid, "Harbour strike", _points(
("64.1466, -21.9426", "impact 1", False),
("64.1481, -21.9401", "impact 2", False),
))
dropped = _place_by_lat(cid, 64.1481)
saved = _save(client, cid, "Harbour strike", _points(
("64.1466, -21.9426", "impact 1", False),
))
# exactly what clearing the single field always did, one line at a time
assert saved["orphans"] == [{"id": dropped["id"], "label": dropped["label"]}]
assert [lk["to"] for lk in _depicts(cid)] == [_place_by_lat(cid, 64.1466)["id"]]
def test_two_points_a_metre_apart_are_one_place(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
_save(client, cid, "Same roof", _points(
("64.1466, -21.9426", "impact 1", False),
("64.14660, -21.94260", "impact 1 again", False),
))
assert len(_places(cid)) == 1
def test_one_place_keeps_the_pov_the_second_line_ticked(client):
"""The duplicate goes, its answer about the camera does not. Dropped with the line, a
POV ticked on the second of two points a metre apart was a claim the composer showed
and the graph never carried."""
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
video = _video(cid)
spec = _points(("64.1466, -21.9426", "roof", False), ("64.14660, -21.94260", "", True))
spec["panels"] = _panels("media/clip.mp4")["panels"]
_save(client, cid, "Same roof", spec)
assert len(_places(cid)) == 1
assert [lk["from"] for lk in _located_at(cid)] == [video["id"]]
def test_a_line_that_reads_as_no_point_is_skipped(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
_save(client, cid, "Prose", _points(
("64.1466, -21.9426", "impact 1", False),
("near the harbour", "impact 2", False),
))
# prose in the field is a caption, not a point
assert [(p["attrs"]["lat"], p["attrs"]["lon"]) for p in _places(cid)] == [(64.1466, -21.9426)]
def test_a_spec_cannot_file_a_hundred_places_on_one_save(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
_save(client, cid, "Too many", _points(
*((f"64.{1000 + i}, -21.9426", "", False) for i in range(30))
))
from azimut.engine.satellite import MAX_PROOF_POINTS
assert len(_places(cid)) == MAX_PROOF_POINTS
def test_the_composer_is_asked_about_every_point_it_cannot_file(client):
client.put("/api/settings/prefs", json={"proof_place_auto": False})
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
saved = _save(client, cid, "Harbour strike", _points(
("64.1466, -21.9426", "impact 1", False),
("64.1502, -21.9350", "caméra", True),
))
assert saved["place"]["asking"] == [
{"lat": 64.1466, "lon": -21.9426, "label": "impact 1", "pov": False},
{"lat": 64.1502, "lon": -21.9350, "label": "caméra", "pov": True},
]
assert _places(cid) == []
filed = client.post(f"/api/cases/{cid}/proofs/Harbour strike/place").json()
assert sorted(one["label"] for one in filed) == ["caméra", "impact 1"]
# the yes reads the spec, so POV lands on the line that carries it
assert [lk["to"] for lk in _located_at(cid)] == [] # no material to place
def test_only_the_conclusion_is_looked_up_at_save(client, monkeypatch):
"""Geography is paced, so three points would hold the save for three seconds.
The Locate pass answers for the rest, exactly as an offline save already is."""
from azimut.engine import geo
asked: list[tuple[float, float]] = []
def _one(lat, lon, timeout=8, language=None):
asked.append((lat, lon))
return {
"display_name": "x",
"attribution": "x",
"address": {"country_code": "is", "country": "Ísland"},
}
monkeypatch.setattr(geo, "reverse_geocode", _one)
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
_save(client, cid, "Harbour strike", _points(
("64.1466, -21.9426", "impact 1", False),
("64.1481, -21.9401", "impact 2", False),
("64.1502, -21.9350", "caméra", True),
))
assert asked == [(64.1466, -21.9426)]
geo_by_label = {p["label"]: (p["attrs"].get("geo") or {}).get("country") for p in _places(cid)}
assert geo_by_label["impact 1"] == "Ísland"
assert geo_by_label["impact 2"] is None # born unlocated, for Locate to pick up
def test_stating_a_point_writes_the_list_and_the_mirror():
"""An older build has to find the conclusion where it has always been."""
from azimut.engine import satellite
spec = satellite.state_points({}, [{"coords": "64.1466, -21.9426", "pov": True}])
assert spec["points"] == [{"coords": "64.1466, -21.9426", "pov": True}]
assert spec["coordsText"] == "64.1466, -21.9426"
assert spec["pov"] is True
def test_stating_one_point_over_a_list_replaces_it(client):
"""A sheet cell must not be swallowed by a list the composer left behind."""
from azimut.engine import satellite
spec = _points(("64.1466, -21.9426", "impact 1", False), ("64.1502, -21.9350", "b", True))
satellite.state_points(spec, [{"coords": "48.8584, 2.2945"}])
assert satellite.spec_points(spec) == [
{"lat": 48.8584, "lon": 2.2945, "coords": "48.8584, 2.2945", "label": "", "pov": False}
]
def test_a_point_filed_by_another_road_is_a_place_of_its_own(client):
"""A sheet row files a point for a proof it never composed. The graph knew
two places while the composer opened on one, so the proof said two things."""
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
_save(client, cid, "Harbour strike", _points(("48.656140, 2.371511", "impact 1", False)))
case = Case.open(cid)
proof = _proof(cid)
# the road the sheet takes: its own place, its own provenance, no re-composition
elsewhere = client.post(
f"/api/cases/{cid}/satellite/place", json={"lat": 48.656289, "lon": 2.371885}
).json()
case.update_entity(elsewhere["id"], {"label": "impact 2"})
case.add_link(proof["id"], elsewhere["id"], "depicts", by="sheet-build")
assert sorted((p["attrs"]["lat"], p["label"]) for p in _places(cid)) == [
(48.65614, "impact 1"), (48.656289, "impact 2"),
]
# and the composer opens on both, the analyst's own row still the conclusion
spec = client.get(f"/api/cases/{cid}/proofs/Harbour strike").json()
assert [one["coords"] for one in spec["points"]] == ["48.656140, 2.371511", "48.656289, 2.371885"]
assert spec["points"][1]["label"] == "impact 2"
def _other_road(client, cid, lat, lon, label, *, material=(), verb="depicts"):
"""A point filed for a proof by a road that never wrote its composition.
What `api/sheetproofs._added_point` writes for the binder's cross-border shape: its
own place, its own provenance, the proof reaching it and the material posed on it.
"""
proof = _proof(cid)
case = Case.open(cid)
place = client.post(f"/api/cases/{cid}/satellite/place", json={"lat": lat, "lon": lon}).json()
case.update_entity(place["id"], {"label": label})
case.add_link(proof["id"], place["id"], "depicts", by="sheet-proofs")
for entity_id in material:
case.add_link(entity_id, place["id"], verb, by="sheet-proofs")
return place
def test_taking_off_a_point_another_road_filed_withdraws_it_for_good(client):
"""The composer opens on a point a sheet row filed, as an editable row. So deleting
that row has to mean what it says: read on its own provenance, the withdrawal found
nothing to take back, the save reported no orphan, and the next open adopted the
point again — a row that could not be deleted, coming back with no way to tell why."""
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
video = _video(cid)
spec = {
**_panels("media/clip.mp4"),
"points": [{"coords": "48.656140, 2.371511", "label": "impact 1", "pov": False}],
}
_save(client, cid, "Harbour strike", spec)
elsewhere = _other_road(client, cid, 48.656289, 2.371885, "impact 2", material=[video["id"]])
opened = client.get(f"/api/cases/{cid}/proofs/Harbour strike").json()
assert [one["label"] for one in opened["points"]] == ["impact 1", "impact 2"]
kept = {**opened, "points": opened["points"][:1]}
saved = _save(client, cid, "Harbour strike", kept)
# the proof's own edge and the footage the road posed with it, both taken back
assert [lk["from"] for lk in _depicts(cid) if lk["to"] == elsewhere["id"]] == []
assert saved["orphans"] == [{"id": elsewhere["id"], "label": "impact 2"}]
again = client.get(f"/api/cases/{cid}/proofs/Harbour strike").json()
assert [one["label"] for one in again["points"]] == ["impact 1"]
def test_a_point_kept_from_another_road_is_stated_rather_than_left_alone(client):
"""The other half of the same rule: a row the analyst leaves standing is a row the
proof now states itself, so its material carries the edge the composition means."""
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
video = _video(cid)
_save(client, cid, "Harbour strike", _with_coords("48.656140, 2.371511", None, "media/clip.mp4"))
elsewhere = _other_road(client, cid, 48.656289, 2.371885, "impact 2")
opened = client.get(f"/api/cases/{cid}/proofs/Harbour strike").json()
_save(client, cid, "Harbour strike", opened)
posed = {lk["from"] for lk in _depicts(cid) if lk["to"] == elsewhere["id"]}
assert {_proof(cid)["id"], video["id"]} <= posed
def test_a_point_a_second_proof_concludes_on_by_another_road_keeps_its_material(client):
"""`_other_proof_states` read one provenance, so a proof withdrawing its point took
the video off a place a sheet-built proof still concludes on."""
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
video = _video(cid)
spec = _with_coords("50.4501, 30.5234", None, "media/clip.mp4")
_save(client, cid, "First", spec)
shared = _places(cid)[0]
case = Case.open(cid)
other = case.add_entity("proof", "Built by the sheet", {"spec": "proofs/x.json"}, by="user")
case.add_link(other["id"], shared["id"], "depicts", by="sheet-proofs")
saved = _save(client, cid, "First", _with_coords("48.8584, 2.2945", None, "media/clip.mp4"))
assert saved["orphans"] == []
holding = {lk["from"] for lk in _depicts(cid) if lk["to"] == shared["id"]}
assert {video["id"], other["id"]} <= holding
def test_the_pov_of_an_adopted_point_is_read_off_this_proof_material(client):
"""POV says *this* proof's footage was recorded there. Read off any media standing
on the point, a second proof's video answered for this one — and the tick came back
on, in a composition whose own footage says nothing of the kind."""
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
_video(cid)
_save(client, cid, "Harbour strike", _with_coords("48.656140, 2.371511", None, "media/clip.mp4"))
somebody = _video(cid, "theirs.mp4")
elsewhere = _other_road(
client, cid, 48.656289, 2.371885, "impact 2",
material=[somebody["id"]], verb="located-at",
)
opened = client.get(f"/api/cases/{cid}/proofs/Harbour strike").json()
adopted = next(one for one in opened["points"] if one.get("label") == "impact 2")
assert adopted.get("pov") is not True
assert [lk["from"] for lk in _located_at(cid) if lk["to"] == elsewhere["id"]] == [
somebody["id"]
]
def test_reopening_a_proof_never_rewrites_what_was_typed(client):
"""Down to the format: somebody who works in DMS typed DMS."""
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
typed = "48°51'30.2\"N 2°17'40.2\"E"
_save(client, cid, "Typed", _points((typed, "", False)))
spec = client.get(f"/api/cases/{cid}/proofs/Typed").json()
assert [one["coords"] for one in spec["points"]] == [typed]
# -- a point nobody checked (the composer's "Later") -----------------------------
#
# The middle of a capture is a guess until somebody looks at it on the map. The
# composer walks each one through the map before a save, and a point saved without
# that check stays off the case map rather than landing there as a conclusion.
def test_an_unchecked_point_is_not_filed(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
spec = _points(("64.1466, -21.9426", "hangar", False), ("64.1502, -21.9350", "", False))
spec["points"][1]["proposed"] = True
saved = _save(client, cid, "Airbase", spec)
assert [p["attrs"]["lat"] for p in _places(cid)] == [64.1466]
assert [one["label"] for one in saved["place"]["filed"]] == ["hangar"]
# never asked about either: the composer just offered to check it
assert saved["place"]["asking"] == []
def test_an_unchecked_point_is_not_asked_about_when_filing_asks(client):
client.put("/api/settings/prefs", json={"proof_place_auto": False})
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
spec = _points(("64.1466, -21.9426", "", False))
spec["points"][0]["proposed"] = True
saved = _save(client, cid, "Airbase", spec)
assert saved.get("place") is None
# and the yes to an earlier question files nothing unchecked either
name = saved["name"]
assert client.post(f"/api/cases/{cid}/proofs/{name}/place").json() == []
assert _places(cid) == []
def test_the_panels_unchecked_answer_is_not_filed(client, sat_tiles):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
cap = _sat(client, cid, 50.4501, 30.5234)
_save(client, cid, "Unchecked", _with_coords(None, {"lat": 50.4501, "lon": 30.5234, "proposed": True}, cap["path"]))
assert _places(cid) == []
# once somebody checked it, the same answer is the conclusion
_save(client, cid, "Checked", _with_coords(None, {"lat": 50.4501, "lon": 30.5234}, cap["path"]))
assert [p["attrs"]["lat"] for p in _places(cid)] == [50.4501]
def test_a_point_already_on_the_map_stays_when_saved_unchecked(client):
"""An older proof reopened reads its capture as unchecked. Saving it for later
must not take back the place it filed before the check existed."""
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
_save(client, cid, "Airbase", _points(("64.1466, -21.9426", "", False)))
[place] = _places(cid)
spec = _points(("64.1466, -21.9426", "", False))
spec["points"][0]["proposed"] = True
saved = _save(client, cid, "Airbase", spec)
assert saved["orphans"] == []
assert [lk["to"] for lk in _depicts(cid)] == [place["id"]]
def test_an_unchecked_point_reopens_unchecked(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
spec = _points(("64.1466, -21.9426", "", False), ("64.1502, -21.9350", "", False))
spec["points"][1]["proposed"] = True
_save(client, cid, "Airbase", spec)
reopened = client.get(f"/api/cases/{cid}/proofs/Airbase").json()
assert [one.get("proposed") for one in reopened["points"]] == [None, True]
from azimut.engine import satellite
assert [one.get("proposed", False) for one in satellite.spec_points(reopened)] == [False, True]
written = satellite.state_points({}, satellite.spec_points(reopened))
assert written["points"][1] == {"coords": "64.1502, -21.9350", "proposed": True}
def test_a_capture_says_where_its_frame_was_centred(client, sat_tiles):
"""What tells the composer a pin was aimed: the point and the frame's centre
differ only when the pin was moved onto the target."""
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
client.post(
f"/api/cases/{cid}/satellite/capture",
json={"lat": 50.45, "lon": 30.52, "zoom": 16, "width": 256, "height": 256,
"marker_style": "pin", "marker_x": 40, "marker_y": -20,
"marker_lat": 50.4501, "marker_lon": 30.5234},
)
client.post(
f"/api/cases/{cid}/satellite/capture",
json={"lat": 48.85, "lon": 2.35, "zoom": 16, "width": 256, "height": 256},
)
captures = {c["lat"]: c for c in client.get(f"/api/cases/{cid}/satellite").json()}
assert (captures[50.4501]["center_lat"], captures[50.4501]["center_lon"]) == (50.45, 30.52)
assert (captures[48.85]["center_lat"], captures[48.85]["center_lon"]) == (48.85, 2.35)
def test_a_proof_the_panels_place_opens_with_an_empty_field(client, sat_tiles):
"""Nothing was typed, so nothing is written into the row: the field shows the
panels' own answer and the reset arrow stays away."""
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
cap = _sat(client, cid, 50.4501, 30.5234)
client.post(f"/api/cases/{cid}/proofs", json={"title": "Auto", "spec": _panels(cap["path"])})
spec = client.get(f"/api/cases/{cid}/proofs/Auto").json()
assert spec.get("points") in (None, [])
def test_the_date_and_the_description_travel_to_the_entity(client):
cid = client.post("/api/cases", json={"name": "Dated proof"}).json()["id"]
saved = client.post(
f"/api/cases/{cid}/proofs",
json={
"title": "Dated proof",
"spec": {
**SPEC,
"when": "2024-03-11~",
"description": "A formation of 13 helicopters heading east",
},
},
).json()
spec = client.get(f"/api/cases/{cid}/proofs/{saved['name']}").json()
assert spec["when"] == "2024-03-11~"
assert spec["description"] == "A formation of 13 helicopters heading east"
# On the entity too: the graph reads the date and the notes off the row it
# already holds, and the Timeline projects the proof from that attribute.
proof = next(e for e in graph_read.entities(cid) if e["type"] == "proof")
assert proof["attrs"]["when"] == "2024-03-11~"
assert proof["attrs"]["notes"] == "A formation of 13 helicopters heading east"
def test_a_dated_proof_states_its_date_on_the_timeline(client):
cid = client.post("/api/cases", json={"name": "Proof on the timeline"}).json()["id"]
client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Dated proof", "spec": {**SPEC, "when": "2024-03-11"}},
)
items = client.get(
f"/api/cases/{cid}/timeline", params={"categories": "statement"}
).json()["items"]
assert [(item["kind"], item["raw"]) for item in items] == [("taken", "2024-03-11")]
def test_a_date_outside_the_profile_is_refused_before_anything_moves(client):
cid = client.post("/api/cases", json={"name": "Bad date"}).json()["id"]
client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Dated proof", "spec": {**SPEC, "when": "2024-03-11"}},
)
refused = client.post(
f"/api/cases/{cid}/proofs",
json={
"rename_from": "Dated proof",
"title": "Renamed proof",
"spec": {**SPEC, "when": "late summer"},
},
)
assert refused.status_code == 422
# The rename never happened: the proof is still the one that was there.
assert [p["name"] for p in client.get(f"/api/cases/{cid}/proofs").json()] == [
"Dated proof"
]
spec = client.get(f"/api/cases/{cid}/proofs/Dated proof").json()
assert spec["when"] == "2024-03-11"
def test_clearing_the_date_takes_it_off_the_entity(client):
cid = client.post("/api/cases", json={"name": "Undated again"}).json()["id"]
client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Dated proof", "spec": {**SPEC, "when": "2024-03-11"}},
)
client.post(
f"/api/cases/{cid}/proofs",
json={"rename_from": "Dated proof", "title": "Dated proof", "spec": SPEC},
)
proof = next(e for e in graph_read.entities(cid) if e["type"] == "proof")
assert proof["attrs"]["when"] == ""
assert client.get(f"/api/cases/{cid}/proofs/Dated proof").json()["when"] is None
assert (
client.get(f"/api/cases/{cid}/timeline", params={"categories": "statement"})
.json()["items"]
== []
)
@pytest.mark.parametrize("cleared", ["", None])
def test_a_date_and_description_cleared_in_details_stay_cleared(client, cleared):
cid = client.post("/api/cases", json={"name": "Cleared in Details"}).json()["id"]
client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Dated", "spec": {**SPEC, "when": "2024-05-01", "description": "Seen from the bridge"}},
)
proof = next(e for e in graph_read.entities(cid) if e["type"] == "proof")
client.patch(
f"/api/cases/{cid}/entities/{proof['id']}", json={"attrs": {"when": cleared, "notes": cleared}}
)
opened = client.get(f"/api/cases/{cid}/proofs/Dated").json()
assert opened["when"] is None and opened["description"] is None
# the composer saves what it opened, and the date must not come back with it
client.post(f"/api/cases/{cid}/proofs", json={"rename_from": "Dated", "title": "Dated", "spec": opened})
proof = next(e for e in graph_read.entities(cid) if e["type"] == "proof")
assert proof["attrs"]["when"] == "" and proof["attrs"]["notes"] == ""
assert (
client.get(f"/api/cases/{cid}/timeline", params={"categories": "statement"}).json()["items"]
== []
)
def test_a_description_edited_in_the_graph_is_what_reopens(client):
cid = client.post("/api/cases", json={"name": "Edited notes"}).json()["id"]
client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Dated proof", "spec": {**SPEC, "description": "First reading"}},
)
proof = next(e for e in graph_read.entities(cid) if e["type"] == "proof")
client.patch(
f"/api/cases/{cid}/entities/{proof['id']}",
json={"attrs": {"notes": "Corrected reading", "when": "2024-03-12"}},
)
spec = client.get(f"/api/cases/{cid}/proofs/Dated proof").json()
assert spec["description"] == "Corrected reading"
assert spec["when"] == "2024-03-12"
def _collected_clip(cid, name="clip.png"):
"""A collected file, as a download would leave it."""
from azimut.engine import media as media_engine
return media_engine.import_image(
Case.open(cid),
Image.new("RGB", (48, 32), (30, 30, 30)),
name,
{"type": "download", "webpage_url": "https://x.com/a/status/1"},
by="ingest",
)["item"]["path"]
def _cut_frame(cid, parent, name="clip_frame.png"):
"""A frame cut out of it: the panel a proof actually composes."""
from azimut.engine import media as media_engine
return media_engine.import_image(
Case.open(cid),
Image.new("RGB", (48, 32), (60, 60, 60)),
name,
{"type": "derived", "op": "frame", "from": parent, "time": 69.0},
by="inspect",
)["item"]["path"]
def _claims(cid):
return [e for e in graph_read.entities(cid) if e["type"] == "claim"]
def test_the_date_states_itself_for_the_footage_behind_the_panel(client):
cid = client.post("/api/cases", json={"name": "Dated footage"}).json()["id"]
video = _collected_clip(cid)
frame = _cut_frame(cid, video)
saved = client.post(
f"/api/cases/{cid}/proofs",
json={
"title": "Dated proof",
"spec": {**_panels(frame), "when": "2024-03-11~"},
},
).json()
# The save says what it wrote, rather than filing into the graph in silence.
assert saved["dated"] == ["clip"]
claim = _claims(cid)[0]
assert claim["attrs"]["when"] == "2024-03-11~"
assert claim["attrs"]["time_role"] == "observed"
assert claim["label"] == "Material of Dated proof was taken"
# About the video, not about the frame cut out of it: the thing that was
# filmed is the one the date is a fact about.
entities = {e["id"]: e for e in graph_read.entities(cid)}
subjects = [
entities[link["to"]]["label"]
for link in graph_read.links(cid)
if link["from"] == claim["id"] and link["type"] == "about"
]
assert subjects == ["clip"]
cites = [
entities[link["to"]]["type"]
for link in graph_read.links(cid)
if link["from"] == claim["id"] and link["type"] == "cites"
]
assert cites == ["proof"]
def test_the_stated_date_shows_on_the_file_it_is_about(client):
cid = client.post("/api/cases", json={"name": "Seen from the video"}).json()["id"]
video = _collected_clip(cid)
client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Dated proof", "spec": {**_panels(video), "when": "2024-03-11"}},
)
media = next(e for e in graph_read.entities(cid) if e["type"] == "media")
page = client.get(
f"/api/cases/{cid}/timeline",
params={"entity": media["id"], "categories": ["statement", "media"]},
).json()
stated = [item for item in page["items"] if item["category"] == "statement"]
assert [item["raw"] for item in stated] == ["2024-03-11"]
# The file's own clock is untouched: the sidecar still says what it said.
item = client.get(f"/api/cases/{cid}/media/item", params={"path": video}).json()
assert "taken_at" not in item
def test_a_proofs_date_is_drawn_once_on_the_timeline(client):
"""The date is the footage's, stated by a Claim that cites the proof. While that
Claim says the proof's date, the proof's own row would be the same date twice."""
cid = client.post("/api/cases", json={"name": "Drawn once"}).json()["id"]
video = _collected_clip(cid)
client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Dated proof", "spec": {**_panels(video), "when": "2024-03-11"}},
)
def statements():
page = client.get(
f"/api/cases/{cid}/timeline", params={"categories": "statement"}
).json()
return page["total"], [(row["kind"], row["raw"]) for row in page["items"]]
assert statements() == (1, [("claim", "2024-03-11")])
# Restated by hand, the Claim is the analyst's own reading and no longer the
# proof's date, so the two are two dates again and both are drawn.
claim = _claims(cid)[0]
client.patch(f"/api/cases/{cid}/timeline/claims/{claim['id']}", json={"when": "2024-03-12"})
total, rows = statements()
assert total == 2
assert sorted(rows) == [("claim", "2024-03-12"), ("taken", "2024-03-11")]
def test_the_event_a_proof_dates_names_the_footage_it_puts_in_time(client):
"""The Timeline's Media lane draws a file where an event dates it: the event says
which file, the one it is about before the proof it cites."""
import json as json_module
cid = client.post("/api/cases", json={"name": "Situated footage"}).json()["id"]
video = _collected_clip(cid)
client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Dated proof", "spec": {**_panels(video), "when": "2024-03-11"}},
)
media = next(e for e in graph_read.entities(cid) if e["type"] == "media")
page = client.get(
f"/api/cases/{cid}/timeline",
params={"category": "statement", "track": json_module.dumps({"as_files": "sources"})},
).json()
[row] = page["items"]
assert row["kind"] == "claim"
assert row["file"]["id"] == media["id"]
assert row["file"]["type"] == "media"
assert row["file"]["label"] == media["label"]
def test_the_media_lane_holds_the_sources_and_the_imagery_lane_what_was_seen_from_above(client):
"""A Compare render or the picture Detect keeps is not a source's footage: the
events that date one are drawn on the Imagery lane, and only there. An event about
a video that cites a render is the video on one lane and the render on the other."""
import json as json_module
from azimut.engine import media as media_engine
cid = client.post("/api/cases", json={"name": "Two file lanes"}).json()["id"]
video = _collected_clip(cid)
rendered = media_engine.import_image(
Case.open(cid), Image.new("RGB", (48, 32), (90, 90, 90)), "render.png",
{"type": "compare"}, by="compare",
)["item"]["path"]
ids = {
entity["attrs"]["path"]: entity["id"]
for entity in graph_read.entities(cid) if entity["type"] == "media"
}
def claim(statement, **connectors):
client.post(
f"/api/cases/{cid}/timeline/claims",
json={"statement": statement, "when": "2024-03-11", **connectors},
).raise_for_status()
claim("Seen in the video", about=[ids[video]])
claim("A crater in the render", cites=[ids[rendered]])
claim("The video's crater", about=[ids[video]], cites=[ids[rendered]])
def lane(kind):
page = client.get(
f"/api/cases/{cid}/timeline",
params={"category": "statement", "track": json_module.dumps({"as_files": kind})},
).json()
return {row["label"]: row["file"]["id"] for row in page["items"]}
assert lane("sources") == {
"Seen in the video": ids[video], "The video's crater": ids[video],
}
assert lane("imagery") == {
"A crater in the render": ids[rendered], "The video's crater": ids[rendered],
}
# a lane that draws no files names none
plain = client.get(
f"/api/cases/{cid}/timeline", params={"category": "statement"}
).json()["items"]
assert len(plain) == 3 and not any("file" in row for row in plain)
def test_a_proofs_date_is_read_on_the_clock_of_its_point(client):
"""Footage from Kyiv is dated on Kyiv's clock unless the analyst says otherwise:
the day spans Kyiv's midnights on the Timeline, for the proof and for the footage."""
cid = client.post("/api/cases", json={"name": "Zoned proof"}).json()["id"]
video = _collected_clip(cid)
saved = client.post(
f"/api/cases/{cid}/proofs",
json={
"title": "Kyiv",
"spec": {**_with_coords("50.4501, 30.5234", None, video), "when": "2024-03-12"},
},
).json()
assert saved["when_zone"] == "Europe/Kyiv"
proof = next(e for e in graph_read.entities(cid) if e["type"] == "proof")
assert proof["attrs"]["when_zone"] == "Europe/Kyiv"
assert _claims(cid)[0]["attrs"]["when_zone"] == "Europe/Kyiv"
rows = client.get(
f"/api/cases/{cid}/timeline", params={"categories": "statement"}
).json()["items"]
assert {(row["earliest"], row["tz"]) for row in rows} == {
("2024-03-11T22:00:00.000000Z", "Europe/Kyiv"),
}
# Left at the point's, the spec keeps no pick, so moving the point moves the zone.
spec = client.get(f"/api/cases/{cid}/proofs/Kyiv").json()
assert spec.get("whenZone") is None
assert spec["whenZoneStated"] == "Europe/Kyiv"
def test_a_proof_date_read_in_another_zone_than_its_claim_is_drawn_twice(client):
"""The footage's Claim moved to UTC's day no longer says what the proof says,
so the proof's own Kyiv day comes back beside it."""
cid = client.post("/api/cases", json={"name": "Two clocks"}).json()["id"]
video = _collected_clip(cid)
client.post(
f"/api/cases/{cid}/proofs",
json={
"title": "Kyiv",
"spec": {**_with_coords("50.4501, 30.5234", None, video), "when": "2024-03-12"},
},
)
claim = _claims(cid)[0]
moved = client.patch(
f"/api/cases/{cid}/timeline/claims/{claim['id']}", json={"when_zone": "UTC"}
)
assert moved.status_code == 200, moved.text
rows = client.get(
f"/api/cases/{cid}/timeline", params={"categories": "statement"}
).json()["items"]
assert sorted((row["kind"], row["tz"]) for row in rows) == [
("claim", "UTC"), ("taken", "Europe/Kyiv"),
]
def test_a_time_typed_on_the_proof_is_placed_once_its_zone_is_known(client):
cid = client.post("/api/cases", json={"name": "Local clock"}).json()["id"]
client.post(
f"/api/cases/{cid}/proofs",
json={
"title": "Clock",
"spec": {**_with_coords("50.4501, 30.5234"), "when": "2024-07-12T14:30:00"},
},
)
rows = client.get(
f"/api/cases/{cid}/timeline", params={"categories": "statement"}
).json()["items"]
assert [(row["earliest"], row["zone"]) for row in rows] == [
("2024-07-12T11:30:00.000000Z", "named"),
]
def test_the_analyst_can_state_the_proofs_date_in_utc_instead(client):
cid = client.post("/api/cases", json={"name": "UTC proof"}).json()["id"]
client.post(
f"/api/cases/{cid}/proofs",
json={
"title": "Stamp",
"spec": {**_with_coords("50.4501, 30.5234"), "when": "2024-03-12", "whenZone": "UTC"},
},
)
spec = client.get(f"/api/cases/{cid}/proofs/Stamp").json()
assert spec["whenZone"] == "UTC"
proof = next(e for e in graph_read.entities(cid) if e["type"] == "proof")
assert proof["attrs"]["when_zone"] == "UTC"
refused = client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Stamp", "spec": {**SPEC, "when": "2024-03-12", "whenZone": "Mars/Base"}},
)
assert refused.status_code == 422
def test_a_zone_set_in_details_opens_as_the_analysts_pick(client):
cid = client.post("/api/cases", json={"name": "Zone from Details"}).json()["id"]
client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Kyiv", "spec": {**_with_coords("50.4501, 30.5234"), "when": "2024-03-12"}},
)
proof = next(e for e in graph_read.entities(cid) if e["type"] == "proof")
patched = client.patch(
f"/api/cases/{cid}/entities/{proof['id']}", json={"attrs": {"when_zone": "Europe/Warsaw"}}
)
assert patched.status_code == 200, patched.text
spec = client.get(f"/api/cases/{cid}/proofs/Kyiv").json()
assert spec["whenZone"] == "Europe/Warsaw"
assert spec["whenZoneStated"] == "Europe/Warsaw"
def test_a_proof_with_no_point_keeps_a_utc_day_and_no_zone(client):
cid = client.post("/api/cases", json={"name": "Nowhere yet"}).json()["id"]
saved = client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Undated place", "spec": {**_panels(), "when": "2024-03-12"}},
).json()
assert saved["when_zone"] is None
proof = next(e for e in graph_read.entities(cid) if e["type"] == "proof")
assert "when_zone" not in proof["attrs"]
rows = client.get(
f"/api/cases/{cid}/timeline", params={"categories": "statement"}
).json()["items"]
assert [row["earliest"] for row in rows] == ["2024-03-12T00:00:00.000000Z"]
def test_a_satellite_capture_is_never_dated_by_the_proof(client, sat_tiles):
cid = client.post("/api/cases", json={"name": "Reference imagery"}).json()["id"]
cap = _sat(client, cid, 50.4501, 30.5234)
saved = client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Dated proof", "spec": {**_panels(cap["path"]), "when": "2024-03-11"}},
).json()
# Its date is the provider's flyover, and the proof has nothing to say about it.
assert saved["dated"] == []
assert _claims(cid) == []
def test_re_saving_restates_the_date_rather_than_filing_a_second_one(client):
cid = client.post("/api/cases", json={"name": "Restated"}).json()["id"]
video = _collected_clip(cid)
body = {"title": "Dated proof", "spec": {**_panels(video), "when": "2024-03-11"}}
client.post(f"/api/cases/{cid}/proofs", json=body)
client.post(
f"/api/cases/{cid}/proofs",
json={
"rename_from": "Dated proof",
"title": "Renamed proof",
"spec": {**_panels(video), "when": "2024-03-12"},
},
)
claims = _claims(cid)
assert len(claims) == 1
assert claims[0]["attrs"]["when"] == "2024-03-12"
# The statement follows the rename, like every other file the proof owns.
assert claims[0]["label"] == "Material of Renamed proof was taken"
def test_clearing_the_date_takes_the_statement_back(client):
cid = client.post("/api/cases", json={"name": "Withdrawn"}).json()["id"]
video = _collected_clip(cid)
client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Dated proof", "spec": {**_panels(video), "when": "2024-03-11"}},
)
client.post(
f"/api/cases/{cid}/proofs",
json={"rename_from": "Dated proof", "title": "Dated proof", "spec": _panels(video)},
)
assert _claims(cid) == []
def test_a_statement_the_analyst_worked_on_is_not_deleted_from_the_composer(client):
cid = client.post("/api/cases", json={"name": "Enriched"}).json()["id"]
video = _collected_clip(cid)
client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Dated proof", "spec": {**_panels(video), "when": "2024-03-11"}},
)
claim = _claims(cid)[0]
client.patch(
f"/api/cases/{cid}/entities/{claim['id']}",
json={"attrs": {"method": "Matched against the shadow length"}},
)
client.post(
f"/api/cases/{cid}/proofs",
json={"rename_from": "Dated proof", "title": "Dated proof", "spec": _panels(video)},
)
# Clearing a field in the composer must not delete reasoning written elsewhere.
kept = _claims(cid)
assert len(kept) == 1
assert kept[0]["attrs"]["method"] == "Matched against the shadow length"
def test_a_source_taken_off_the_proof_is_no_longer_dated_by_it(client):
cid = client.post("/api/cases", json={"name": "Two clips"}).json()["id"]
first = _collected_clip(cid, "first.png")
second = _collected_clip(cid, "second.png")
client.post(
f"/api/cases/{cid}/proofs",
json={
"title": "Dated proof",
"spec": {**_panels(first, second), "when": "2024-03-11"},
},
)
client.post(
f"/api/cases/{cid}/proofs",
json={
"rename_from": "Dated proof",
"title": "Dated proof",
"spec": {**_panels(first), "when": "2024-03-11"},
},
)
claim = _claims(cid)[0]
entities = {e["id"]: e for e in graph_read.entities(cid)}
subjects = sorted(
entities[link["to"]]["label"]
for link in graph_read.links(cid)
if link["from"] == claim["id"] and link["type"] == "about"
)
assert subjects == ["first"]
def test_a_statement_reworded_by_hand_keeps_its_own_wording(client):
cid = client.post("/api/cases", json={"name": "Reworded"}).json()["id"]
video = _collected_clip(cid)
client.post(
f"/api/cases/{cid}/proofs",
json={"title": "Dated proof", "spec": {**_panels(video), "when": "2024-03-11"}},
)
claim = _claims(cid)[0]
client.patch(
f"/api/cases/{cid}/entities/{claim['id']}",
json={"label": "The convoy was filmed that morning"},
)
client.post(
f"/api/cases/{cid}/proofs",
json={
"rename_from": "Dated proof",
"title": "Dated proof",
"spec": {**_panels(video), "when": "2024-03-12"},
},
)
restated = _claims(cid)[0]
assert restated["label"] == "The convoy was filmed that morning"
assert restated["attrs"]["when"] == "2024-03-12" # the date is still restated
def test_a_proof_named_with_a_hash_is_opened_and_deleted_on_its_own(client):
from urllib.parse import quote
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
for title in ("Ops", "Ops #2"):
client.post(f"/api/cases/{cid}/proofs", json={"title": title, "spec": SPEC, "png_base64": _png_b64()})
assert client.get(f"/api/cases/{cid}/proofs/{quote('Ops #2', safe='')}").json()["title"] == "Ops #2"
assert client.delete(f"/api/cases/{cid}/proofs/{quote('Ops #2', safe='')}").status_code == 200
assert [row["name"] for row in client.get(f"/api/cases/{cid}/proofs").json()] == ["Ops"]
@pytest.mark.parametrize("folded", [False, True], ids=["linux", "windows-macos"])
def test_a_change_of_case_renames_the_proof_and_its_picture_in_place(client, monkeypatch, folded):
import casefold
from azimut import layout
from azimut.workspace import Case
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
client.post(f"/api/cases/{cid}/proofs", json={"title": "Roof", "spec": SPEC, "png_base64": _png_b64()})
if folded:
casefold.fold_names(monkeypatch, "proofs")
renamed = client.post(
f"/api/cases/{cid}/proofs", json={"title": "roof", "rename_from": "Roof", "spec": SPEC}
)
assert renamed.status_code == 200, renamed.text
case = Case.open(cid)
assert [p.name for p in (case.tool_root / "proofs" / layout.META_DIR).glob("*.json")] == ["roof.json"]
assert [p.name for p in (case.tool_root / "proofs").glob("*.png")] == ["roof.png"]
assert client.get(f"/api/cases/{cid}/proofs/roof").json()["title"] == "roof"
def test_two_proofs_differing_only_by_case_cannot_both_be_saved(client):
cid = client.post("/api/cases", json={"name": "Proofs"}).json()["id"]
client.post(f"/api/cases/{cid}/proofs", json={"title": "Roof", "spec": SPEC})
assert client.post(f"/api/cases/{cid}/proofs", json={"title": "roof", "spec": SPEC}).status_code == 409