home · contact · privacy
Redirect / to /day, throw informative Exception on other unknown paths.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 27 Mar 2024 01:04:52 +0000 (02:04 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 27 Mar 2024 01:04:52 +0000 (02:04 +0100)
plomtask/http.py
tests/days.py

index af1a60cd148ec86a83bf27bad8759a7e1cf74e6f..1046eccbb1523c784717ca8d5f7a970d11404b85 100644 (file)
@@ -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)
index 06e4302d71aaba58867e961506806a792c1fe807..c6fdcc783db16bdd637d7944ced84ddfe19a2622 100644 (file)
@@ -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')