1 """How to test wradmin:
3 WRADMIN_SETTINGS=../wradmin/test.cfg python3 -m unittest tests.test_wradmin
6 import bs4 # beautiful soup
11 class WradminTestBase(unittest.TestCase):
13 wradmin.app.config['TESTING'] = True
14 self.app = wradmin.app.test_client()
17 class TestNoDbWradmin(WradminTestBase):
19 result = self.app.get('/')
20 self.assertEqual(result.status_code, 200)
21 self.assertTrue(result.data.startswith(b'<!doctype html'))
22 soup = bs4.BeautifulSoup(result.data, 'html.parser')
23 self.assertEqual(soup.title.text, 'Hauptmenü')
25 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):
33 result = self.app.post('/coordtool/convert', data={'input': '47.987, 11.123'}, follow_redirects=True)
34 self.assertEqual(result.status_code, 200)
35 self.assertTrue(result.data.startswith(b'<!doctype html'))
36 soup = bs4.BeautifulSoup(result.data, 'html.parser')
37 self.assertEqual(soup.title.text, 'Koordinaten-Rechner')
38 self.assertIn('GPX Format', str(soup))
40 def test_coordtool_convert_error(self):
41 result = self.app.post('/coordtool/convert', data={'input': 'abc'}, follow_redirects=True)
42 self.assertEqual(result.status_code, 200)
43 self.assertTrue(result.data.startswith(b'<!doctype html'))
44 soup = bs4.BeautifulSoup(result.data, 'html.parser')
45 self.assertEqual(soup.title.text, 'Koordinaten-Rechner')
46 self.assertIn('no known format', str(soup))
49 class TestDbWradmin(WradminTestBase):
52 with wradmin.app.app_context():
54 with open('tests/testdb.sql', 'r') as f:
56 with wradmin.model.meta.engine.begin() as con:
60 seconds_diff, = con.execute("SELECT TIMESTAMPDIFF(SECOND, '2017-03-31 07:00', now())").fetchone()
61 seconds_diff = int(seconds_diff)
62 con.execute("UPDATE wrreport SET date_report = DATE(date_report + INTERVAL %s SECOND) WHERE time_report IS NULL", (seconds_diff,))
63 con.execute("UPDATE wrreport SET date_report = DATE(TIMESTAMP(date_report, time_report) + INTERVAL %s SECOND) WHERE time_report IS NOT NULL", (seconds_diff,))
64 con.execute("UPDATE wrreport SET time_report = TIME(TIMESTAMP(date_report, time_report) + INTERVAL %s SECOND) WHERE time_report IS NOT NULL", (seconds_diff,))
65 con.execute("UPDATE wrreport SET date_entry = date_entry + INTERVAL %s SECOND", (seconds_diff,))
66 con.execute("UPDATE wrreport SET date_invalid = date_invalid + INTERVAL %s SECOND", (seconds_diff,))
67 con.execute("UPDATE wrreport SET delete_date = delete_date + INTERVAL %s SECOND", (seconds_diff,))
69 def test_bericht_list(self):
70 result = self.app.get('/bericht/list')
71 self.assertEqual(result.status_code, 200)
72 self.assertTrue(result.data.startswith(b'<!doctype html'))
73 soup = bs4.BeautifulSoup(result.data, 'html.parser')
74 self.assertEqual(soup.title.text, 'Rodelbahnberichte')
76 def test_bericht_view(self):
77 result = self.app.get('/bericht/view/19591')
78 self.assertEqual(result.status_code, 200)
79 self.assertTrue(result.data.startswith(b'<!doctype html'))
80 soup = bs4.BeautifulSoup(result.data, 'html.parser')
81 self.assertEqual(soup.title.text, 'Rodelbahnbericht #19591')
82 self.assertIn('Brandstatt Alm', str(soup.table))
84 def test_bericht_change_date_invalid_twoweeks(self):
85 post_data = {'date_invalid': 'two_weeks', 'date_userdefined': '2018-01-30 18:26'}
86 result = self.app.post('/bericht/change_date_invalid/19591', data=post_data, follow_redirects=True)
87 self.assertEqual(result.status_code, 200)
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('Datum wurde erfolgreich geändert', str(soup))
93 def test_bericht_change_date_invalid_userdefined(self):
94 post_data = {'date_invalid': 'userdefined', 'date_userdefined': '2018-01-30 15:09'}
95 result = self.app.post('/bericht/change_date_invalid/19591', data=post_data, follow_redirects=True)
96 self.assertEqual(result.status_code, 200)
97 self.assertTrue(result.data.startswith(b'<!doctype html'))
98 soup = bs4.BeautifulSoup(result.data, 'html.parser')
99 self.assertEqual(soup.title.text, 'Rodelbahnbericht #19591')
100 self.assertIn('Datum wurde erfolgreich geändert', str(soup))
101 self.assertIn('2018-01-30 15:09:00', str(soup))
103 def test_gasthaus_list(self):
104 result = self.app.get('/gasthaus/list')
105 self.assertEqual(result.status_code, 200)
106 self.assertTrue(result.data.startswith(b'<!doctype html'))
107 soup = bs4.BeautifulSoup(result.data, 'html.parser')
108 self.assertEqual(soup.title.text, 'Gasthäuser')
109 self.assertIn('Meißner', str(soup.table))
111 def test_gasthaus_view(self):
112 result = self.app.get('/gasthaus/view/362')
113 self.assertEqual(result.status_code, 200)
114 self.assertTrue(result.data.startswith(b'<!doctype html'))
115 soup = bs4.BeautifulSoup(result.data, 'html.parser')
116 self.assertIn('Gasthaus', soup.title.text)
117 self.assertIn('Meißner', str(soup))
119 def test_gasthaus_update_success(self):
120 result = self.app.get('/gasthaus/update', follow_redirects=True)
121 self.assertEqual(result.status_code, 200)
122 self.assertTrue(result.data.startswith(b'<!doctype html'))
123 soup = bs4.BeautifulSoup(result.data, 'html.parser')
124 self.assertIn('Die Gasthausliste wurde erfolgreich aktualisiert.', str(soup))
126 def test_gasthaus_update_fail(self):
127 session = wradmin.model.meta.Session
128 text = session.query(wradmin.model.MwText).get(8719)
129 text.old_text = text.old_text.replace('maria-waldrast@aon.at', 'abc@def@example.com')
131 result = self.app.get('/gasthaus/update', follow_redirects=True)
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('Fehler bei Gasthaus \'Maria Waldrast (Klostergasthaus)\'', str(soup))
137 def test_rodelbahn_list(self):
138 result = self.app.get('/rodelbahn/list')
139 self.assertEqual(result.status_code, 200)
140 self.assertTrue(result.data.startswith(b'<!doctype html'))
141 soup = bs4.BeautifulSoup(result.data, 'html.parser')
142 self.assertEqual(soup.title.text, 'Rodelbahnen')
143 table = soup.find('table')
144 self.assertIsNotNone(table)
145 rows = table.find_all('tr')
146 self.assertEqual(len(rows), 9+1)
148 def test_rodelbahn_view(self):
149 result = self.app.get('/rodelbahn/view/926')
150 self.assertEqual(result.status_code, 200)
151 self.assertTrue(result.data.startswith(b'<!doctype html'))
152 soup = bs4.BeautifulSoup(result.data, 'html.parser')
153 self.assertIn('Rodelbahn', soup.title.text)
154 self.assertIn('Hühnerspiel', str(soup))
156 def test_rodelbahn_update(self):
157 result = self.app.get('/rodelbahn/update', follow_redirects=True)
158 self.assertEqual(result.status_code, 200)
159 self.assertTrue(result.data.startswith(b'<!doctype html'))
160 soup = bs4.BeautifulSoup(result.data, 'html.parser')
161 self.assertIn('Die Rodelbahnliste wurde erfolgreich aktualisiert.', str(soup))
163 def test_rodelbahn_update_regioncache(self):
164 result = self.app.get('/rodelbahn/update_regioncache', follow_redirects=True)
165 self.assertEqual(result.status_code, 200)
166 self.assertTrue(result.data.startswith(b'<!doctype html'))
167 soup = bs4.BeautifulSoup(result.data, 'html.parser')
168 self.assertIn('Die Rodelbahneinträge in den Regionslisten wurden erfolgreich aktualisiert.', str(soup))