b4509380336b7ff94a19f5c396f311b558391dc6
[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_googlemap_to_wrmap():
158     wikitext = u'''
159     <googlemap version="0.9" lat="47.113291" lon="11.272337" zoom="15" height="450">
160     (Parkplatz)47.114958,11.266026
161     Erster Parkplatz
162     
163     (Gasthaus) 47.114715, 11.266262, Alt Bärnbad (Gasthaus)
164     6#FF014E9A
165     47.114715,11.266262
166     47.114135,11.268381
167     47.113421,11.269322
168     47.11277,11.269979
169     47.112408,11.271119
170     </googlemap>
171     '''
172     attributes, coords, paths = wrpylib.mwmarkup.parse_googlemap(wikitext)
173     json = wrpylib.wrmwmarkup.googlemap_to_wrmap(attributes, coords, paths)
174     assert json['properties']['lon'] == 11.272337
175     assert json['properties']['lat'] == 47.113291
176     assert json['properties']['zoom'] == 15
177     assert json['properties']['height'] == 450
178     assert json['features'][0]['properties']['type'] == 'parkplatz'
179     assert json['features'][0]['properties']['name'] == 'Erster Parkplatz'
180     assert json['features'][0]['geometry']['coordinates'] == [11.266026, 47.114958]
181     assert json['features'][1]['properties']['type'] == 'gasthaus'
182     assert json['features'][1]['properties']['name'] == u'Alt Bärnbad (Gasthaus)'
183     assert json['features'][1]['geometry']['coordinates'] == [11.266262, 47.114715]
184     assert json['features'][2]['properties']['type'] == 'rodelbahn'
185     assert json['features'][2]['geometry']['coordinates'] == [
186         [11.266262, 47.114715],
187         [11.268381, 47.114135],
188         [11.269322, 47.113421],
189         [11.269979, 47.11277],
190         [11.271119, 47.112408]]
191
192
193 def test_parse_wrmap():
194     wikitext = u'''
195     <wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
196     <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 11.190454</gasthaus>
197     <parkplatz>47.245789 11.238971</parkplatz>
198     <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 11.238283</haltestelle>
199     <rodelbahn>
200         47.238587 11.203360
201         47.244951 11.230868
202         47.245470 11.237853
203     </rodelbahn>
204     </wrmap>
205     '''
206     json = wrpylib.wrmwmarkup.parse_wrmap(wikitext)
207     assert json['properties']['lon'] == 11.21408895
208     assert json['properties']['lat'] == 47.2417134
209     assert json['properties']['zoom'] == 14
210     assert json['properties']['width'] == 700
211     assert json['properties']['height'] == 400
212     assert json['features'][0]['properties']['type'] == 'gasthaus'
213     assert json['features'][0]['properties']['name'] == u'Rosskogelhütte'
214     assert json['features'][0]['properties']['wiki'] == u'Rosskogelhütte'
215     assert json['features'][0]['geometry']['coordinates'] == [11.190454, 47.240689]
216     assert json['features'][1]['properties']['type'] == 'parkplatz'
217     assert json['features'][1]['geometry']['coordinates'] == [11.238971, 47.245789]
218     assert json['features'][2]['properties']['type'] == 'haltestelle'
219     assert json['features'][2]['properties']['name'] == u'Oberperfuss Rangger Köpfl Lift'
220     assert json['features'][2]['geometry']['coordinates'] == [11.238283, 47.245711]
221     assert json['features'][3]['properties']['type'] == 'rodelbahn'
222     assert json['features'][3]['geometry']['coordinates'] == [
223         [11.203360, 47.238587],
224         [11.230868, 47.244951],
225         [11.237853, 47.245470]]
226
227
228 def test_create_wrmap():
229     geojson = {
230         'type': 'FeatureCollection',
231         'features':
232             [{
233                 'type': 'Feature',
234                 'geometry': {
235                     'type': 'Point',
236                     'coordinates': [11.190454, 47.240689]},
237                 'properties': {'type': 'gasthaus', 'name': u'Rosskogelhütte', 'wiki': u'Rosskogelhütte'}
238             }, {
239                 'type': 'Feature',
240                 'geometry': {
241                     'type': 'Point',
242                     'coordinates': [11.238971, 47.245789]},
243                 'properties': {'type': 'parkplatz'}
244             }, {
245                 'type': 'Feature',
246                 'geometry': {
247                     'type': 'Point',
248                     'coordinates': [11.238283, 47.245711]},
249                 'properties': {'type': 'haltestelle', 'name': u'Oberperfuss Rangger Köpfl Lift'}
250             }, {
251                 'type': 'Feature',
252                 'geometry': {
253                     'type': 'LineString',
254                     'coordinates': [
255                         [11.203360, 47.238587],
256                         [11.230868, 47.244951],
257                         [11.237853, 47.245470]]},
258                 'properties': {'type': 'rodelbahn'}
259             }],
260         'properties': {
261             'lon': 11.21408895,
262             'lat': 47.2417134,
263             'zoom': 14,
264             'width': 700,
265             'height': 400}
266     }
267
268     wikitext = wrpylib.wrmwmarkup.create_wrmap(geojson)
269     assert wikitext == textwrap.dedent(u'''\
270     <wrmap height="400" lat="47.241713" lon="11.214089" width="700" zoom="14">
271
272     <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 N 11.190454 E</gasthaus>
273     <parkplatz>47.245789 N 11.238971 E</parkplatz>
274     <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 N 11.238283 E</haltestelle>
275
276     <rodelbahn>
277     47.238587 N 11.203360 E
278     47.244951 N 11.230868 E
279     47.245470 N 11.237853 E
280     </rodelbahn>
281
282     </wrmap>''')
283