2 import bs4 # beautiful soup
7 class WradminTestBase(unittest.TestCase):
9 wradmin.app.config['TESTING'] = True
10 self.app = wradmin.app.test_client()
13 class TestNoDbWradmin(WradminTestBase):
15 result = self.app.get('/')
16 self.assertEqual(result.status_code, 200)
17 self.assertTrue(result.data.startswith(b'<!doctype html'))
18 soup = bs4.BeautifulSoup(result.data, 'html.parser')
19 self.assertEqual(soup.title.text, 'Hauptmenü')
21 def test_coordtool(self):
22 result = self.app.get('/coordtool/index')
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, 'Koordinaten-Rechner')
28 def test_coordtool_convert_ok(self):
29 result = self.app.post('/coordtool/convert', data={'input': '47.987, 11.123'}, follow_redirects=True)
30 self.assertEqual(result.status_code, 200)
31 self.assertTrue(result.data.startswith(b'<!doctype html'))
32 soup = bs4.BeautifulSoup(result.data, 'html.parser')
33 self.assertEqual(soup.title.text, 'Koordinaten-Rechner')
34 self.assertIn('GPX Format', str(soup))
36 def test_coordtool_convert_error(self):
37 result = self.app.post('/coordtool/convert', data={'input': 'abc'}, follow_redirects=True)
38 self.assertEqual(result.status_code, 200)
39 self.assertTrue(result.data.startswith(b'<!doctype html'))
40 soup = bs4.BeautifulSoup(result.data, 'html.parser')
41 self.assertEqual(soup.title.text, 'Koordinaten-Rechner')
42 self.assertIn('no known format', str(soup))
45 class TestDbWradmin(WradminTestBase):
48 with wradmin.app.app_context():
50 with open('tests/testdb.sql', 'r') as f:
52 with wradmin.model.meta.engine.begin() as con:
56 seconds_diff, = con.execute("SELECT TIMESTAMPDIFF(SECOND, '2017-03-31 07:00', now())").fetchone()
57 seconds_diff = int(seconds_diff)
58 con.execute("UPDATE wrreport SET date_report = DATE(date_report + INTERVAL %s SECOND) WHERE time_report IS NULL", (seconds_diff,))
59 con.execute("UPDATE wrreport SET date_report = DATE(TIMESTAMP(date_report, time_report) + INTERVAL %s SECOND) WHERE time_report IS NOT NULL", (seconds_diff,))
60 con.execute("UPDATE wrreport SET time_report = TIME(TIMESTAMP(date_report, time_report) + INTERVAL %s SECOND) WHERE time_report IS NOT NULL", (seconds_diff,))
61 con.execute("UPDATE wrreport SET date_entry = date_entry + INTERVAL %s SECOND", (seconds_diff,))
62 con.execute("UPDATE wrreport SET date_invalid = date_invalid + INTERVAL %s SECOND", (seconds_diff,))
63 con.execute("UPDATE wrreport SET delete_date = delete_date + INTERVAL %s SECOND", (seconds_diff,))
65 def test_bericht_list(self):
66 result = self.app.get('/bericht/list')
67 self.assertEqual(result.status_code, 200)
68 self.assertTrue(result.data.startswith(b'<!doctype html'))
69 soup = bs4.BeautifulSoup(result.data, 'html.parser')
70 self.assertEqual(soup.title.text, 'Rodelbahnberichte')
72 def test_bericht_view(self):
73 result = self.app.get('/bericht/view/19591')
74 self.assertEqual(result.status_code, 200)
75 self.assertTrue(result.data.startswith(b'<!doctype html'))
76 soup = bs4.BeautifulSoup(result.data, 'html.parser')
77 self.assertEqual(soup.title.text, 'Rodelbahnbericht #19591')
78 self.assertIn('Brandstatt Alm', str(soup.table))
80 def test_bericht_change_date_invalid_twoweeks(self):
81 post_data = {'date_invalid': 'two_weeks', 'date_userdefined': '2018-01-30 18:26'}
82 result = self.app.post('/bericht/change_date_invalid/19591', data=post_data, follow_redirects=True)
83 self.assertEqual(result.status_code, 200)
84 self.assertTrue(result.data.startswith(b'<!doctype html'))
85 soup = bs4.BeautifulSoup(result.data, 'html.parser')
86 self.assertEqual(soup.title.text, 'Rodelbahnbericht #19591')
87 self.assertIn('Datum wurde erfolgreich geändert', str(soup))
89 def test_bericht_change_date_invalid_userdefined(self):
90 post_data = {'date_invalid': 'userdefined', 'date_userdefined': '2018-01-30 15:09'}
91 result = self.app.post('/bericht/change_date_invalid/19591', data=post_data, follow_redirects=True)
92 self.assertEqual(result.status_code, 200)
93 self.assertTrue(result.data.startswith(b'<!doctype html'))
94 soup = bs4.BeautifulSoup(result.data, 'html.parser')
95 self.assertEqual(soup.title.text, 'Rodelbahnbericht #19591')
96 self.assertIn('Datum wurde erfolgreich geändert', str(soup))
97 self.assertIn('2018-01-30 15:09:00', str(soup))
99 def test_gasthaus_list(self):
100 result = self.app.get('/gasthaus/list')
101 self.assertEqual(result.status_code, 200)
102 self.assertTrue(result.data.startswith(b'<!doctype html'))
103 soup = bs4.BeautifulSoup(result.data, 'html.parser')
104 self.assertEqual(soup.title.text, 'Gasthäuser')
105 self.assertIn('Meißner', str(soup.table))
107 def test_gasthaus_view(self):
108 result = self.app.get('/gasthaus/view/362')
109 self.assertEqual(result.status_code, 200)
110 self.assertTrue(result.data.startswith(b'<!doctype html'))
111 soup = bs4.BeautifulSoup(result.data, 'html.parser')
112 self.assertIn('Gasthaus', soup.title.text)
113 self.assertIn('Meißner', str(soup))
115 def test_gasthaus_update_success(self):
116 result = self.app.get('/gasthaus/update', follow_redirects=True)
117 self.assertEqual(result.status_code, 200)
118 self.assertTrue(result.data.startswith(b'<!doctype html'))
119 soup = bs4.BeautifulSoup(result.data, 'html.parser')
120 self.assertIn('Die Gasthausliste wurde erfolgreich aktualisiert.', str(soup))
122 def test_gasthaus_update_fail(self):
123 session = wradmin.model.meta.Session
124 text = session.query(wradmin.model.MwText).get(8719)
125 text.old_text = text.old_text.replace('maria-waldrast@aon.at', 'abc@def@example.com')
127 result = self.app.get('/gasthaus/update', follow_redirects=True)
128 self.assertEqual(result.status_code, 200)
129 self.assertTrue(result.data.startswith(b'<!doctype html'))
130 soup = bs4.BeautifulSoup(result.data, 'html.parser')
131 self.assertIn('Fehler bei Gasthaus \'Maria Waldrast (Klostergasthaus)\'', str(soup))
133 def test_rodelbahn_list(self):
134 result = self.app.get('/rodelbahn/list')
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.assertEqual(soup.title.text, 'Rodelbahnen')
139 table = soup.find('table')
140 self.assertIsNotNone(table)
141 rows = table.find_all('tr')
142 self.assertEqual(len(rows), 9+1)
144 def test_rodelbahn_view(self):
145 result = self.app.get('/rodelbahn/view/926')
146 self.assertEqual(result.status_code, 200)
147 self.assertTrue(result.data.startswith(b'<!doctype html'))
148 soup = bs4.BeautifulSoup(result.data, 'html.parser')
149 self.assertIn('Rodelbahn', soup.title.text)
150 self.assertIn('Hühnerspiel', str(soup))
152 def test_rodelbahn_update_success(self):
153 result = self.app.get('/rodelbahn/update', follow_redirects=True)
154 self.assertEqual(result.status_code, 200)
155 self.assertTrue(result.data.startswith(b'<!doctype html'))
156 soup = bs4.BeautifulSoup(result.data, 'html.parser')
157 self.assertIn('Die Rodelbahnliste wurde erfolgreich aktualisiert.', str(soup))
159 def test_rodelbahn_update_fail(self):
160 session = wradmin.model.meta.Session
161 text = session.query(wradmin.model.MwText).get(12106)
162 text.old_text = text.old_text.replace('Schwierigkeit = mittel', 'Schwierigkeit = geht so')
164 result = self.app.get('/rodelbahn/update', 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('Fehler bei Rodelbahn \'Juifenalm\'', str(soup))
170 def test_rodelbahn_update_regioncache(self):
171 result = self.app.get('/rodelbahn/update_regioncache', follow_redirects=True)
172 self.assertEqual(result.status_code, 200)
173 self.assertTrue(result.data.startswith(b'<!doctype html'))
174 soup = bs4.BeautifulSoup(result.data, 'html.parser')
175 self.assertIn('Die Rodelbahneinträge in den Regionslisten wurden erfolgreich aktualisiert.', str(soup))