style: format backend with black

Also drops the session-sliding comment in login_required.
This commit is contained in:
2026-10-02 14:46:16 -05:00
parent 2512c67893
commit 63c9991421
14 changed files with 320 additions and 82 deletions
+25 -7
View File
@@ -29,19 +29,30 @@ class NoteTests(ApiTestCase):
def test_delete(self):
note = self.add("Temporary").get_json()
self.assertEqual(self.call("DELETE", f"/api/notes/{note['id']}").status_code, 204)
self.assertEqual(
self.call("DELETE", f"/api/notes/{note['id']}").status_code, 204
)
self.assertEqual(self.call("GET", self.notes_path).get_json(), [])
self.assertEqual(self.call("DELETE", f"/api/notes/{note['id']}").status_code, 404)
self.assertEqual(
self.call("DELETE", f"/api/notes/{note['id']}").status_code, 404
)
def test_validation(self):
for body, status in ((" ", 400), ("x" * 10_001, 400), ("a\x00b", 400)):
with self.subTest(length=len(body)):
self.assertEqual(self.add(body).status_code, status)
self.assertEqual(self.call("POST", self.notes_path, {"body": "ok", "book_id": 2}).status_code, 400)
self.assertEqual(
self.call(
"POST", self.notes_path, {"body": "ok", "book_id": 2}
).status_code,
400,
)
def test_missing_book_and_out_of_range_ids_are_404(self):
self.assertEqual(self.call("GET", "/api/books/999/notes").status_code, 404)
self.assertEqual(self.call("PATCH", "/api/notes/99999999999", {"body": "x"}).status_code, 404)
self.assertEqual(
self.call("PATCH", "/api/notes/99999999999", {"body": "x"}).status_code, 404
)
def test_deleting_book_deletes_its_notes(self):
self.add("Will be gone")
@@ -53,7 +64,9 @@ class NoteIsolationTests(ApiTestCase):
def test_other_user_cannot_read_add_edit_or_delete_notes(self):
self.register("alice")
book = self.create_book()
note = self.call("POST", f"/api/books/{book['id']}/notes", {"body": "Private"}).get_json()
note = self.call(
"POST", f"/api/books/{book['id']}/notes", {"body": "Private"}
).get_json()
bob = self.other_user("bob")
attempts = (
("GET", f"/api/books/{book['id']}/notes", None),
@@ -63,6 +76,11 @@ class NoteIsolationTests(ApiTestCase):
)
for method, path, payload in attempts:
with self.subTest(method=method, path=path):
self.assertEqual(self.call(method, path, payload, client=bob).status_code, 404)
bodies = [n["body"] for n in self.call("GET", f"/api/books/{book['id']}/notes").get_json()]
self.assertEqual(
self.call(method, path, payload, client=bob).status_code, 404
)
bodies = [
n["body"]
for n in self.call("GET", f"/api/books/{book['id']}/notes").get_json()
]
self.assertEqual(bodies, ["Private"])