]> ToastFreeware Gitweb - philipp/winterrodeln/wrfeed.git/blobdiff - tests/test_wrfeed.py
Add test_region.
[philipp/winterrodeln/wrfeed.git] / tests / test_wrfeed.py
index 5eaf220b91545f3087915b7633d28945a4b3e34e..c057b12dc62d3646a6026fc8554cc01e66b081f0 100644 (file)
@@ -1,4 +1,5 @@
 import unittest
+import xml.etree.ElementTree as et
 import sqlalchemy
 from sqlalchemy.engine.url import URL, make_url
 import wrfeed
@@ -37,6 +38,18 @@ class TestDbWrfeed(WrfeedTestBase):
                 sql = f.read()
             self.engine.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,))
+            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,))
+
+
     def tearDown(self):
         with wrfeed.app.app_context():
             self.engine.execute("DROP DATABASE {}".format(self.uri.database))
@@ -44,3 +57,33 @@ class TestDbWrfeed(WrfeedTestBase):
     def test_alle(self):
         result = self.app.get('/berichte/alle')
         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')), 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))