]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blobdiff - tests/test_wradmin.py
Use flask_sqlalchemy to manage the database connection.
[philipp/winterrodeln/wradmin.git] / tests / test_wradmin.py
index 35b8a059269a530bcc35c9cf0d94705b698f9ed3..44dce22f7924ffb5ca322935cd7b8321cfcee4f9 100644 (file)
@@ -1,13 +1,17 @@
 import unittest
+
 import bs4  # beautiful soup
+
+import wradmin.app
 import wradmin.model
-import wradmin
+from wradmin.app import db
 
 
 class WradminTestBase(unittest.TestCase):
     def setUp(self):
         wradmin.app.config['TESTING'] = True
         self.app = wradmin.app.test_client()
+        self.db = db
 
     def login(self):
         return self.app.post('/login', data={'user_name': 'Johndoe', 'password': 'doejohn'}, follow_redirects=True)
@@ -55,7 +59,7 @@ class TestDbWradmin(WradminTestBase):
             # fill database
             with open('tests/testdb.sql', 'r') as f:
                 sql = f.read()
-            with wradmin.model.meta.engine.begin() as con:
+            with wradmin.db.engine.begin() as con:
                 con.execution_options(no_parameters=True).execute(sql)
 
                 # update dates
@@ -119,7 +123,6 @@ class TestDbWradmin(WradminTestBase):
         self.assertIn('2018-01-30 15:09:00', str(soup))
 
     def test_gasthaus_list(self):
-
         result = self.login_and_get('/gasthaus/list')
         self.assertEqual(result.status_code, 200)
         self.assertTrue(result.data.startswith(b'<!doctype html'))
@@ -144,10 +147,9 @@ class TestDbWradmin(WradminTestBase):
         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(14415)
+        text = self.db.session.query(wradmin.model.MwText).get(14415)
         text.old_text = text.old_text.replace('lindauerhuette@aon.at', 'abc@def@example.com')
-        session.commit()
+        self.db.session.commit()
         self.login()
         result = self.app.get('/gasthaus/update', follow_redirects=True)
         self.assertEqual(result.status_code, 200)
@@ -182,10 +184,9 @@ class TestDbWradmin(WradminTestBase):
         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(15032)
+        text = self.db.session.query(wradmin.model.MwText).get(15032)
         text.old_text = text.old_text.replace('Schwierigkeit        = mittel', 'Schwierigkeit        = geht so')
-        session.commit()
+        self.db.session.commit()
         self.login()
         result = self.app.get('/rodelbahn/update', follow_redirects=True)
         self.assertEqual(result.status_code, 200)