feature:verlauf backup papierkorb
This commit is contained in:
1 parent
4cb6cd8cf9
commit
8b383d2552
41 files changed
+4369
-641
No files matched your search
@@ -0,0 +1,337 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""Verlauf und Papierkorb gegen PostgreSQL: punktuell wiederherstellen, Überbuchung,
|
||||
Löschen durch Teilnehmende, gelöschte Personen, Aufbewahrung (CI)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
pytest.importorskip("fastapi")
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
from helpers import new_client, token_for
|
||||
from sqlalchemy import func, select, update
|
||||
from sqlalchemy.orm import Session
|
||||
from test_forms import (
|
||||
creator,
|
||||
fill,
|
||||
form_row,
|
||||
participant,
|
||||
question_ids,
|
||||
save_settings,
|
||||
simple_form,
|
||||
)
|
||||
from test_mail import admin
|
||||
from test_phase5 import bookings, options_of, slot_form
|
||||
|
||||
from surveybox import db
|
||||
from surveybox.forms import erasure, history
|
||||
from surveybox.models import (
|
||||
Answer,
|
||||
Form,
|
||||
FormSnapshot,
|
||||
FormTrash,
|
||||
Response,
|
||||
UserAccount,
|
||||
)
|
||||
from surveybox.settings import get_settings
|
||||
|
||||
pytestmark = pytest.mark.db
|
||||
|
||||
|
||||
def snapshots(pid: str) -> list[tuple[int, str, history.Payload]]:
|
||||
"""(Kennung, Anlass, Inhalt) aller Stände eines Formulars, älteste zuerst."""
|
||||
form_id = form_row(pid).id
|
||||
with Session(db.get_engine()) as s:
|
||||
rows = list(s.scalars(select(FormSnapshot).where(FormSnapshot.form_id == form_id)
|
||||
.order_by(FormSnapshot.created_at, FormSnapshot.id)))
|
||||
return [(r.id, r.reason, history.unpack(r)) for r in rows]
|
||||
|
||||
|
||||
def responses_of(pid: str) -> list[Response]:
|
||||
with Session(db.get_engine()) as s:
|
||||
rows = list(s.scalars(select(Response).where(Response.form_id == form_row(pid).id)
|
||||
.order_by(Response.id)))
|
||||
for row in rows:
|
||||
s.expunge(row)
|
||||
return rows
|
||||
|
||||
|
||||
def restore(client: TestClient, pid: str, snapshot_id: int, *items: str) -> Any:
|
||||
url = f"/forms/{pid}/history/{snapshot_id}"
|
||||
return client.post(f"{url}/restore",
|
||||
data={"csrf_token": token_for(client, url), "item": list(items)})
|
||||
|
||||
|
||||
def remove_option(client: TestClient, pid: str, qid: int, keep: str) -> None:
|
||||
csrf = token_for(client, f"/forms/{pid}/questions/{qid}")
|
||||
resp = client.post(f"/forms/{pid}/questions/{qid}", data={
|
||||
"csrf_token": csrf, "label": "Schicht", "slot_mode": "list",
|
||||
"option_id": [keep], "option_label": ["Spät"], "option_capacity": [""]})
|
||||
assert resp.status_code == 303, resp.text
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Der Fall aus der Praxis: gebuchte Option gelöscht, einzeln zurückholen
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_restore_deleted_booked_option_only(app: Any) -> None:
|
||||
owner = creator(app)
|
||||
pid, token, qid, (early, late) = slot_form(owner, capacity="2")
|
||||
assert fill(new_client(app), token, {f"q{qid}": early}).status_code == 303 # Anna
|
||||
assert fill(new_client(app), token, {f"q{qid}": late}).status_code == 303 # Bert
|
||||
remove_option(owner, pid, qid, late)
|
||||
assert [b[0] for b in bookings(qid)] == [late]
|
||||
# Danach geht es weiter: neue Antwort, neuer Titel
|
||||
assert fill(new_client(app), token, {f"q{qid}": late}).status_code == 303 # Carl
|
||||
assert save_settings(owner, pid, title="Herbstfest", access="link").status_code == 303
|
||||
|
||||
found = [s for s in snapshots(pid)
|
||||
if any(o.get("id") == early for q in s[2].rows("question")
|
||||
for o in (q["config"] or {}).get("options") or [])]
|
||||
snapshot_id = found[-1][0] # der Stand direkt vor dem Streichen
|
||||
page = owner.get(f"/forms/{pid}/history/{snapshot_id}").text
|
||||
assert f'value="opt:{qid}:{early}"' in page and "Früh" in page
|
||||
assert "1 booked place" in page
|
||||
|
||||
resp = restore(owner, pid, snapshot_id, f"opt:{qid}:{early}")
|
||||
assert resp.status_code == 303 and "history_restored" in resp.headers["location"]
|
||||
assert [o["id"] for o in options_of(qid)] == [early, late]
|
||||
assert sorted(b[0] for b in bookings(qid)) == sorted([early, late, late])
|
||||
# Alles andere bleibt, wie es ist
|
||||
assert form_row(pid).title == "Herbstfest"
|
||||
assert len(responses_of(pid)) == 3
|
||||
# Vorher wurde der jetzige Stand gesichert
|
||||
assert snapshots(pid)[-1][1] == "before_restore"
|
||||
|
||||
|
||||
def test_restore_nothing_selected(app: Any) -> None:
|
||||
owner = creator(app)
|
||||
pid, _, qid, (_, late) = slot_form(owner)
|
||||
remove_option(owner, pid, qid, late)
|
||||
snapshot_id = snapshots(pid)[-1][0]
|
||||
resp = restore(owner, pid, snapshot_id)
|
||||
assert resp.status_code == 400 and "Please choose at least one" in resp.text
|
||||
resp = restore(owner, pid, snapshot_id, "opt:999:x", "setting:status")
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Antworten: von Verwaltern gelöscht, zurück trotz voller Plätze
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_restore_deleted_answer_overbooks(app: Any) -> None:
|
||||
owner = creator(app)
|
||||
pid, token, qid, (early, _) = slot_form(owner, capacity="1")
|
||||
assert fill(new_client(app), token, {f"q{qid}": early}).status_code == 303
|
||||
(first,) = responses_of(pid)
|
||||
url = f"/forms/{pid}/responses/{first.public_id}"
|
||||
resp = owner.post(f"{url}/delete", data={"csrf_token": token_for(owner, url),
|
||||
"confirm": "on"})
|
||||
assert resp.status_code == 303
|
||||
# Der frei gewordene Platz ist inzwischen vergeben
|
||||
assert fill(new_client(app), token, {f"q{qid}": early}).status_code == 303
|
||||
|
||||
snapshot_id, reason, _ = snapshots(pid)[-1]
|
||||
assert reason == "answer_delete"
|
||||
page = owner.get(f"/forms/{pid}/history/{snapshot_id}").text
|
||||
assert f'value="r_del:{first.id}"' in page
|
||||
assert restore(owner, pid, snapshot_id, f"r_del:{first.id}").status_code == 303
|
||||
assert len(responses_of(pid)) == 2
|
||||
assert [b[:2] for b in bookings(qid)] == [(early, "confirmed"), (early, "confirmed")]
|
||||
assert "More places are booked than available" in owner.get(f"/forms/{pid}/history").text
|
||||
assert "More places are booked than available" in owner.get(f"/forms/{pid}").text
|
||||
assert "overbooked" in owner.get(f"/forms/{pid}/responses").text
|
||||
|
||||
|
||||
def test_restore_deleted_question_with_answers(app: Any) -> None:
|
||||
owner = creator(app)
|
||||
pid, token, (q_name, q_food) = simple_form(owner, access="link")
|
||||
for name in ("Anna", "Bert"):
|
||||
assert fill(new_client(app), token, {f"q{q_name}": name}).status_code == 303
|
||||
csrf = token_for(owner, f"/forms/{pid}/questions/{q_name}")
|
||||
resp = owner.post(f"/forms/{pid}/questions/{q_name}/delete",
|
||||
data={"csrf_token": csrf, "confirm": "on"})
|
||||
assert resp.status_code == 303
|
||||
assert question_ids(pid) == [q_food]
|
||||
snapshot_id = snapshots(pid)[-1][0]
|
||||
assert "With 2 answers" in owner.get(f"/forms/{pid}/history/{snapshot_id}").text
|
||||
assert restore(owner, pid, snapshot_id, f"q_del:{q_name}").status_code == 303
|
||||
assert question_ids(pid) == [q_name, q_food] # wieder an erster Stelle
|
||||
with Session(db.get_engine()) as s:
|
||||
texts = sorted(s.scalars(select(Answer.value_text).where(Answer.question_id == q_name)))
|
||||
assert texts == ["Anna", "Bert"]
|
||||
|
||||
|
||||
def test_restore_setting_only(app: Any) -> None:
|
||||
owner = creator(app)
|
||||
pid, _, _ = simple_form(owner, access="link")
|
||||
assert save_settings(owner, pid, title="Neu", access="link",
|
||||
closes_at="2030-01-01T10:00").status_code == 303
|
||||
snapshot_id = snapshots(pid)[-1][0]
|
||||
page = owner.get(f"/forms/{pid}/history/{snapshot_id}").text
|
||||
assert 'value="setting:title"' in page and 'value="setting:closes_at"' in page
|
||||
assert restore(owner, pid, snapshot_id, "setting:title").status_code == 303
|
||||
row = form_row(pid)
|
||||
assert row.title == "Sommerfest" and row.closes_at is not None
|
||||
|
||||
|
||||
def test_participant_edits_are_not_offered(app: Any) -> None:
|
||||
owner = creator(app)
|
||||
pid, token, (q_name, _) = simple_form(owner, access="users")
|
||||
paul = participant(app)
|
||||
assert fill(paul, token, {f"q{q_name}": "Paul"}).status_code == 303
|
||||
assert save_settings(owner, pid, title="Neu").status_code == 303 # neuer Stand
|
||||
assert fill(paul, token, {f"q{q_name}": "Paula"}, path="/edit").status_code == 303
|
||||
snapshot_id = snapshots(pid)[-1][0]
|
||||
assert "r_chg:" not in owner.get(f"/forms/{pid}/history/{snapshot_id}").text
|
||||
|
||||
|
||||
def test_history_needs_edit_rights(app: Any) -> None:
|
||||
from test_media_team import add_member
|
||||
|
||||
owner = creator(app)
|
||||
pid, _, _ = simple_form(owner, access="link")
|
||||
assert save_settings(owner, pid, title="Neu", access="link").status_code == 303
|
||||
snapshot_id = snapshots(pid)[-1][0]
|
||||
editor = participant(app, "erik@example.de")
|
||||
evaluator = participant(app, "eva@example.de")
|
||||
add_member(owner, pid, "erik@example.de", "editor")
|
||||
add_member(owner, pid, "eva@example.de", "evaluator")
|
||||
assert editor.get(f"/forms/{pid}/history").status_code == 200
|
||||
assert editor.get(f"/forms/{pid}/history/{snapshot_id}").status_code == 200
|
||||
for other in (evaluator, participant(app)):
|
||||
assert other.get(f"/forms/{pid}/history").status_code in (403, 404)
|
||||
assert other.get(f"/forms/{pid}/history/{snapshot_id}").status_code in (403, 404)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Datenschutz
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_self_deleted_answer_leaves_history(app: Any) -> None:
|
||||
owner = creator(app)
|
||||
pid, token, (q_name, _) = simple_form(owner, access="link")
|
||||
assert fill(new_client(app), token, {f"q{q_name}": "Anna"}).status_code == 303
|
||||
assert save_settings(owner, pid, title="Neu", access="link").status_code == 303
|
||||
(response,) = responses_of(pid)
|
||||
assert any(r["id"] == response.id for _, _, p in snapshots(pid) for r in p.rows("response"))
|
||||
with Session(db.get_engine()) as s:
|
||||
row = s.get(Response, response.id)
|
||||
assert row is not None
|
||||
erasure.delete_response(s, get_settings(), row) # wie über den persönlichen Link
|
||||
s.commit()
|
||||
assert not any(p.rows("response") for _, _, p in snapshots(pid))
|
||||
snapshot_id = snapshots(pid)[-1][0]
|
||||
assert "r_del:" not in owner.get(f"/forms/{pid}/history/{snapshot_id}").text
|
||||
|
||||
|
||||
def test_erased_user_leaves_history(app: Any) -> None:
|
||||
owner = creator(app)
|
||||
pid, token, (q_name, _) = simple_form(owner, access="users", deletion_mode="delete")
|
||||
paul = participant(app)
|
||||
assert fill(paul, token, {f"q{q_name}": "Paul"}).status_code == 303
|
||||
assert save_settings(owner, pid, title="Neu", deletion_mode="delete").status_code == 303
|
||||
with Session(db.get_engine()) as s:
|
||||
user = s.scalar(select(UserAccount).where(UserAccount.email == "paul@example.de"))
|
||||
assert user is not None
|
||||
user_id = user.id
|
||||
erasure.erase_user(s, get_settings(), user, {}, actor_id=None)
|
||||
s.commit()
|
||||
for _, _, payload in snapshots(pid):
|
||||
assert not any(r.get("user_id") == user_id for r in payload.rows("response"))
|
||||
with Session(db.get_engine()) as s:
|
||||
assert not s.scalar(select(func.count()).select_from(FormSnapshot)
|
||||
.where(FormSnapshot.user_ids.contains([user_id])))
|
||||
|
||||
|
||||
def test_retention_removes_history(app: Any) -> None:
|
||||
from surveybox.forms import retention
|
||||
|
||||
owner = creator(app)
|
||||
pid, token, (q_name, _) = simple_form(owner, access="link")
|
||||
assert fill(new_client(app), token, {f"q{q_name}": "Anna"}).status_code == 303
|
||||
assert save_settings(owner, pid, title="Neu", access="link").status_code == 303
|
||||
assert snapshots(pid)
|
||||
with Session(db.get_engine()) as s:
|
||||
form = s.get(Form, form_row(pid).id)
|
||||
assert form is not None
|
||||
retention.apply(s, form, datetime.now(UTC))
|
||||
s.commit()
|
||||
assert snapshots(pid) == []
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Papierkorb und Aufbewahrung
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_trash_and_restore_form(app: Any) -> None:
|
||||
owner = creator(app)
|
||||
pid, token, (q_name, q_food) = simple_form(owner, access="link")
|
||||
assert fill(new_client(app), token, {f"q{q_name}": "Anna"}).status_code == 303
|
||||
csrf = token_for(owner, f"/forms/{pid}/settings")
|
||||
resp = owner.post(f"/forms/{pid}/delete", data={"csrf_token": csrf, "confirm": "on"})
|
||||
assert resp.status_code == 303 and "form_trashed" in resp.headers["location"]
|
||||
assert new_client(app).get(f"/f/{token}").status_code == 404
|
||||
listing = owner.get("/forms").text
|
||||
assert "Trash" in listing and f"/forms/trash/{pid}/restore" in listing
|
||||
# Andere sehen den Papierkorb nicht und können nichts zurückholen
|
||||
other = creator(app, "otto@example.de")
|
||||
assert f"/forms/trash/{pid}/restore" not in other.get("/forms").text
|
||||
csrf = token_for(other, "/forms")
|
||||
assert other.post(f"/forms/trash/{pid}/restore",
|
||||
data={"csrf_token": csrf}).status_code == 404
|
||||
|
||||
csrf = token_for(owner, "/forms")
|
||||
resp = owner.post(f"/forms/trash/{pid}/restore", data={"csrf_token": csrf})
|
||||
assert resp.status_code == 303 and "form_restored" in resp.headers["location"]
|
||||
assert question_ids(pid) == [q_name, q_food]
|
||||
assert len(responses_of(pid)) == 1
|
||||
assert new_client(app).get(f"/f/{token}").status_code == 200
|
||||
with Session(db.get_engine()) as s:
|
||||
assert s.scalar(select(func.count()).select_from(FormTrash)) == 0
|
||||
|
||||
|
||||
def test_prune_expired(app: Any) -> None:
|
||||
owner = creator(app)
|
||||
pid, _, _ = simple_form(owner, access="link")
|
||||
assert save_settings(owner, pid, title="Neu", access="link").status_code == 303
|
||||
keep_pid, _, _ = simple_form(owner, access="link")
|
||||
csrf = token_for(owner, f"/forms/{keep_pid}/settings")
|
||||
owner.post(f"/forms/{keep_pid}/delete", data={"csrf_token": csrf, "confirm": "on"})
|
||||
form_id = form_row(pid).id
|
||||
old = datetime.now(UTC) - timedelta(days=history.DEFAULT_HISTORY_DAYS + 1)
|
||||
with Session(db.get_engine()) as s:
|
||||
s.execute(update(FormSnapshot).values(created_at=old))
|
||||
s.execute(update(FormTrash).values(
|
||||
deleted_at=datetime.now(UTC) - timedelta(days=history.DEFAULT_TRASH_DAYS + 1)))
|
||||
s.commit()
|
||||
assert history.prune(s, datetime.now(UTC)) >= 2
|
||||
s.commit()
|
||||
assert s.scalar(select(func.count()).select_from(FormSnapshot)) == 0
|
||||
assert s.scalar(select(func.count()).select_from(FormTrash)) == 0
|
||||
# Der tägliche Stand legt wieder einen an
|
||||
assert history.daily(s, datetime.now(UTC)) == 1
|
||||
s.commit()
|
||||
assert s.scalar(select(FormSnapshot.form_id)) == form_id
|
||||
assert history.daily(s, datetime.now(UTC)) == 0 # nichts geändert
|
||||
|
||||
|
||||
def test_instance_settings(app: Any) -> None:
|
||||
client = admin(app)
|
||||
url = "/admin/settings"
|
||||
resp = client.post(f"{url}/history", data={"csrf_token": token_for(client, url),
|
||||
"history_days": "30", "trash_days": "7"})
|
||||
assert resp.status_code == 303 and "settings_saved" in resp.headers["location"]
|
||||
resp = client.post(f"{url}/history", data={"csrf_token": token_for(client, url),
|
||||
"history_days": "0", "trash_days": "7"})
|
||||
assert "error=history" in resp.headers["location"]
|
||||
with Session(db.get_engine()) as s:
|
||||
assert history.history_days(s) == 30 and history.trash_days(s) == 7
|
||||
@@ -0,0 +1,132 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""Verlauf der Formulare ohne Datenbank: Kodierung, Prüfsummen, Vergleich, Bereinigung."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
from datetime import UTC, date, datetime, time
|
||||
from decimal import Decimal
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
pytest.importorskip("sqlalchemy")
|
||||
|
||||
from surveybox.forms import history
|
||||
from surveybox.forms.booking import Availability
|
||||
|
||||
|
||||
def test_values_survive_encoding() -> None:
|
||||
values = [None, True, 3, 1.5, "Text", Decimal("12.500000"),
|
||||
datetime(2026, 11, 26, 9, 30, tzinfo=UTC), date(2026, 11, 26), time(9, 30),
|
||||
uuid.uuid4(), b"\x00\xffmarker", {"selected": ["a", "b"]}, ["x", 1]]
|
||||
for value in values:
|
||||
assert history.decode_value(history.encode_value(value)) == value
|
||||
|
||||
|
||||
def payload(**tables: list[dict[str, Any]]) -> history.Payload:
|
||||
return history.Payload(1, dict(tables))
|
||||
|
||||
|
||||
def form_row(**values: Any) -> dict[str, Any]:
|
||||
return {"id": 1, "title": "Sommerfest", "updated_at": datetime(2026, 1, 1, tzinfo=UTC),
|
||||
**values}
|
||||
|
||||
|
||||
def test_hash_ignores_updated_at_and_separates_answers() -> None:
|
||||
base = payload(form=[form_row()], response=[{"id": 5, "form_id": 1}])
|
||||
touched = payload(form=[form_row(updated_at=datetime(2026, 2, 1, tzinfo=UTC))],
|
||||
response=[{"id": 5, "form_id": 1}])
|
||||
assert history.pack(base).full_hash == history.pack(touched).full_hash
|
||||
renamed = payload(form=[form_row(title="Herbstfest")], response=[{"id": 5, "form_id": 1}])
|
||||
assert history.pack(base).full_hash != history.pack(renamed).full_hash
|
||||
# Nur Einstellungen geändert: Antworten-Prüfsumme bleibt (Entprellen)
|
||||
assert history.pack(base).data_hash == history.pack(renamed).data_hash
|
||||
more = payload(form=[form_row()], response=[{"id": 5, "form_id": 1},
|
||||
{"id": 6, "form_id": 1}])
|
||||
assert history.pack(base).data_hash != history.pack(more).data_hash
|
||||
|
||||
|
||||
def question(**values: Any) -> dict[str, Any]:
|
||||
return {"id": 7, "label": "Schicht", "help_text": None, "required": False,
|
||||
"personal": False, "config": {"options": [{"id": "a", "label": "Früh"},
|
||||
{"id": "b", "label": "Spät"}]},
|
||||
**values}
|
||||
|
||||
|
||||
def test_removed_option_is_not_a_changed_question() -> None:
|
||||
old = question()
|
||||
fewer = question(config={"options": [{"id": "b", "label": "Spät"}]})
|
||||
added = question(config={"options": [{"id": "a", "label": "Früh"},
|
||||
{"id": "b", "label": "Spät"},
|
||||
{"id": "c", "label": "Abend"}]})
|
||||
relabeled = question(config={"options": [{"id": "a", "label": "Morgens"},
|
||||
{"id": "b", "label": "Spät"}]})
|
||||
confirmed = question(config={**old["config"], "confirmed": ["a"]})
|
||||
assert not history._definition_differs(old, fewer)
|
||||
assert not history._definition_differs(old, added)
|
||||
assert not history._definition_differs(old, confirmed)
|
||||
assert history._definition_differs(old, relabeled)
|
||||
assert history._definition_differs(old, question(label="Dienst"))
|
||||
|
||||
|
||||
def test_compare_lists_deleted_question_and_removed_option() -> None:
|
||||
old = payload(form=[form_row()],
|
||||
question=[question(position=0), question(id=8, label="Name", position=1)],
|
||||
answer=[{"question_id": 8, "response_id": 1},
|
||||
{"question_id": 7, "response_id": 1}],
|
||||
booking=[{"question_id": 7, "option_id": "a", "response_id": 1}])
|
||||
now = payload(form=[form_row()],
|
||||
question=[question(position=0,
|
||||
config={"options": [{"id": "b", "label": "Spät"}]})])
|
||||
result = history.Comparison(snapshot=None) # type: ignore[arg-type]
|
||||
history._compare_questions(old, now, result)
|
||||
keys = {item.key: item for item in result.questions}
|
||||
assert set(keys) == {"q_del:8", "opt:7:a"}
|
||||
assert keys["q_del:8"].answers == 1
|
||||
assert keys["opt:7:a"].bookings == 1 and keys["opt:7:a"].title == "Früh"
|
||||
|
||||
|
||||
def test_settings_compare_only_known_fields() -> None:
|
||||
old = payload(form=[form_row(closes_at=None, status="open")])
|
||||
now = payload(form=[form_row(title="Neu", closes_at=datetime(2026, 12, 1, tzinfo=UTC),
|
||||
status="closed")])
|
||||
result = history.Comparison(snapshot=None) # type: ignore[arg-type]
|
||||
history._compare_settings(old, now, result)
|
||||
assert [i.key for i in result.settings] == ["setting:title", "setting:closes_at"]
|
||||
|
||||
|
||||
def test_drop_responses_removes_dependent_rows() -> None:
|
||||
data = payload(response=[{"id": 1}, {"id": 2}],
|
||||
answer=[{"response_id": 1}, {"response_id": 2}],
|
||||
booking=[{"response_id": 1}], response_note=[{"response_id": 1}],
|
||||
media_file=[{"response_id": 1, "storage_key": "k1"},
|
||||
{"response_id": None, "storage_key": "k2"}])
|
||||
assert history._drop_responses(data, {1})
|
||||
assert [r["id"] for r in data.rows("response")] == [2]
|
||||
assert data.rows("answer") == [{"response_id": 2}]
|
||||
assert data.rows("booking") == [] and data.rows("response_note") == []
|
||||
assert [m["storage_key"] for m in data.rows("media_file")] == ["k2"]
|
||||
assert not history._drop_responses(data, {99})
|
||||
|
||||
|
||||
def test_people_index() -> None:
|
||||
data = payload(form=[form_row(owner_id=3)],
|
||||
response=[{"id": 1, "user_id": 4, "guest_contact_id": None},
|
||||
{"id": 2, "user_id": None, "guest_contact_id": 9}],
|
||||
response_note=[{"author_id": 5}], form_access=[{"user_id": None}])
|
||||
assert history._people(data) == ([3, 4, 5], [9])
|
||||
|
||||
|
||||
def test_conditions_on_missing_questions_are_dropped() -> None:
|
||||
config = {"condition": {"mode": "all", "rules": [{"q": 3, "op": "eq", "value": "x"},
|
||||
{"q": 4, "op": "eq", "value": "y"}]}}
|
||||
cleaned = history._clean_conditions(config, {3})
|
||||
assert [r["q"] for r in cleaned["condition"]["rules"]] == [3]
|
||||
assert "condition" not in history._clean_conditions(config, set())
|
||||
|
||||
|
||||
def test_overbooked() -> None:
|
||||
assert Availability(capacity=1, confirmed=2, waiting=0).overbooked
|
||||
assert not Availability(capacity=2, confirmed=2, waiting=1).overbooked
|
||||
assert not Availability(capacity=None, confirmed=9, waiting=0).overbooked
|
||||
@@ -174,7 +174,7 @@ def test_protected_pages_need_login_and_rights(app: Any) -> None:
|
||||
if denied.status_code == 303:
|
||||
assert not denied.headers["location"].startswith(path), path
|
||||
checked += 1
|
||||
# Stand Phase 10: 38 geschützte Seiten; die Untergrenze fängt eine leere Erfassung ab
|
||||
# Stand mit Verlauf: 40 geschützte Seiten; die Untergrenze fängt eine leere Erfassung ab
|
||||
assert checked > 30, _describe(app)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user