]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/commitdiff
Update tests to work with admin requirements.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Tue, 29 Sep 2020 19:47:15 +0000 (21:47 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Tue, 29 Sep 2020 19:47:15 +0000 (21:47 +0200)
tests/test_wradmin.py

index eb8a9ccf5d2e9306f0a120f90672850f70c4e18d..35b8a059269a530bcc35c9cf0d94705b698f9ed3 100644 (file)
@@ -9,6 +9,9 @@ class WradminTestBase(unittest.TestCase):
         wradmin.app.config['TESTING'] = True
         self.app = wradmin.app.test_client()
 
+    def login(self):
+        return self.app.post('/login', data={'user_name': 'Johndoe', 'password': 'doejohn'}, follow_redirects=True)
+
 
 class TestNoDbWradmin(WradminTestBase):
     def test_root(self):
@@ -19,6 +22,7 @@ class TestNoDbWradmin(WradminTestBase):
         self.assertEqual(soup.title.text, 'Hauptmenü')
 
     def test_coordtool(self):
+        self.login()
         result = self.app.get('/coordtool/index')
         self.assertEqual(result.status_code, 200)
         self.assertTrue(result.data.startswith(b'<!doctype html'))
@@ -26,6 +30,7 @@ class TestNoDbWradmin(WradminTestBase):
         self.assertEqual(soup.title.text, 'Koordinaten-Rechner')
 
     def test_coordtool_convert_ok(self):
+        self.login()
         result = self.app.post('/coordtool/convert', data={'input': '47.987, 11.123'}, follow_redirects=True)
         self.assertEqual(result.status_code, 200)
         self.assertTrue(result.data.startswith(b'<!doctype html'))
@@ -34,6 +39,7 @@ class TestNoDbWradmin(WradminTestBase):
         self.assertIn('GPX Format', str(soup))
 
     def test_coordtool_convert_error(self):
+        self.login()
         result = self.app.post('/coordtool/convert', data={'input': 'abc'}, follow_redirects=True)
         self.assertEqual(result.status_code, 200)
         self.assertTrue(result.data.startswith(b'<!doctype html'))
@@ -62,9 +68,6 @@ 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 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)
@@ -88,6 +91,7 @@ class TestDbWradmin(WradminTestBase):
         self.assertIn('Brandstatt Alm', str(soup.table))
 
     def test_bericht_change_date_invalid_twoweeks(self):
+        self.login()
         url = '/bericht/change_date_invalid/19591'
         post_data = {'date_invalid': 'two_weeks', 'date_userdefined': '2018-01-30 18:26'}
         result = self.app.post(url, data=post_data)
@@ -115,7 +119,8 @@ class TestDbWradmin(WradminTestBase):
         self.assertIn('2018-01-30 15:09:00', str(soup))
 
     def test_gasthaus_list(self):
-        result = self.app.get('/gasthaus/list')
+
+        result = self.login_and_get('/gasthaus/list')
         self.assertEqual(result.status_code, 200)
         self.assertTrue(result.data.startswith(b'<!doctype html'))
         soup = bs4.BeautifulSoup(result.data, 'html.parser')
@@ -123,7 +128,7 @@ class TestDbWradmin(WradminTestBase):
         self.assertIn('Meißner', str(soup.table))
 
     def test_gasthaus_view(self):
-        result = self.app.get('/gasthaus/view/362')
+        result = self.login_and_get('/gasthaus/view/362')
         self.assertEqual(result.status_code, 200)
         self.assertTrue(result.data.startswith(b'<!doctype html'))
         soup = bs4.BeautifulSoup(result.data, 'html.parser')
@@ -131,6 +136,7 @@ class TestDbWradmin(WradminTestBase):
         self.assertIn('Meißner', str(soup))
 
     def test_gasthaus_update_success(self):
+        self.login()
         result = self.app.get('/gasthaus/update', follow_redirects=True)
         self.assertEqual(result.status_code, 200)
         self.assertTrue(result.data.startswith(b'<!doctype html'))
@@ -139,17 +145,18 @@ class TestDbWradmin(WradminTestBase):
 
     def test_gasthaus_update_fail(self):
         session = wradmin.model.meta.Session
-        text = session.query(wradmin.model.MwText).get(8719)
-        text.old_text = text.old_text.replace('maria-waldrast@aon.at', 'abc@def@example.com')
+        text = session.query(wradmin.model.MwText).get(14415)
+        text.old_text = text.old_text.replace('lindauerhuette@aon.at', 'abc@def@example.com')
         session.commit()
+        self.login()
         result = self.app.get('/gasthaus/update', follow_redirects=True)
         self.assertEqual(result.status_code, 200)
         self.assertTrue(result.data.startswith(b'<!doctype html'))
         soup = bs4.BeautifulSoup(result.data, 'html.parser')
-        self.assertIn('Fehler bei Gasthaus \'Maria Waldrast (Klostergasthaus)\'', str(soup))
+        self.assertIn('Fehler bei Gasthaus \'Lindauer Hütte (Gasthaus)\'', str(soup))
 
     def test_rodelbahn_list(self):
-        result = self.app.get('/rodelbahn/list')
+        result = self.login_and_get('/rodelbahn/list')
         self.assertEqual(result.status_code, 200)
         self.assertTrue(result.data.startswith(b'<!doctype html'))
         soup = bs4.BeautifulSoup(result.data, 'html.parser')
@@ -160,13 +167,14 @@ class TestDbWradmin(WradminTestBase):
         self.assertEqual(len(rows), 9+1)
 
     def test_rodelbahn_view(self):
-        result = self.app.get('/rodelbahn/view/926')
+        result = self.login_and_get('/rodelbahn/view/926')
         self.assertTrue(result.data.startswith(b'<!doctype html'))
         soup = bs4.BeautifulSoup(result.data, 'html.parser')
         self.assertIn('Rodelbahn', soup.title.text)
         self.assertIn('Hühnerspiel', str(soup))
 
     def test_rodelbahn_update_success(self):
+        self.login()
         result = self.app.get('/rodelbahn/update', follow_redirects=True)
         self.assertEqual(result.status_code, 200)
         self.assertTrue(result.data.startswith(b'<!doctype html'))
@@ -175,9 +183,10 @@ class TestDbWradmin(WradminTestBase):
 
     def test_rodelbahn_update_fail(self):
         session = wradmin.model.meta.Session
-        text = session.query(wradmin.model.MwText).get(12106)
+        text = session.query(wradmin.model.MwText).get(15032)
         text.old_text = text.old_text.replace('Schwierigkeit        = mittel', 'Schwierigkeit        = geht so')
         session.commit()
+        self.login()
         result = self.app.get('/rodelbahn/update', follow_redirects=True)
         self.assertEqual(result.status_code, 200)
         self.assertTrue(result.data.startswith(b'<!doctype html'))
@@ -185,6 +194,7 @@ class TestDbWradmin(WradminTestBase):
         self.assertIn('Fehler bei Rodelbahn \'Juifenalm\'', str(soup))
 
     def test_rodelbahn_update_regioncache(self):
+        self.login()
         result = self.app.get('/rodelbahn/update_regioncache', follow_redirects=True)
         self.assertEqual(result.status_code, 200)
         self.assertTrue(result.data.startswith(b'<!doctype html'))