Repository navigation
Give the action buttons states, and stop swallowing failures #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| """Was bei einer Zuordnung schiefgehen darf, ohne Spuren zu hinterlassen. | ||
|
|
||
| Gemessen an der laufenden Instanz: POST /api/unknowns/assign mit veralteten IDs gab | ||
| HTTP 200 und {"assigned": 0, "slug": "testperson"} zurueck — und die Person war | ||
| angelegt. Ueber "Track as new" (PR #32) heisst das: jeder Fehlversuch laesst ein | ||
| leeres Unnamed-xxxxxx in der Galerie zurueck. | ||
| """ | ||
| import tempfile | ||
| import unittest | ||
| from pathlib import Path | ||
| from types import SimpleNamespace | ||
|
|
||
| from app.gallery import Gallery | ||
| from app.webui import build_app | ||
|
|
||
|
|
||
| def _app(tmp: Path): | ||
| data = tmp / "data" | ||
| (data / "persons").mkdir(parents=True) | ||
| (data / "ignored").mkdir() | ||
| gallery = Gallery(data, top_k=3, max_per_person=40) | ||
| cfg = {"faceid": {"match_threshold": 0.5, "unknown_threshold": 0.35, | ||
| "suggest_threshold": 0.4, "cluster_eps": 0.55, | ||
| "ignore_threshold": 0.5, "dedupe_threshold": 0.65}, | ||
| "folder": {"enabled": False}, "frigate": {"url": ""}, "mqtt": {}} | ||
| proc = SimpleNamespace(_announced=set(), match_thr=0.5, unknown_thr=0.35, | ||
| ignore_thr=0.5, history=None, logbuffer=None, | ||
| frigate=SimpleNamespace(enabled=False), | ||
| folder_ingest=SimpleNamespace(status=lambda: {}, | ||
| max_indexed_files=5000, | ||
| enabled=False)) | ||
| app = build_app(cfg, None, gallery, proc, data, Path("static")) | ||
| return app, gallery | ||
|
|
||
|
|
||
| def _route(app, path: str): | ||
| for r in app.routes: | ||
| if getattr(r, "path", None) == path: | ||
| return r.endpoint | ||
| raise AssertionError(f"route {path} not found") | ||
|
|
||
|
|
||
| class AssignGuardTests(unittest.TestCase): | ||
| def setUp(self): | ||
| self.tmp = tempfile.TemporaryDirectory() | ||
| self.app, self.gallery = _app(Path(self.tmp.name)) | ||
| self.assign = _route(self.app, "/api/unknowns/assign") | ||
| from app.webui import AssignBody | ||
| self.Body = AssignBody | ||
|
|
||
| def tearDown(self): | ||
| self.tmp.cleanup() | ||
|
|
||
| def test_a_failed_assign_does_not_leave_an_empty_person(self): | ||
| from fastapi import HTTPException | ||
| with self.assertRaises(HTTPException) as cm: | ||
| self.assign(self.Body(ids=["does-not-exist"], person="Unnamed-ab12cd")) | ||
| self.assertEqual(cm.exception.status_code, 409) | ||
| self.assertEqual(self.gallery.persons(), {}, | ||
| "die fuer diesen Aufruf angelegte Person muss weg sein") | ||
| self.assertFalse((Path(self.tmp.name) / "data" / "persons" / "unnamed-ab12cd").exists()) | ||
|
|
||
| def test_an_existing_person_survives_a_failed_assign(self): | ||
| from fastapi import HTTPException | ||
| slug = self.gallery.create_person("Juli") | ||
| with self.assertRaises(HTTPException) as cm: | ||
| self.assign(self.Body(ids=["does-not-exist"], person=slug)) | ||
| self.assertEqual(cm.exception.status_code, 409) | ||
| self.assertIn(slug, self.gallery.persons(), | ||
| "eine vorhandene Person darf ein Fehlversuch nie loeschen") | ||
|
|
||
| def test_a_display_name_for_an_existing_person_never_deletes_it(self): | ||
| # create_person ist idempotent: "Juli" liefert den vorhandenen Slug "juli" | ||
| # zurueck. Wer am Eingabewert statt am aufgeloesten Slug entscheidet, loescht | ||
| # hier eine bestehende Person samt Gesichtern. | ||
| from fastapi import HTTPException | ||
| slug = self.gallery.create_person("Juli") | ||
| self.assertEqual(slug, "juli") | ||
| for typed in ("Juli", " juli ", "JULI"): | ||
| with self.assertRaises(HTTPException) as cm: | ||
| self.assign(self.Body(ids=["does-not-exist"], person=typed)) | ||
| self.assertEqual(cm.exception.status_code, 409) | ||
| self.assertIn(slug, self.gallery.persons(), | ||
| f"Eingabe {typed!r} darf die vorhandene Person nicht loeschen") | ||
|
|
||
| def test_a_successful_assign_still_returns_the_count(self): | ||
| # Gegenprobe: der 409 darf nur den Nullfall treffen. | ||
| import numpy as np | ||
| slug = self.gallery.create_person("Juli") | ||
| emb = np.ones(512, dtype=np.float32) / np.sqrt(512) | ||
| crop = np.full((80, 80, 3), 127, dtype=np.uint8) | ||
| uid = self.gallery.save_unknown(crop, emb, {"camera": "entrance"}) | ||
| self.assertIsNotNone(uid) | ||
| r = self.assign(self.Body(ids=[uid], person=slug)) | ||
| self.assertEqual(r["assigned"], 1) | ||
| self.assertEqual(r["slug"], slug) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.