This commit is contained in:
2026-11-01 17:17:58 +01:00
parent dc9d5a750e
commit 7675acd81e
11 changed files with 528 additions and 18 deletions
+72
View File
@@ -167,6 +167,7 @@ class MainAppTest(unittest.TestCase):
self.assertEqual(self.login().status_code, 302)
self.assertEqual(self.client.get("/home").status_code, 200)
self.assertEqual(self.client.get("/sensors").status_code, 200)
self.assertEqual(self.client.get("/notes").status_code, 200)
self.assertEqual(self.client.get("/api/docs").status_code, 200)
def test_public_device_api_is_proxied_to_sensors(self):
@@ -195,6 +196,77 @@ class MainAppTest(unittest.TestCase):
self.assertEqual(hourly.status_code, 200)
self.assertEqual(len(hourly.get_json()), 1)
def test_notes_require_login(self):
response = self.client.get("/notes")
self.assertEqual(response.status_code, 302)
self.assertIn("/login", response.headers["Location"])
def test_notes_and_checklist_are_stored_in_main_db(self):
from user_models import Note, NoteItem, User, user_db
self.login()
created = self.client.post(
"/notes", data={"title": "Test title", "content": "My short note"}
)
self.assertEqual(created.status_code, 302)
with self.main_app.app_context():
user = User.query.filter_by(username="tester").one()
note = Note.query.filter_by(user_id=user.id).one()
note_id = note.id
self.assertEqual(note.title, "Test title")
self.assertEqual(note.content, "My short note")
tables = set(inspect(user_db.engine).get_table_names())
self.assertIn("note", tables)
self.assertIn("note_item", tables)
self.assertEqual(
self.client.post(
f"/notes/{note_id}/items", data={"text": "first item"}
).status_code,
302,
)
self.assertEqual(
self.client.post(
f"/notes/{note_id}/items", data={"text": "second item"}
).status_code,
302,
)
with self.main_app.app_context():
first, second = (
NoteItem.query.filter_by(note_id=note_id).order_by(NoteItem.id).all()
)
first_id = first.id
self.assertEqual(
self.client.post(
f"/notes/{note_id}/items/{first_id}/toggle",
data={"is_done": "1"},
).status_code,
302,
)
page = self.client.get("/notes")
html = page.get_data(as_text=True)
self.assertEqual(page.status_code, 200)
self.assertIn('class="done"', html)
self.assertIn('value="Test title"', html)
self.assertLess(html.index("second item"), html.index("first item"))
with self.main_app.app_context():
user_db.session.expire_all()
items = (
NoteItem.query.filter_by(note_id=note_id).order_by(NoteItem.id).all()
)
self.assertTrue(items[0].is_done)
self.assertFalse(items[1].is_done)
self.assertEqual(
[item.text for item in items[0].note.ordered_items],
["second item", "first item"],
)
if __name__ == "__main__":
unittest.main()