]> ToastFreeware Gitweb - philipp/winterrodeln/wrfeed.git/blobdiff - tests/test_wrfeed.py
Add test_region.
[philipp/winterrodeln/wrfeed.git] / tests / test_wrfeed.py
index 463afa1ac9124375c1d984158c7724687d3eaba3..c057b12dc62d3646a6026fc8554cc01e66b081f0 100644 (file)
@@ -42,8 +42,9 @@ class TestDbWrfeed(WrfeedTestBase):
             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)", (seconds_diff,))
-            con.execute("UPDATE wrreport SET time_report = TIME(time_report + INTERVAL %s SECOND)", (seconds_diff,))
+            con.execute("UPDATE wrreport SET date_report = DATE(date_report + INTERVAL %s SECOND) WHERE time_report IS NULL", (seconds_diff,))
+            con.execute("UPDATE wrreport SET date_report = DATE(TIMESTAMP(date_report, time_report) + INTERVAL %s SECOND) WHERE time_report IS NOT NULL", (seconds_diff,))
+            con.execute("UPDATE wrreport SET time_report = TIME(TIMESTAMP(date_report, time_report) + INTERVAL %s SECOND) WHERE time_report IS NOT NULL", (seconds_diff,))
             con.execute("UPDATE wrreport SET date_entry = date_entry + INTERVAL %s SECOND", (seconds_diff,))
             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,))
@@ -59,3 +60,30 @@ class TestDbWrfeed(WrfeedTestBase):
         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')), 7)
+
+    def test_bahn(self):
+        bahn_count = {
+            'haunold': 1,
+            'pleisenhütte_axamer_lizum': 2,
+            'prantner_alm': 0,
+            '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))
+
+    def test_region(self):
+        region_count = {
+            'tirol': 6,
+            'schweiz': 1,
+            '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))