Created new function find_tag to find XML like tags.
[philipp/winterrodeln/wrpylib.git] / tests / test_wrmwmarkup.py
index 5ebfe1f6980f0c4f512ddefa854654ace5b84278..c38c823ee8a63e86f362532526171da190c82694 100644 (file)
@@ -1,7 +1,9 @@
 #!/usr/bin/python2.7
 # -*- coding: iso-8859-15 -*-
 import wrpylib.wrmwmarkup
+import wrpylib.mwmarkup
 import formencode
+import textwrap
 
 
 def test_rodelbahnbox_to_sledrun():
@@ -57,7 +59,7 @@ def test_gasthausbox_to_inn():
     wrpylib.wrmwmarkup.inn_to_gasthausbox(inn)
 
 
-def test_parse_googlemap():
+def test_googlemap_to_wrmap():
     wikitext = u'''
     <googlemap version="0.9" lat="47.113291" lon="11.272337" zoom="15">
     (Parkplatz)47.114958,11.266026
@@ -72,17 +74,18 @@ def test_parse_googlemap():
     47.112408,11.271119
     </googlemap>
     '''
-    attributes, json = wrpylib.wrmwmarkup.parse_googlemap(wikitext)
-    assert attributes['lon'] == 11.272337
-    assert attributes['lat'] == 47.113291
-    assert attributes['zoom'] == 15
-    assert json['features'][0]['properties']['type'] == 'carpark'
+    center, zoom, coords, paths = wrpylib.mwmarkup.parse_googlemap(wikitext)
+    json = wrpylib.wrmwmarkup.googlemap_to_wrmap(center, zoom, coords, paths)
+    assert json['properties']['lon'] == 11.272337
+    assert json['properties']['lat'] == 47.113291
+    assert json['properties']['zoom'] == 15
+    assert json['features'][0]['properties']['type'] == 'parkplatz'
     assert json['features'][0]['properties']['name'] == 'Erster Parkplatz'
     assert json['features'][0]['geometry']['coordinates'] == [11.266026, 47.114958]
-    assert json['features'][1]['properties']['type'] == 'inn'
+    assert json['features'][1]['properties']['type'] == 'gasthaus'
     assert json['features'][1]['properties']['name'] == u'Alt Bärnbad (Gasthaus)'
     assert json['features'][1]['geometry']['coordinates'] == [11.266262, 47.114715]
-    assert json['features'][2]['properties']['type'] == 'sledrun'
+    assert json['features'][2]['properties']['type'] == 'rodelbahn'
     assert json['features'][2]['geometry']['coordinates'] == [
         [11.266262, 47.114715],
         [11.268381, 47.114135],
@@ -127,7 +130,6 @@ def test_parse_wrmap():
 
 
 def test_create_wrmap():
-    attributes = {'lon': 11.21408895, 'lat': 47.2417134, 'zoom': 14, 'width': 700, 'height': 400}
     geojson = {
         'type': 'FeatureCollection',
         'features':
@@ -136,19 +138,19 @@ def test_create_wrmap():
                 'geometry': {
                     'type': 'Point',
                     'coordinates': [11.190454, 47.240689]},
-                'properties': {'type': 'inn', 'name': u'Rosskogelhütte', 'wiki': u'Rosskogelhütte'}
+                'properties': {'type': 'gasthaus', 'name': u'Rosskogelhütte', 'wiki': u'Rosskogelhütte'}
             }, {
                 'type': 'Feature',
                 'geometry': {
                     'type': 'Point',
                     'coordinates': [11.238971, 47.245789]},
-                'properties': {'type': 'carpark'}
+                'properties': {'type': 'parkplatz'}
             }, {
                 'type': 'Feature',
                 'geometry': {
                     'type': 'Point',
                     'coordinates': [11.238283, 47.245711]},
-                'properties': {'type': 'busstop', 'name': u'Oberperfuss Rangger Köpfl Lift'}
+                'properties': {'type': 'haltestelle', 'name': u'Oberperfuss Rangger Köpfl Lift'}
             }, {
                 'type': 'Feature',
                 'geometry': {
@@ -157,20 +159,29 @@ def test_create_wrmap():
                         [11.203360, 47.238587],
                         [11.230868, 47.244951],
                         [11.237853, 47.245470]]},
-                'properties': {'type': 'sledrun'}
-            }]
+                'properties': {'type': 'rodelbahn'}
+            }],
+        'properties': {
+            'lon': 11.21408895,
+            'lat': 47.2417134,
+            'zoom': 14,
+            'width': 700,
+            'height': 400}
     }
 
-    wikitext = wrpylib.wrmwmarkup.create_wrmap(attributes, geojson)
-    assert wikitext == u'''
-    <wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
-    <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 11.190454</gasthaus>
-    <parkplatz>47.245789 11.238971</parkplatz>
-    <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 11.238283</haltestelle>
+    wikitext = wrpylib.wrmwmarkup.create_wrmap(geojson)
+    assert wikitext == textwrap.dedent(u'''\
+    <wrmap height="400" lat="47.2417134" lon="11.21408895" width="700" zoom="14">
+
+    <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 N 11.190454 E</gasthaus>
+    <parkplatz>47.245789 N 11.238971 E</parkplatz>
+    <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 N 11.238283 E</haltestelle>
+
     <rodelbahn>
-        47.238587 11.203360
-        47.244951 11.230868
-        47.245470 11.237853
+    47.238587 N 11.203360 E
+    47.244951 N 11.230868 E
+    47.245470 N 11.237853 E
     </rodelbahn>
-    </wrmap>'''
+
+    </wrmap>''')