]> ToastFreeware Gitweb - philipp/winterrodeln/wrpylib.git/blobdiff - tests/test_wrmwmarkup.py
Create function optional_set.
[philipp/winterrodeln/wrpylib.git] / tests / test_wrmwmarkup.py
index d60129dc8742cf92cee04c263235d59a1ebdb945..273fa36c5b58e553250d463e1987a6684b0c4f49 100644 (file)
@@ -6,7 +6,8 @@ import wrpylib.wrvalidators
 import wrpylib.wrmwmarkup
 from wrpylib.wrvalidators import LonLat
 from wrpylib.wrmwmarkup import sledrun_from_rodelbahnbox, sledrun_to_rodelbahnbox, \
-    inn_from_gasthausbox, inn_to_gasthausbox, lonlat_ele_from_template, latlon_ele_to_template
+    inn_from_gasthausbox, inn_to_gasthausbox, lonlat_ele_from_template, latlon_ele_to_template, create_sledrun_wiki, \
+    lonlat_to_json, lonlat_ele_to_json
 
 
 class TestSledrun(unittest.TestCase):
@@ -22,7 +23,7 @@ class TestSledrun(unittest.TestCase):
             ('Länge', 5045),
             ('Schwierigkeit', 3),
             ('Lawinen', 2),
-            ('Betreiber', 'SchneeFunFit'),
+            ('Betreiber', (True, 'SchneeFunFit')),
             ('Öffentliche Anreise', 2),
             ('Aufstieg möglich', True),
             ('Aufstieg getrennt', (0.0, None)),
@@ -115,7 +116,7 @@ class TestSledrun(unittest.TestCase):
         self.assertEqual(rodelbahnbox['Länge'], 9644)
         self.assertEqual(rodelbahnbox['Schwierigkeit'], 3)
         self.assertEqual(rodelbahnbox['Lawinen'], 2)
-        self.assertEqual(rodelbahnbox['Betreiber'], 'McRodel')
+        self.assertEqual(rodelbahnbox['Betreiber'], (True, 'McRodel'))
         self.assertEqual(rodelbahnbox['Öffentliche Anreise'], 3)
         self.assertEqual(rodelbahnbox['Aufstieg möglich'], True)
         self.assertEqual(rodelbahnbox['Aufstieg getrennt'], (0.5, 'Nur unterer Teil'))
@@ -363,6 +364,25 @@ class TestLonlatEle(unittest.TestCase):
         template = latlon_ele_to_template((LonLat(11.468819, 46.942239), 1866), 'Position oben')
         self.assertEqual('{{Position oben|46.942239 N 11.468819 E|1866}}', template)
 
+    def test_lonlat_to_json(self):
+        actual = lonlat_to_json(LonLat(11.2, 47.6))
+        self.assertEqual({'longitude': 11.2, 'latitude': 47.6}, actual)
+
+    def test_lonlat_ele_to_json(self):
+        actual = lonlat_ele_to_json(LonLat(12.3, 42.9), 420)
+        expected = {'position': {'longitude': 12.3, 'latitude': 42.9}, 'elevation': 420}
+        self.assertEqual(expected, actual)
+
+        actual = lonlat_ele_to_json(LonLat(13.0, 40.1), None)
+        expected = {'position': {'longitude': 13.0, 'latitude': 40.1}}
+        self.assertEqual(expected, actual)
+
+        actual = lonlat_ele_to_json(None, 1580)
+        expected = {'elevation': 1580}
+        self.assertEqual(expected, actual)
+
+        self.assertEqual({}, lonlat_ele_to_json(None, None))
+
 
 class TestWrMap(unittest.TestCase):
     def test_parse_wrmap(self):
@@ -441,7 +461,7 @@ class TestWrMap(unittest.TestCase):
 
         wikitext = wrpylib.wrmwmarkup.create_wrmap(geojson)
         self.assertEqual(wikitext, textwrap.dedent('''\
-        <wrmap height="400" lat="47.241713" lon="11.214089" width="700" zoom="14">
+        <wrmap lon="11.214089" lat="47.241713" zoom="14" width="700" height="400">
 
         <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 N 11.190454 E</gasthaus>
         <parkplatz>47.245789 N 11.238971 E</parkplatz>
@@ -454,3 +474,9 @@ class TestWrMap(unittest.TestCase):
         </rodelbahn>
 
         </wrmap>'''))
+
+
+class TestWikiJson(unittest.TestCase):
+    def test_empty_json(self):
+        wiki_text = create_sledrun_wiki({}, None)
+        self.assertIsInstance(wiki_text, str)