Coverage for an_website/quotes/__init__.py: 100.000%

13 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-16 19: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/>. 

13 

14"""A page with wrong quotes.""" 

15 

16from __future__ import annotations 

17 

18from tornado.web import RedirectHandler 

19 

20from ..utils.utils import ModuleInfo, PageInfo 

21from .create import CreatePage1, CreatePage2 

22from .generator import QuoteGenerator, QuoteGeneratorAPI 

23from .image import QuoteAsImage 

24from .info import AuthorsInfoPage, QuotesInfoPage 

25from .quote_of_the_day import ( 

26 QuoteOfTheDayAPI, 

27 QuoteOfTheDayRedirect, 

28 QuoteOfTheDayRSS, 

29) 

30from .quotes import QuoteAPIHandler, QuoteById, QuoteMainPage, QuoteRedirectAPI 

31from .share import ShareQuote 

32from .utils import update_cache_periodically 

33 

34 

35def get_module_info() -> ModuleInfo: 

36 """Create and return the ModuleInfo for this module.""" 

37 return ModuleInfo( 

38 handlers=( 

39 (r"/zitate", QuoteMainPage), 

40 # {1,10} is too much, but better too much than not enough 

41 (r"/zitate/([0-9]{1,10})-([0-9]{1,10})", QuoteById), 

42 (r"/zitate/([0-9]{1,10})", QuoteById), 

43 ( 

44 r"/zitate/-([0-9]{1,10})", 

45 RedirectHandler, 

46 {"url": "/zitate/info/a/{0}"}, 

47 ), 

48 ( 

49 r"/zitate/([0-9]{1,10})-", 

50 RedirectHandler, 

51 {"url": "/zitate/info/z/{0}"}, 

52 ), 

53 ( # /zitate/69-420.html shouldn't say "unsupported file extension" 

54 r"/zitate/([0-9]{1,10})-([0-9]{1,10}).html?", 

55 RedirectHandler, 

56 {"url": "/zitate/{0}-{1}"}, 

57 ), 

58 ( # redirect to the new URL 

59 r"/zitate/([0-9]{1,10})-([0-9]{1,10})/image\.([a-zA-Z]+)", 

60 RedirectHandler, 

61 {"url": "/zitate/{0}-{1}.{2}"}, 

62 ), 

63 ( 

64 r"/zitate/([0-9]{1,10})-([0-9]{1,10})\.([a-zA-Z]+)", 

65 QuoteAsImage, 

66 ), 

67 ( 

68 r"/zitate/([0-9]{1,10})()\.([a-zA-Z]+)", 

69 QuoteAsImage, 

70 ), 

71 ( 

72 r"/zitate/([0-9]{1,10})-([0-9]{1,10})/image", 

73 QuoteAsImage, 

74 ), 

75 ( 

76 r"/zitate/([0-9]{1,10})()/(image)", 

77 QuoteAsImage, 

78 ), 

79 ( # redirect to the new URL (changed because of robots.txt) 

80 r"/zitate/([0-9]{1,10})-([0-9]{1,10})/share", 

81 RedirectHandler, 

82 {"url": "/zitate/share/{0}-{1}"}, 

83 ), 

84 (r"/zitate/share/([0-9]{1,10})-([0-9]{1,10})", ShareQuote), 

85 (r"/api/zitate(/full|)", QuoteRedirectAPI), 

86 ( 

87 r"/api/zitate/([0-9]{1,10})-([0-9]{1,10})(?:/full|)", 

88 QuoteAPIHandler, 

89 ), 

90 ( 

91 r"/api/zitate/([0-9]{1,10})(?:/full|)", 

92 QuoteAPIHandler, 

93 ), 

94 # quotes creator 

95 (r"/zitate/erstellen", CreatePage1), 

96 (r"/zitate/create-wrong-quote", CreatePage2), 

97 # quote generator 

98 (r"/zitate/generator", QuoteGenerator), 

99 (r"/api/zitate/generator", QuoteGeneratorAPI), 

100 # quote of the day 

101 (r"/zitat-des-tages/feed", QuoteOfTheDayRSS), 

102 (r"/zitat-des-tages", QuoteOfTheDayRedirect), 

103 ( 

104 r"/zitat-des-tages/([0-9]{4}-[0-9]{2}-[0-9]{2})", 

105 QuoteOfTheDayRedirect, 

106 ), 

107 (r"/api/zitat-des-tages", QuoteOfTheDayAPI), 

108 ( 

109 r"/api/zitat-des-tages/([0-9]{4}-[0-9]{2}-[0-9]{2})", 

110 QuoteOfTheDayAPI, 

111 ), 

112 (r"/api/zitat-des-tages/full", QuoteOfTheDayAPI), 

113 ( 

114 r"/api/zitat-des-tages/([0-9]{4}-[0-9]{2}-[0-9]{2})/full", 

115 QuoteOfTheDayAPI, 

116 ), 

117 # author/quote info 

118 (r"/zitate/info/a/([0-9]{1,10})", AuthorsInfoPage), 

119 (r"/zitate/info/z/([0-9]{1,10})", QuotesInfoPage), 

120 ), 

121 name="Falsch zugeordnete Zitate", 

122 short_name="Falsche Zitate", 

123 description="Witzige, aber falsch zugeordnete Zitate", 

124 path="/zitate", 

125 aliases=("/z",), 

126 sub_pages=( 

127 PageInfo( 

128 name="Falsche-Zitate-Ersteller", 

129 description="Erstelle witzige falsch zugeordnete Zitate", 

130 path="/zitate/erstellen", 

131 ), 

132 PageInfo( 

133 name="Der Zitate-Generator", 

134 short_name="Zitate-Generator", 

135 description="Lasse falsch zugeordnete Zitate generieren", 

136 path="/zitate/generator", 

137 keywords=( 

138 "Generator", 

139 "Falsche Zitate", 

140 "Falsch zugeordnete Zitate", 

141 ), 

142 ), 

143 PageInfo( 

144 name="Das Zitat des Tages", 

145 description="Jeden Tag ein anderes Zitat", 

146 path="/zitat-des-tages", 

147 keywords=( 

148 "Zitate", 

149 "Witzig", 

150 "Känguru", 

151 ), 

152 ), 

153 ), 

154 keywords=( 

155 "falsch zugeordnet", 

156 "Zitate", 

157 "Witzig", 

158 "Känguru", 

159 "Marc-Uwe Kling", 

160 "falsche Zitate", 

161 "falsch zugeordnete Zitate", 

162 ), 

163 required_background_tasks=frozenset({update_cache_periodically}), 

164 )