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