49ba2ab41fe963ccd13a3bb1611336b8da5bdec0
[philipp/winterrodeln/wrpylib.git] / tests / test_wrmwmarkup.py
1 #!/usr/bin/python2.7
2 # -*- coding: iso-8859-15 -*-
3 import collections
4 import wrpylib.wrmwmarkup
5 import wrpylib.mwmarkup
6 import formencode
7 import textwrap
8
9
10 def test_rodelbahnbox_to_sledrun():
11     wikitext = u'''== Allgemeines ==
12     {{Rodelbahnbox
13     | Position             = 47.309820 N 9.986508 E
14     | Position oben        = 
15     | Höhe oben            = 1244
16     | Position unten       = 
17     | Höhe unten           = 806
18     | Länge                = 5045
19     | Schwierigkeit        = 
20     | Lawinen              = gelegentlich
21     | Betreiber            = 
22     | Öffentliche Anreise  = Ja
23     | Gehzeit              = 105
24     | Aufstieg möglich     = Nein
25     | Aufstieg getrennt    = Nein
26     | Aufstiegshilfe       = Nein
27     | Beleuchtungsanlage   = Nein
28     | Beleuchtungstage     = 
29     | Rodelverleih         = Ja
30     | Gütesiegel           = 
31     | Webauskunft          = 
32     | Telefonauskunft      = +43-664-1808482 (Bergkristallhütte)
33     | Bild                 = Rodelbahn Bergkristallhütte 2009-03-03.jpg
34     | In Übersichtskarte   = Ja
35     | Forumid              = 72
36     }}
37     Die Rodelbahn zur Bergkristallhütte ist durchaus abwechslungsreich.'''
38     start, end, sledrun = wrpylib.wrmwmarkup.rodelbahnbox_to_sledrun(wikitext)
39     wrpylib.wrmwmarkup.sledrun_to_rodelbahnbox(sledrun)
40
41
42 def test_RodelbahnboxDictConverter():
43     v = wrpylib.wrmwmarkup.RodelbahnboxDictConverter()
44     other = collections.OrderedDict([
45         (u'Position', (47.30982, 9.986508)),
46         (u'Position oben', (None, None)),
47         (u'Höhe oben', 1244),
48         (u'Position unten', (None, None)),
49         (u'Höhe unten', 806),
50         (u'Länge', 5045),
51         (u'Schwierigkeit', None),
52         (u'Lawinen', 3),
53         (u'Betreiber', None),
54         (u'Öffentliche Anreise', 6),
55         (u'Aufstieg möglich', True),
56         (u'Aufstieg getrennt', (0.0, None)),
57         (u'Gehzeit', 105),
58         (u'Aufstiegshilfe', (False, None)),
59         (u'Beleuchtungsanlage', (0.0, None)),
60         (u'Beleuchtungstage', (None, None)),
61         (u'Rodelverleih', (True, u'Ja')),
62         (u'Gütesiegel', None),
63         (u'Webauskunft', None),
64         (u'Telefonauskunft', u'+43-664-1808482 (Bergkristallhütte)'),
65         (u'Bild', u'Rodelbahn Bergkristallhütte 2009-03-03.jpg'),
66         (u'In Übersichtskarte', True),
67         (u'Forumid', 72)])
68     sledrun = v.to_python(other)
69     assert sledrun.forum_id == 72
70     other2 = v.from_python(sledrun)
71     assert other == other2
72
73
74 def test_RodelbahnboxValidator():
75     v = wrpylib.wrmwmarkup.RodelbahnboxValidator()
76     wikitext = textwrap.dedent(u'''\
77     {{Rodelbahnbox
78     | Position             = 47.309820 N 9.986508 E
79     | Position oben        =
80     | Höhe oben            = 1244
81     | Position unten       =
82     | Höhe unten           = 806
83     | Länge                = 5045
84     | Schwierigkeit        =
85     | Lawinen              = gelegentlich
86     | Betreiber            =
87     | Öffentliche Anreise  = Ja
88     | Aufstieg möglich     = Nein
89     | Aufstieg getrennt    = Nein
90     | Gehzeit              = 105
91     | Aufstiegshilfe       = Nein
92     | Beleuchtungsanlage   = Nein
93     | Beleuchtungstage     =
94     | Rodelverleih         = Ja
95     | Gütesiegel           =
96     | Webauskunft          =
97     | Telefonauskunft      = +43-664-1808482 (Bergkristallhütte)
98     | Bild                 = Rodelbahn Bergkristallhütte 2009-03-03.jpg
99     | In Übersichtskarte   = Ja
100     | Forumid              = 72
101     }}''')
102     sledrun = v.to_python(wikitext)
103     wikitext2 = v.from_python(sledrun)
104     assert wikitext == wikitext2
105     wikitext = textwrap.dedent(u'''\
106     {{Rodelbahnbox
107     | Position             =
108     | Position oben        =
109     | Höhe oben            =
110     | Position unten       =
111     | Höhe unten           =
112     | Länge                =
113     | Schwierigkeit        =
114     | Lawinen              =
115     | Betreiber            =
116     | Öffentliche Anreise  =
117     | Aufstieg möglich     =
118     | Aufstieg getrennt    =
119     | Gehzeit              =
120     | Aufstiegshilfe       =
121     | Beleuchtungsanlage   =
122     | Beleuchtungstage     =
123     | Rodelverleih         =
124     | Gütesiegel           =
125     | Webauskunft          =
126     | Telefonauskunft      =
127     | Bild                 =
128     | In Übersichtskarte   =
129     | Forumid              =
130     }}''')
131     sledrun = v.to_python(wikitext)
132     wikitext2 = v.from_python(sledrun)
133     assert wikitext == wikitext2
134
135
136 def test_gasthausbox_to_inn():
137     wikitext = u'''{{Gasthausbox
138     | Position          = 47.295549 N 9.986970 E
139     | Höhe              = 1250
140     | Betreiber         = 
141     | Sitzplätze        = 
142     | Übernachtung      = 
143     | Rauchfrei         = Nein
144     | Rodelverleih      = 
145     | Handyempfang      = A1; T-Mobile/Telering
146     | Homepage          = http://www.bergkristallhuette.com/
147     | E-Mail            = bergkristallhuette@gmx.at
148     | Telefon           = +43-664-1808482
149     | Bild              = Bergkritsallhütte 2009-02-07.JPG
150     | Rodelbahnen       = [[Bergkristallhütte]]
151     }}
152     Die Bergkristallhütte ist Teil des Boden-Vorsäß.'''
153     start, end, inn = wrpylib.wrmwmarkup.gasthausbox_to_inn(wikitext)
154     wrpylib.wrmwmarkup.inn_to_gasthausbox(inn)
155
156
157 def test_GasthausboxDictConverter():
158     v = wrpylib.wrmwmarkup.GasthausboxDictConverter()
159     other = collections.OrderedDict([
160     (u'Position', (47.295549, 9.986970)),
161     (u'Höhe', 1250),
162     (u'Betreiber', None),
163     (u'Sitzplätze', None),
164     (u'Übernachtung', (None, None)),
165     (u'Rauchfrei', (True, False)),
166     (u'Rodelverleih', (None, None)),
167     (u'Handyempfang', u'A1; T-Mobile/Telering'),
168     (u'Homepage', u'http://www.bergkristallhuette.com/'),
169     (u'E-Mail', u'bergkristallhuette@gmx.at'),
170     (u'Telefon', u'+43-664-1808482'),
171     (u'Bild', u'Bergkritsallhütte 2009-02-07.JPG'),
172     (u'Rodelbahnen', u'[[Bergkristallhütte]]')])
173     inn = v.to_python(other)
174     assert inn.homepage == u'http://www.bergkristallhuette.com/'
175     other2 = v.from_python(inn)
176     assert other == other2
177
178
179 def test_GasthausboxValidator():
180     v = wrpylib.wrmwmarkup.GasthausboxValidator()
181     wikitext = textwrap.dedent(u'''\
182     {{Gasthausbox
183     | Position          = 47.295549 N 9.986970 E
184     | Höhe              = 1250
185     | Betreiber         =
186     | Sitzplätze        =
187     | Übernachtung      =
188     | Rauchfrei         = Nein
189     | Rodelverleih      =
190     | Handyempfang      = A1; T-Mobile/Telering
191     | Homepage          = http://www.bergkristallhuette.com/
192     | E-Mail            = bergkristallhuette@gmx.at
193     | Telefon           = +43-664-1808482
194     | Bild              = Bergkritsallhütte 2009-02-07.JPG
195     | Rodelbahnen       = [[Bergkristallhütte]]
196     }}''')
197     inn = v.to_python(wikitext)
198     wikitext2 = v.from_python(inn)
199     assert wikitext == wikitext2
200
201
202 def test_googlemap_to_wrmap():
203     wikitext = u'''
204     <googlemap version="0.9" lat="47.113291" lon="11.272337" zoom="15" height="450">
205     (Parkplatz)47.114958,11.266026
206     Erster Parkplatz
207     
208     (Gasthaus) 47.114715, 11.266262, Alt Bärnbad (Gasthaus)
209     6#FF014E9A
210     47.114715,11.266262
211     47.114135,11.268381
212     47.113421,11.269322
213     47.11277,11.269979
214     47.112408,11.271119
215     </googlemap>
216     '''
217     attributes, coords, paths = wrpylib.mwmarkup.parse_googlemap(wikitext)
218     json = wrpylib.wrmwmarkup.googlemap_to_wrmap(attributes, coords, paths)
219     assert json['properties']['lon'] == 11.272337
220     assert json['properties']['lat'] == 47.113291
221     assert json['properties']['zoom'] == 15
222     assert json['properties']['height'] == 450
223     assert json['features'][0]['properties']['type'] == 'parkplatz'
224     assert json['features'][0]['properties']['name'] == 'Erster Parkplatz'
225     assert json['features'][0]['geometry']['coordinates'] == [11.266026, 47.114958]
226     assert json['features'][1]['properties']['type'] == 'gasthaus'
227     assert json['features'][1]['properties']['name'] == u'Alt Bärnbad (Gasthaus)'
228     assert json['features'][1]['geometry']['coordinates'] == [11.266262, 47.114715]
229     assert json['features'][2]['properties']['type'] == 'rodelbahn'
230     assert json['features'][2]['geometry']['coordinates'] == [
231         [11.266262, 47.114715],
232         [11.268381, 47.114135],
233         [11.269322, 47.113421],
234         [11.269979, 47.11277],
235         [11.271119, 47.112408]]
236
237
238 def test_parse_wrmap():
239     wikitext = u'''
240     <wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
241     <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 11.190454</gasthaus>
242     <parkplatz>47.245789 11.238971</parkplatz>
243     <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 11.238283</haltestelle>
244     <rodelbahn>
245         47.238587 11.203360
246         47.244951 11.230868
247         47.245470 11.237853
248     </rodelbahn>
249     </wrmap>
250     '''
251     json = wrpylib.wrmwmarkup.parse_wrmap(wikitext)
252     assert json['properties']['lon'] == 11.21408895
253     assert json['properties']['lat'] == 47.2417134
254     assert json['properties']['zoom'] == 14
255     assert json['properties']['width'] == 700
256     assert json['properties']['height'] == 400
257     assert json['features'][0]['properties']['type'] == 'gasthaus'
258     assert json['features'][0]['properties']['name'] == u'Rosskogelhütte'
259     assert json['features'][0]['properties']['wiki'] == u'Rosskogelhütte'
260     assert json['features'][0]['geometry']['coordinates'] == [11.190454, 47.240689]
261     assert json['features'][1]['properties']['type'] == 'parkplatz'
262     assert json['features'][1]['geometry']['coordinates'] == [11.238971, 47.245789]
263     assert json['features'][2]['properties']['type'] == 'haltestelle'
264     assert json['features'][2]['properties']['name'] == u'Oberperfuss Rangger Köpfl Lift'
265     assert json['features'][2]['geometry']['coordinates'] == [11.238283, 47.245711]
266     assert json['features'][3]['properties']['type'] == 'rodelbahn'
267     assert json['features'][3]['geometry']['coordinates'] == [
268         [11.203360, 47.238587],
269         [11.230868, 47.244951],
270         [11.237853, 47.245470]]
271
272
273 def test_create_wrmap():
274     geojson = {
275         'type': 'FeatureCollection',
276         'features':
277             [{
278                 'type': 'Feature',
279                 'geometry': {
280                     'type': 'Point',
281                     'coordinates': [11.190454, 47.240689]},
282                 'properties': {'type': 'gasthaus', 'name': u'Rosskogelhütte', 'wiki': u'Rosskogelhütte'}
283             }, {
284                 'type': 'Feature',
285                 'geometry': {
286                     'type': 'Point',
287                     'coordinates': [11.238971, 47.245789]},
288                 'properties': {'type': 'parkplatz'}
289             }, {
290                 'type': 'Feature',
291                 'geometry': {
292                     'type': 'Point',
293                     'coordinates': [11.238283, 47.245711]},
294                 'properties': {'type': 'haltestelle', 'name': u'Oberperfuss Rangger Köpfl Lift'}
295             }, {
296                 'type': 'Feature',
297                 'geometry': {
298                     'type': 'LineString',
299                     'coordinates': [
300                         [11.203360, 47.238587],
301                         [11.230868, 47.244951],
302                         [11.237853, 47.245470]]},
303                 'properties': {'type': 'rodelbahn'}
304             }],
305         'properties': {
306             'lon': 11.21408895,
307             'lat': 47.2417134,
308             'zoom': 14,
309             'width': 700,
310             'height': 400}
311     }
312
313     wikitext = wrpylib.wrmwmarkup.create_wrmap(geojson)
314     assert wikitext == textwrap.dedent(u'''\
315     <wrmap height="400" lat="47.241713" lon="11.214089" width="700" zoom="14">
316
317     <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 N 11.190454 E</gasthaus>
318     <parkplatz>47.245789 N 11.238971 E</parkplatz>
319     <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 N 11.238283 E</haltestelle>
320
321     <rodelbahn>
322     47.238587 N 11.203360 E
323     47.244951 N 11.230868 E
324     47.245470 N 11.237853 E
325     </rodelbahn>
326
327     </wrmap>''')
328