2 import bs4 # beautiful soup
7 class WradminTestBase(unittest.TestCase):
9 wradmin.app.config['TESTING'] = True
10 self.app = wradmin.app.test_client()
13 return self.app.post('/login', data={'user_name': 'Johndoe', 'password': 'doejohn'}, follow_redirects=True)
16 class TestNoDbWradmin(WradminTestBase):
18 result = self.app.get('/')
19 self.assertEqual(result.status_code, 200)
20 self.assertTrue(result.data.startswith(b'<!doctype html'))
21 soup = bs4.BeautifulSoup(result.data, 'html.parser')
22 self.assertEqual(soup.title.text, 'Hauptmenü')
24 def test_coordtool(self):
26 result = self.app.get('/coordtool/index')
27 self.assertEqual(result.status_code, 200)
28 self.assertTrue(result.data.startswith(b'<!doctype html'))
29 soup = bs4.BeautifulSoup(result.data, 'html.parser')
30 self.assertEqual(soup.title.text, 'Koordinaten-Rechner')
32 def test_coordtool_convert_ok(self):
34 result = self.app.post('/coordtool/convert', data={'input': '47.987, 11.123'}, follow_redirects=True)
35 self.assertEqual(result.status_code, 200)
36 self.assertTrue(result.data.startswith(b'<!doctype html'))
37 soup = bs4.BeautifulSoup(result.data, 'html.parser')
38 self.assertEqual(soup.title.text, 'Koordinaten-Rechner')
39 self.assertIn('GPX Format', str(soup))
41 def test_coordtool_convert_error(self):
43 result = self.app.post('/coordtool/convert', data={'input': 'abc'}, follow_redirects=True)
44 self.assertEqual(result.status_code, 200)
45 self.assertTrue(result.data.startswith(b'<!doctype html'))
46 soup = bs4.BeautifulSoup(result.data, 'html.parser')
47 self.assertEqual(soup.title.text, 'Koordinaten-Rechner')
48 self.assertIn('no known format', str(soup))
51 class TestDbWradmin(WradminTestBase):
54 with wradmin.app.app_context():
56 with open('tests/testdb.sql', 'r') as f:
58 with wradmin.model.meta.engine.begin() as con:
59 con.execution_options(no_parameters=True).execute(sql)
62 seconds_diff, = con.execute("SELECT TIMESTAMPDIFF(SECOND, '2017-03-31 07:00', now())").fetchone()
63 seconds_diff = int(seconds_diff)
64 con.execute("UPDATE wrreport SET date_report = DATE(date_report + INTERVAL %s SECOND) WHERE time_report IS NULL", (seconds_diff,))
65 con.execute("UPDATE wrreport SET date_report = DATE(TIMESTAMP(date_report, time_report) + INTERVAL %s SECOND) WHERE time_report IS NOT NULL", (seconds_diff,))
66 con.execute("UPDATE wrreport SET time_report = TIME(TIMESTAMP(date_report, time_report) + INTERVAL %s SECOND) WHERE time_report IS NOT NULL", (seconds_diff,))
67 con.execute("UPDATE wrreport SET date_entry = date_entry + INTERVAL %s SECOND", (seconds_diff,))
68 con.execute("UPDATE wrreport SET date_invalid = date_invalid + INTERVAL %s SECOND", (seconds_diff,))
69 con.execute("UPDATE wrreport SET delete_date = delete_date + INTERVAL %s SECOND", (seconds_diff,))
71 def login_and_get(self, url: str):
72 result = self.app.get(url)
73 self.assertEqual(result.status_code, 302)
75 self.assertEqual(result.status_code, 200)
76 result = self.app.get(url)
77 self.assertEqual(result.status_code, 200)
80 def test_bericht_list(self):
81 result = self.login_and_get('/bericht/list')
82 self.assertTrue(result.data.startswith(b'<!doctype html'))
83 soup = bs4.BeautifulSoup(result.data, 'html.parser')
84 self.assertEqual(soup.title.text, 'Rodelbahnberichte')
86 def test_bericht_view(self):
87 result = self.login_and_get('/bericht/view/19591')
88 self.assertTrue(result.data.startswith(b'<!doctype html'))
89 soup = bs4.BeautifulSoup(result.data, 'html.parser')
90 self.assertEqual(soup.title.text, 'Rodelbahnbericht #19591')
91 self.assertIn('Brandstatt Alm', str(soup.table))
93 def test_bericht_change_date_invalid_twoweeks(self):
95 url = '/bericht/change_date_invalid/19591'
96 post_data = {'date_invalid': 'two_weeks', 'date_userdefined': '2018-01-30 18:26'}
97 result = self.app.post(url, data=post_data)
98 self.assertEqual(result.status_code, 302)
99 result = self.app.post(url, data=post_data, follow_redirects=True)
100 self.assertEqual(result.status_code, 200)
101 result = self.login()
102 self.assertEqual(result.status_code, 200)
103 result = self.app.post(url, data=post_data, follow_redirects=True)
104 self.assertEqual(result.status_code, 200)
105 self.assertTrue(result.data.startswith(b'<!doctype html'))
106 soup = bs4.BeautifulSoup(result.data, 'html.parser')
107 self.assertEqual(soup.title.text, 'Rodelbahnbericht #19591')
108 self.assertIn('Datum wurde erfolgreich geändert', str(soup))
110 def test_bericht_change_date_invalid_userdefined(self):
112 post_data = {'date_invalid': 'userdefined', 'date_userdefined': '2018-01-30 15:09'}
113 result = self.app.post('/bericht/change_date_invalid/19591', data=post_data, follow_redirects=True)
114 self.assertEqual(result.status_code, 200)
115 self.assertTrue(result.data.startswith(b'<!doctype html'))
116 soup = bs4.BeautifulSoup(result.data, 'html.parser')
117 self.assertEqual(soup.title.text, 'Rodelbahnbericht #19591')
118 self.assertIn('Datum wurde erfolgreich geändert', str(soup))
119 self.assertIn('2018-01-30 15:09:00', str(soup))
121 def test_gasthaus_list(self):
123 result = self.login_and_get('/gasthaus/list')
124 self.assertEqual(result.status_code, 200)
125 self.assertTrue(result.data.startswith(b'<!doctype html'))
126 soup = bs4.BeautifulSoup(result.data, 'html.parser')
127 self.assertEqual(soup.title.text, 'Gasthäuser')
128 self.assertIn('Meißner', str(soup.table))
130 def test_gasthaus_view(self):
131 result = self.login_and_get('/gasthaus/view/362')
132 self.assertEqual(result.status_code, 200)
133 self.assertTrue(result.data.startswith(b'<!doctype html'))
134 soup = bs4.BeautifulSoup(result.data, 'html.parser')
135 self.assertIn('Gasthaus', soup.title.text)
136 self.assertIn('Meißner', str(soup))
138 def test_gasthaus_update_success(self):
140 result = self.app.get('/gasthaus/update', follow_redirects=True)
141 self.assertEqual(result.status_code, 200)
142 self.assertTrue(result.data.startswith(b'<!doctype html'))
143 soup = bs4.BeautifulSoup(result.data, 'html.parser')
144 self.assertIn('Die Gasthausliste wurde erfolgreich aktualisiert.', str(soup))
146 def test_gasthaus_update_fail(self):
147 session = wradmin.model.meta.Session
148 text = session.query(wradmin.model.MwText).get(14415)
149 text.old_text = text.old_text.replace('lindauerhuette@aon.at', 'abc@def@example.com')
152 result = self.app.get('/gasthaus/update', follow_redirects=True)
153 self.assertEqual(result.status_code, 200)
154 self.assertTrue(result.data.startswith(b'<!doctype html'))
155 soup = bs4.BeautifulSoup(result.data, 'html.parser')
156 self.assertIn('Fehler bei Gasthaus \'Lindauer Hütte (Gasthaus)\'', str(soup))
158 def test_rodelbahn_list(self):
159 result = self.login_and_get('/rodelbahn/list')
160 self.assertEqual(result.status_code, 200)
161 self.assertTrue(result.data.startswith(b'<!doctype html'))
162 soup = bs4.BeautifulSoup(result.data, 'html.parser')
163 self.assertEqual(soup.title.text, 'Rodelbahnen')
164 table = soup.find('table')
165 self.assertIsNotNone(table)
166 rows = table.find_all('tr')
167 self.assertEqual(len(rows), 9+1)
169 def test_rodelbahn_view(self):
170 result = self.login_and_get('/rodelbahn/view/926')
171 self.assertTrue(result.data.startswith(b'<!doctype html'))
172 soup = bs4.BeautifulSoup(result.data, 'html.parser')
173 self.assertIn('Rodelbahn', soup.title.text)
174 self.assertIn('Hühnerspiel', str(soup))
176 def test_rodelbahn_update_success(self):
178 result = self.app.get('/rodelbahn/update', follow_redirects=True)
179 self.assertEqual(result.status_code, 200)
180 self.assertTrue(result.data.startswith(b'<!doctype html'))
181 soup = bs4.BeautifulSoup(result.data, 'html.parser')
182 self.assertIn('Die Rodelbahnliste wurde erfolgreich aktualisiert.', str(soup))
184 def test_rodelbahn_update_fail(self):
185 session = wradmin.model.meta.Session
186 text = session.query(wradmin.model.MwText).get(15032)
187 text.old_text = text.old_text.replace('Schwierigkeit = mittel', 'Schwierigkeit = geht so')
190 result = self.app.get('/rodelbahn/update', follow_redirects=True)
191 self.assertEqual(result.status_code, 200)
192 self.assertTrue(result.data.startswith(b'<!doctype html'))
193 soup = bs4.BeautifulSoup(result.data, 'html.parser')
194 self.assertIn('Fehler bei Rodelbahn \'Juifenalm\'', str(soup))
196 def test_rodelbahn_update_regioncache(self):
198 result = self.app.get('/rodelbahn/update_regioncache', follow_redirects=True)
199 self.assertEqual(result.status_code, 200)
200 self.assertTrue(result.data.startswith(b'<!doctype html'))
201 soup = bs4.BeautifulSoup(result.data, 'html.parser')
202 self.assertIn('Die Rodelbahneinträge in den Regionslisten wurden erfolgreich aktualisiert.', str(soup))