]> ToastFreeware Gitweb - philipp/winterrodeln/wrfeed.git/blobdiff - tests/test_wrfeed.py
Test now works again (e.g. change DATABASE_URI to SQLALCHEMY_DATABASE_URI).
[philipp/winterrodeln/wrfeed.git] / tests / test_wrfeed.py
index 6397208ec4546aac3433652dc90d678d5362280b..aed5896cb19ce8661e8ed52385f1fcec312b75d2 100644 (file)
@@ -1,3 +1,11 @@
+"""How to test wrfeed:
+
+To prepare a system for testing, create a database philipp_winterrodeln_wiki_wrfeed_test with mysql:
+echo 'create database philipp_winterrodeln_wiki_wrfeed_test;' | mysql
+mysql philipp_winterrodeln_wiki_wrfeed_test < testdb.sql
+
+WRFEED_SETTINGS=../wrfeed/test.cfg python3 -m unittest tests/test_wrfeed.py
+"""
 import unittest
 import xml.etree.ElementTree as et
 import sqlalchemy
@@ -23,7 +31,7 @@ class TestDbWrfeed(WrfeedTestBase):
         super().setUp()
         with wrfeed.app.app_context():
             # create database
-            uri = make_url(wrfeed.app.config['DATABASE_URI'])
+            uri = make_url(wrfeed.app.config['SQLALCHEMY_DATABASE_URI'])
             self.uri = uri
             uri_nodb = URL(uri.drivername, host=uri.host, port=uri.port, username=uri.username, password=uri.password, query=uri.query)
             engine_nodb = sqlalchemy.create_engine(uri_nodb)
@@ -49,11 +57,6 @@ class TestDbWrfeed(WrfeedTestBase):
             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 tearDown(self):
-        with wrfeed.app.app_context():
-            self.engine.execute("DROP DATABASE {}".format(self.uri.database))
-
     def test_alle(self):
         result = self.app.get('/berichte/alle')
         self.assertTrue(result.data.startswith(b'<?xml'))
@@ -69,11 +72,12 @@ class TestDbWrfeed(WrfeedTestBase):
             'birgitzer_alm_(vom_adelshof)': 1,
         }
         for bahn, count in bahn_count.items():
-            result = self.app.get('/berichte/bahn/{}'.format(bahn))
-            self.assertTrue(result.data.startswith(b'<?xml'))
-            root = et.fromstring(result.data)
-            self.assertIn('Rodelbahnberichte', root.find('{http://www.w3.org/2005/Atom}title').text)
-            self.assertEqual(len(root.findall('{http://www.w3.org/2005/Atom}entry')), count, '"{}" not found {} times'.format(bahn, count))
+            with self.subTest(bahn=bahn):
+                result = self.app.get('/berichte/bahn/{}'.format(bahn))
+                self.assertTrue(result.data.startswith(b'<?xml'))
+                root = et.fromstring(result.data)
+                self.assertIn('Rodelbahnberichte', root.find('{http://www.w3.org/2005/Atom}title').text)
+                self.assertEqual(len(root.findall('{http://www.w3.org/2005/Atom}entry')), count, '"{}" not found {} times'.format(bahn, count))
 
     def test_bahnen(self):
         bahnen_count = {
@@ -87,11 +91,12 @@ class TestDbWrfeed(WrfeedTestBase):
             '761+1417+5+228': 5,
         }
         for bahnen, count in bahnen_count.items():
-            result = self.app.get('/berichte/bahnen/{}'.format(bahnen))
-            self.assertTrue(result.data.startswith(b'<?xml'))
-            root = et.fromstring(result.data)
-            self.assertIn('Rodelbahnberichte', root.find('{http://www.w3.org/2005/Atom}title').text)
-            self.assertEqual(len(root.findall('{http://www.w3.org/2005/Atom}entry')), count, 'bahnen "{}" not found {} times'.format(bahnen, count))
+            with self.subTest(bahnen=bahnen):
+                result = self.app.get('/berichte/bahnen/{}'.format(bahnen))
+                self.assertTrue(result.data.startswith(b'<?xml'))
+                root = et.fromstring(result.data)
+                self.assertIn('Rodelbahnberichte', root.find('{http://www.w3.org/2005/Atom}title').text)
+                self.assertEqual(len(root.findall('{http://www.w3.org/2005/Atom}entry')), count, 'bahnen "{}" not found {} times'.format(bahnen, count))
 
     def test_region(self):
         region_count = {
@@ -100,8 +105,9 @@ class TestDbWrfeed(WrfeedTestBase):
             'innsbruck': 3,
         }
         for region, count in region_count.items():
-            result = self.app.get('/berichte/region/{}'.format(region))
-            self.assertTrue(result.data.startswith(b'<?xml'))
-            root = et.fromstring(result.data)
-            self.assertIn('Rodelbahnberichte', root.find('{http://www.w3.org/2005/Atom}title').text)
-            self.assertEqual(len(root.findall('{http://www.w3.org/2005/Atom}entry')), count, '"{}" not found {} times'.format(region, count))
+            with self.subTest(region=region):
+                result = self.app.get('/berichte/region/{}'.format(region))
+                self.assertTrue(result.data.startswith(b'<?xml'))
+                root = et.fromstring(result.data)
+                self.assertIn('Rodelbahnberichte', root.find('{http://www.w3.org/2005/Atom}title').text)
+                self.assertEqual(len(root.findall('{http://www.w3.org/2005/Atom}entry')), count, '"{}" not found {} times'.format(region, count))