]> ToastFreeware Gitweb - philipp/winterrodeln/wrfeed.git/blobdiff - tests/test_wrfeed.py
Use subTest for test_bahn, test_bahnen and test_region.
[philipp/winterrodeln/wrfeed.git] / tests / test_wrfeed.py
index 172ea77194d62ac2d75ac878aee91220102808df..873ec436948dfc1ddf7d69241263d2e908299d94 100644 (file)
@@ -32,14 +32,14 @@ class TestDbWrfeed(WrfeedTestBase):
 
             # connect to database
             self.engine = sqlalchemy.create_engine(uri)
+            con = self.engine.connect()
 
             # fill database
             with open('tests/testdb.sql', 'r') as f:
                 sql = f.read()
-            self.engine.execute(sql)
+            con.execute(sql)
 
             # update dates
-            con = self.engine.connect()
             seconds_diff, = con.execute("SELECT TIMESTAMPDIFF(SECOND, '2017-03-31 07:00', now())").fetchone()
             seconds_diff = int(seconds_diff)
             con.execute("UPDATE wrreport SET date_report = DATE(date_report + INTERVAL %s SECOND) WHERE time_report IS NULL", (seconds_diff,))
@@ -69,8 +69,42 @@ 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 = {
+            '761': 2,
+            '793': 0,
+            '100': 0,
+            '1417': 1,
+            '5': 1,
+            '228': 1,
+            '793+100': 0,
+            '761+1417+5+228': 5,
+        }
+        for bahnen, count in bahnen_count.items():
+            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 = {
+            'tirol': 6,
+            'schweiz': 1,
+            'innsbruck': 3,
+        }
+        for region, count in region_count.items():
+            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))