Coverage for an_website/quotes/__init__.py: 100.000%
12 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-10 18:56 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-10 18:56 +0000
1# This program is free software: you can redistribute it and/or modify
2# it under the terms of the GNU Affero General Public License as
3# published by the Free Software Foundation, either version 3 of the
4# License, or (at your option) any later version.
5#
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9# GNU Affero General Public License for more details.
10#
11# You should have received a copy of the GNU Affero General Public License
12# along with this program. If not, see <https://www.gnu.org/licenses/>.
14"""A page with wrong quotes."""
16from tornado.web import RedirectHandler
18from ..utils.utils import ModuleInfo, PageInfo
19from .create import CreatePage1, CreatePage2
20from .generator import QuoteGenerator, QuoteGeneratorAPI
21from .image import QuoteAsImage
22from .info import AuthorsInfoPage, QuotesInfoPage
23from .quote_of_the_day import (
24 QuoteOfTheDayAPI,
25 QuoteOfTheDayRedirect,
26 QuoteOfTheDayRSS,
27)
28from .quotes import QuoteAPIHandler, QuoteById, QuoteMainPage, QuoteRedirectAPI
29from .share import ShareQuote
30from .utils import update_cache_periodically
33def get_module_info() -> ModuleInfo:
34 """Create and return the ModuleInfo for this module."""
35 return ModuleInfo(
36 handlers=(
37 (r"/zitate", QuoteMainPage),
38 # {1,10} is too much, but better too much than not enough
39 (r"/zitate/([0-9]{1,10})-([0-9]{1,10})", QuoteById),
40 (r"/zitate/([0-9]{1,10})", QuoteById),
41 (
42 r"/zitate/-([0-9]{1,10})",
43 RedirectHandler,
44 {"url": "/zitate/info/a/{0}"},
45 ),
46 (
47 r"/zitate/([0-9]{1,10})-",
48 RedirectHandler,
49 {"url": "/zitate/info/z/{0}"},
50 ),
51 ( # /zitate/69-420.html shouldn't say "unsupported file extension"
52 r"/zitate/([0-9]{1,10})-([0-9]{1,10}).html?",
53 RedirectHandler,
54 {"url": "/zitate/{0}-{1}"},
55 ),
56 ( # redirect to the new URL
57 r"/zitate/([0-9]{1,10})-([0-9]{1,10})/image\.([a-zA-Z]+)",
58 RedirectHandler,
59 {"url": "/zitate/{0}-{1}.{2}"},
60 ),
61 (
62 r"/zitate/([0-9]{1,10})-([0-9]{1,10})\.([a-zA-Z]+)",
63 QuoteAsImage,
64 ),
65 (
66 r"/zitate/([0-9]{1,10})()\.([a-zA-Z]+)",
67 QuoteAsImage,
68 ),
69 (
70 r"/zitate/([0-9]{1,10})-([0-9]{1,10})/image",
71 QuoteAsImage,
72 ),
73 (
74 r"/zitate/([0-9]{1,10})()/(image)",
75 QuoteAsImage,
76 ),
77 ( # redirect to the new URL (changed because of robots.txt)
78 r"/zitate/([0-9]{1,10})-([0-9]{1,10})/share",
79 RedirectHandler,
80 {"url": "/zitate/share/{0}-{1}"},
81 ),
82 (r"/zitate/share/([0-9]{1,10})-([0-9]{1,10})", ShareQuote),
83 (r"/api/zitate(/full|)", QuoteRedirectAPI),
84 (
85 r"/api/zitate/([0-9]{1,10})-([0-9]{1,10})(?:/full|)",
86 QuoteAPIHandler,
87 ),
88 (
89 r"/api/zitate/([0-9]{1,10})(?:/full|)",
90 QuoteAPIHandler,
91 ),
92 # quotes creator
93 (r"/zitate/erstellen", CreatePage1),
94 (r"/zitate/create-wrong-quote", CreatePage2),
95 # quote generator
96 (r"/zitate/generator", QuoteGenerator),
97 (r"/api/zitate/generator", QuoteGeneratorAPI),
98 # quote of the day
99 (r"/zitat-des-tages/feed", QuoteOfTheDayRSS),
100 (r"/zitat-des-tages", QuoteOfTheDayRedirect),
101 (
102 r"/zitat-des-tages/([0-9]{4}-[0-9]{2}-[0-9]{2})",
103 QuoteOfTheDayRedirect,
104 ),
105 (r"/api/zitat-des-tages", QuoteOfTheDayAPI),
106 (
107 r"/api/zitat-des-tages/([0-9]{4}-[0-9]{2}-[0-9]{2})",
108 QuoteOfTheDayAPI,
109 ),
110 (r"/api/zitat-des-tages/full", QuoteOfTheDayAPI),
111 (
112 r"/api/zitat-des-tages/([0-9]{4}-[0-9]{2}-[0-9]{2})/full",
113 QuoteOfTheDayAPI,
114 ),
115 # author/quote info
116 (r"/zitate/info/a/([0-9]{1,10})", AuthorsInfoPage),
117 (r"/zitate/info/z/([0-9]{1,10})", QuotesInfoPage),
118 ),
119 name="Falsch zugeordnete Zitate",
120 short_name="Falsche Zitate",
121 description="Witzige, aber falsch zugeordnete Zitate",
122 path="/zitate",
123 aliases=("/z",),
124 sub_pages=(
125 PageInfo(
126 name="Falsche-Zitate-Ersteller",
127 description="Erstelle witzige falsch zugeordnete Zitate",
128 path="/zitate/erstellen",
129 ),
130 PageInfo(
131 name="Der Zitate-Generator",
132 short_name="Zitate-Generator",
133 description="Lasse falsch zugeordnete Zitate generieren",
134 path="/zitate/generator",
135 keywords=(
136 "Generator",
137 "Falsche Zitate",
138 "Falsch zugeordnete Zitate",
139 ),
140 ),
141 PageInfo(
142 name="Das Zitat des Tages",
143 description="Jeden Tag ein anderes Zitat",
144 path="/zitat-des-tages",
145 keywords=(
146 "Zitate",
147 "Witzig",
148 "Känguru",
149 ),
150 ),
151 PageInfo(
152 name="Zitate API",
153 description="Ein zufälliges falsches Zitat",
154 path="/api/zitate",
155 hidden=True,
156 ),
157 ),
158 keywords=(
159 "falsch zugeordnet",
160 "Zitate",
161 "Witzig",
162 "Känguru",
163 "Marc-Uwe Kling",
164 "falsche Zitate",
165 "falsch zugeordnete Zitate",
166 ),
167 required_background_tasks=frozenset({update_cache_periodically}),
168 )