]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blobdiff - tests/test_wradmin.py
Now the tests pass - MwUser class had to be modified.
[philipp/winterrodeln/wradmin.git] / tests / test_wradmin.py
index 67505b3d4b57d4ccee8ebac9f0cff26b304b18cf..db266652cfce54021de9b3b8c2f3990a3d5b5d9d 100644 (file)
@@ -62,24 +62,41 @@ class TestDbWradmin(WradminTestBase):
                 con.execute("UPDATE wrreport SET date_invalid = date_invalid + INTERVAL %s SECOND", (seconds_diff,))
                 con.execute("UPDATE wrreport SET delete_date = delete_date + INTERVAL %s SECOND", (seconds_diff,))
 
-    def test_bericht_list(self):
-        result = self.app.get('/bericht/list')
+    def login(self):
+        return self.app.post('/login', data={'user_name': 'Johndoe', 'password': 'doejohn'}, follow_redirects=True)
+
+    def login_and_get(self, url: str):
+        result = self.app.get(url)
+        self.assertEqual(result.status_code, 302)
+        result = self.login()
+        self.assertEqual(result.status_code, 200)
+        result = self.app.get(url)
         self.assertEqual(result.status_code, 200)
+        return result
+
+    def test_bericht_list(self):
+        result = self.login_and_get('/bericht/list')
         self.assertTrue(result.data.startswith(b'<!doctype html'))
         soup = bs4.BeautifulSoup(result.data, 'html.parser')
         self.assertEqual(soup.title.text, 'Rodelbahnberichte')
 
     def test_bericht_view(self):
-        result = self.app.get('/bericht/view/19591')
-        self.assertEqual(result.status_code, 200)
+        result = self.login_and_get('/bericht/view/19591')
         self.assertTrue(result.data.startswith(b'<!doctype html'))
         soup = bs4.BeautifulSoup(result.data, 'html.parser')
         self.assertEqual(soup.title.text, 'Rodelbahnbericht #19591')
         self.assertIn('Brandstatt Alm', str(soup.table))
 
     def test_bericht_change_date_invalid_twoweeks(self):
+        url = '/bericht/change_date_invalid/19591'
         post_data = {'date_invalid': 'two_weeks', 'date_userdefined': '2018-01-30 18:26'}
-        result = self.app.post('/bericht/change_date_invalid/19591', data=post_data, follow_redirects=True)
+        result = self.app.post(url, data=post_data)
+        self.assertEqual(result.status_code, 302)
+        result = self.app.post(url, data=post_data, follow_redirects=True)
+        self.assertEqual(result.status_code, 200)
+        result = self.login()
+        self.assertEqual(result.status_code, 200)
+        result = self.app.post(url, data=post_data, follow_redirects=True)
         self.assertEqual(result.status_code, 200)
         self.assertTrue(result.data.startswith(b'<!doctype html'))
         soup = bs4.BeautifulSoup(result.data, 'html.parser')
@@ -87,6 +104,7 @@ class TestDbWradmin(WradminTestBase):
         self.assertIn('Datum wurde erfolgreich geƤndert', str(soup))
 
     def test_bericht_change_date_invalid_userdefined(self):
+        self.login()
         post_data = {'date_invalid': 'userdefined', 'date_userdefined': '2018-01-30 15:09'}
         result = self.app.post('/bericht/change_date_invalid/19591', data=post_data, follow_redirects=True)
         self.assertEqual(result.status_code, 200)
@@ -143,7 +161,6 @@ class TestDbWradmin(WradminTestBase):
 
     def test_rodelbahn_view(self):
         result = self.app.get('/rodelbahn/view/926')
-        self.assertEqual(result.status_code, 200)
         self.assertTrue(result.data.startswith(b'<!doctype html'))
         soup = bs4.BeautifulSoup(result.data, 'html.parser')
         self.assertIn('Rodelbahn', soup.title.text)