189c7c152f8fcad01b85bcf07b1032e3810b4e17
[philipp/winterrodeln/wrpylib.git] / tests / test_wrmwmarkup.py
1 #!/usr/bin/python2.7
2 # -*- coding: iso-8859-15 -*-
3 import wrpylib.wrmwmarkup
4 import formencode
5
6
7 def test_rodelbahnbox_to_sledrun():
8     wikitext = u'''== Allgemeines ==
9     {{Rodelbahnbox
10     | Position             = 47.309820 N 9.986508 E
11     | Position oben        = 
12     | Höhe oben            = 1244
13     | Position unten       = 
14     | Höhe unten           = 806
15     | Länge                = 5045
16     | Schwierigkeit        = 
17     | Lawinen              = gelegentlich
18     | Betreiber            = 
19     | Öffentliche Anreise  = Ja
20     | Gehzeit              = 105
21     | Aufstieg getrennt    = Nein
22     | Aufstiegshilfe       = Nein
23     | Beleuchtungsanlage   = Nein
24     | Beleuchtungstage     = 
25     | Rodelverleih         = Ja
26     | Gütesiegel           = 
27     | Webauskunft          = 
28     | Telefonauskunft      = +43-664-1808482 (Bergkristallhütte)
29     | Bild                 = Rodelbahn Bergkristallhütte 2009-03-03.jpg
30     | In Übersichtskarte   = Ja
31     | Forumid              = 72
32     }}
33     Die Rodelbahn zur Bergkristallhütte ist durchaus abwechslungsreich.'''
34     start, end, sledrun = wrpylib.wrmwmarkup.rodelbahnbox_to_sledrun(wikitext)
35     wrpylib.wrmwmarkup.sledrun_to_rodelbahnbox(sledrun, '1.3')
36
37
38
39 def test_gasthausbox_to_inn():
40     wikitext = u'''{{Gasthausbox
41     | Position          = 47.295549 N 9.986970 E
42     | Höhe              = 1250
43     | Betreiber         = 
44     | Sitzplätze        = 
45     | Übernachtung      = 
46     | Rauchfrei         = Nein
47     | Rodelverleih      = 
48     | Handyempfang      = A1; T-Mobile/Telering
49     | Homepage          = http://www.bergkristallhuette.com/
50     | E-Mail            = bergkristallhuette@gmx.at
51     | Telefon           = +43-664-1808482
52     | Bild              = Bergkritsallhütte 2009-02-07.JPG
53     | Rodelbahnen       = [[Bergkristallhütte]]
54     }}
55     Die Bergkristallhütte ist Teil des Boden-Vorsäß.'''
56     start, end, inn = wrpylib.wrmwmarkup.gasthausbox_to_inn(wikitext)
57     wrpylib.wrmwmarkup.inn_to_gasthausbox(inn)
58
59
60 def test_parse_googlemap():
61     wikitext = u'''
62     <googlemap version="0.9" lat="47.113291" lon="11.272337" zoom="15">
63     (Parkplatz)47.114958,11.266026
64     Erster Parkplatz
65     
66     (Gasthaus) 47.114715, 11.266262, Alt Bärnbad (Gasthaus)
67     6#FF014E9A
68     47.114715,11.266262
69     47.114135,11.268381
70     47.113421,11.269322
71     47.11277,11.269979
72     47.112408,11.271119
73     </googlemap>
74     '''
75     json = wrpylib.wrmwmarkup.parse_googlemap(wikitext)
76     assert json['properties']['lon'] == 11.272337
77     assert json['properties']['lat'] == 47.113291
78     assert json['properties']['zoom'] == 15
79     assert json['features'][0]['properties']['type'] == 'parkplatz'
80     assert json['features'][0]['properties']['name'] == 'Erster Parkplatz'
81     assert json['features'][0]['geometry']['coordinates'] == [11.266026, 47.114958]
82     assert json['features'][1]['properties']['type'] == 'gasthaus'
83     assert json['features'][1]['properties']['name'] == u'Alt Bärnbad (Gasthaus)'
84     assert json['features'][1]['geometry']['coordinates'] == [11.266262, 47.114715]
85     assert json['features'][2]['properties']['type'] == 'rodelbahn'
86     assert json['features'][2]['geometry']['coordinates'] == [
87         [11.266262, 47.114715],
88         [11.268381, 47.114135],
89         [11.269322, 47.113421],
90         [11.269979, 47.11277],
91         [11.271119, 47.112408]]
92
93
94 def test_parse_wrmap():
95     wikitext = u'''
96     <wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
97     <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 11.190454</gasthaus>
98     <parkplatz>47.245789 11.238971</parkplatz>
99     <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 11.238283</haltestelle>
100     <rodelbahn>
101         47.238587 11.203360
102         47.244951 11.230868
103         47.245470 11.237853
104     </rodelbahn>
105     </wrmap>
106     '''
107     json = wrpylib.wrmwmarkup.parse_wrmap(wikitext)
108     assert json['properties']['lon'] == 11.21408895
109     assert json['properties']['lat'] == 47.2417134
110     assert json['properties']['zoom'] == 14
111     assert json['properties']['width'] == 700
112     assert json['properties']['height'] == 400
113     assert json['features'][0]['properties']['type'] == 'gasthaus'
114     assert json['features'][0]['properties']['name'] == u'Rosskogelhütte'
115     assert json['features'][0]['properties']['wiki'] == u'Rosskogelhütte'
116     assert json['features'][0]['geometry']['coordinates'] == [11.190454, 47.240689]
117     assert json['features'][1]['properties']['type'] == 'parkplatz'
118     assert json['features'][1]['geometry']['coordinates'] == [11.238971, 47.245789]
119     assert json['features'][2]['properties']['type'] == 'haltestelle'
120     assert json['features'][2]['properties']['name'] == u'Oberperfuss Rangger Köpfl Lift'
121     assert json['features'][2]['geometry']['coordinates'] == [11.238283, 47.245711]
122     assert json['features'][3]['properties']['type'] == 'rodelbahn'
123     assert json['features'][3]['geometry']['coordinates'] == [
124         [11.203360, 47.238587],
125         [11.230868, 47.244951],
126         [11.237853, 47.245470]]
127
128
129 def test_create_wrmap():
130     attributes = {'lon': 11.21408895, 'lat': 47.2417134, 'zoom': 14, 'width': 700, 'height': 400}
131     geojson = {
132         'type': 'FeatureCollection',
133         'features':
134             [{
135                 'type': 'Feature',
136                 'geometry': {
137                     'type': 'Point',
138                     'coordinates': [11.190454, 47.240689]},
139                 'properties': {'type': 'inn', 'name': u'Rosskogelhütte', 'wiki': u'Rosskogelhütte'}
140             }, {
141                 'type': 'Feature',
142                 'geometry': {
143                     'type': 'Point',
144                     'coordinates': [11.238971, 47.245789]},
145                 'properties': {'type': 'carpark'}
146             }, {
147                 'type': 'Feature',
148                 'geometry': {
149                     'type': 'Point',
150                     'coordinates': [11.238283, 47.245711]},
151                 'properties': {'type': 'busstop', 'name': u'Oberperfuss Rangger Köpfl Lift'}
152             }, {
153                 'type': 'Feature',
154                 'geometry': {
155                     'type': 'LineString',
156                     'coordinates': [
157                         [11.203360, 47.238587],
158                         [11.230868, 47.244951],
159                         [11.237853, 47.245470]]},
160                 'properties': {'type': 'sledrun'}
161             }]
162     }
163
164     wikitext = wrpylib.wrmwmarkup.create_wrmap(attributes, geojson)
165     assert wikitext == u'''
166     <wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
167     <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 11.190454</gasthaus>
168     <parkplatz>47.245789 11.238971</parkplatz>
169     <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 11.238283</haltestelle>
170     <rodelbahn>
171         47.238587 11.203360
172         47.244951 11.230868
173         47.245470 11.237853
174     </rodelbahn>
175     </wrmap>'''
176