From: Christian Heller Date: Wed, 27 Mar 2024 01:04:52 +0000 (+0100) Subject: Redirect / to /day, throw informative Exception on other unknown paths. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7B%20deck_id%20%7D%7D/processes?a=commitdiff_plain;h=17be4d0a78f3d1b56df588807b6bda05bb2d8ebc;p=plomtask Redirect / to /day, throw informative Exception on other unknown paths. --- 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')