From 17be4d0a78f3d1b56df588807b6bda05bb2d8ebc Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Wed, 27 Mar 2024 02:04:52 +0100
Subject: [PATCH] Redirect / to /day, throw informative Exception on other
 unknown paths.

---
 plomtask/http.py | 8 ++++++--
 tests/days.py    | 6 +++++-
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/plomtask/http.py b/plomtask/http.py
index af1a60c..1046ecc 100644
--- a/plomtask/http.py
+++ b/plomtask/http.py
@@ -6,7 +6,8 @@ from urllib.parse import urlparse, parse_qs
 from os.path import split as path_split
 from jinja2 import Environment as JinjaEnv, FileSystemLoader as JinjaFSLoader
 from plomtask.days import Day, todays_date
-from plomtask.exceptions import HandledException, BadFormatException
+from plomtask.exceptions import HandledException, BadFormatException, \
+        NotFoundException
 from plomtask.db import DatabaseConnection, DatabaseFile
 from plomtask.processes import Process
 
@@ -47,8 +48,11 @@ class TaskHandler(BaseHTTPRequestHandler):
                 html = self.do_GET_process(conn, id__)
             elif 'processes' == site:
                 html = self.do_GET_processes(conn)
+            elif '' == site:
+                self._redirect('/day')
+                return
             else:
-                raise HandledException('Test!')
+                raise NotFoundException(f'Unknown page: /{site}')
             conn.commit()
             conn.close()
             self._send_html(html)
diff --git a/tests/days.py b/tests/days.py
index 06e4302..c6fdcc7 100644
--- a/tests/days.py
+++ b/tests/days.py
@@ -91,7 +91,7 @@ class TestsWithServer(TestCaseWithServer):
     """Tests against our HTTP server/handler (and database)."""
 
     def test_do_GET(self) -> None:
-        """Test /day and /calendar response codes."""
+        """Test /day and /calendar response codes, and / redirect."""
         self.conn.request('GET', '/day')
         self.assertEqual(self.conn.getresponse().status, 200)
         self.conn.request('GET', '/day?date=3000-01-01')
@@ -108,3 +108,7 @@ class TestsWithServer(TestCaseWithServer):
         self.assertEqual(self.conn.getresponse().status, 200)
         self.conn.request('GET', '/calendar?start=foo')
         self.assertEqual(self.conn.getresponse().status, 400)
+        self.conn.request('GET', '/')
+        response = self.conn.getresponse()
+        self.assertEqual(response.status, 302)
+        self.assertEqual(response.getheader('Location'), '/day')
-- 
2.30.2