]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blobdiff - tests/test_wradmin.py
Start working on implementing login in tests.
[philipp/winterrodeln/wradmin.git] / tests / test_wradmin.py
index e443325e9c4e2c889e337e0ccbaf0a6186a23377..80515c23847b89b9b3296e51207516b185192113 100644 (file)
@@ -1,9 +1,6 @@
-"""How to test wradmin:
-
-WRADMIN_SETTINGS=../wradmin/test.cfg python3 -m unittest tests.test_wradmin
-"""
 import unittest
 import bs4  # beautiful soup
+import wradmin.model
 import wradmin
 
 
@@ -65,7 +62,14 @@ 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_auth(self):
+        result = self.app.get('/bericht/list')
+        self.assertEqual(result.status_code, 302)
+
     def test_bericht_list(self):
+        result = self.app.post('/login', data={'user': 'john', 'password': 'doe'})
+        self.assertEqual(result.status_code, 200)
+
         result = self.app.get('/bericht/list')
         self.assertEqual(result.status_code, 200)
         self.assertTrue(result.data.startswith(b'<!doctype html'))
@@ -115,13 +119,24 @@ class TestDbWradmin(WradminTestBase):
         self.assertIn('Gasthaus', soup.title.text)
         self.assertIn('Meißner', str(soup))
 
-    def test_gasthaus_update(self):
+    def test_gasthaus_update_success(self):
         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('Die Gasthausliste wurde erfolgreich aktualisiert.', str(soup))
 
+    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')
+        session.commit()
+        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))
+
     def test_rodelbahn_list(self):
         result = self.app.get('/rodelbahn/list')
         self.assertEqual(result.status_code, 200)
@@ -141,13 +156,24 @@ class TestDbWradmin(WradminTestBase):
         self.assertIn('Rodelbahn', soup.title.text)
         self.assertIn('Hühnerspiel', str(soup))
 
-    def test_rodelbahn_update(self):
+    def test_rodelbahn_update_success(self):
         result = self.app.get('/rodelbahn/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('Die Rodelbahnliste wurde erfolgreich aktualisiert.', str(soup))
 
+    def test_rodelbahn_update_fail(self):
+        session = wradmin.model.meta.Session
+        text = session.query(wradmin.model.MwText).get(12106)
+        text.old_text = text.old_text.replace('Schwierigkeit        = mittel', 'Schwierigkeit        = geht so')
+        session.commit()
+        result = self.app.get('/rodelbahn/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 Rodelbahn \'Juifenalm\'', str(soup))
+
     def test_rodelbahn_update_regioncache(self):
         result = self.app.get('/rodelbahn/update_regioncache', follow_redirects=True)
         self.assertEqual(result.status_code, 200)