|
| 1 | +import folium |
| 2 | +import folium.plugins |
| 3 | +from folium.utilities import temp_html_filepath |
| 4 | + |
| 5 | + |
| 6 | +def test_geojson(driver): |
| 7 | + """Verify that loading data in GeoJson works well for different use cases. |
| 8 | +
|
| 9 | + Prevent two regressions: |
| 10 | + - https://github.com/python-visualization/folium/pull/1190 |
| 11 | + - https://github.com/python-visualization/folium/pull/1289 |
| 12 | +
|
| 13 | + """ |
| 14 | + data_url = 'https://cdn.jsdelivr.net/gh/python-visualization/folium@master/examples/data/search_bars_rome.json' |
| 15 | + |
| 16 | + m = folium.Map((41.9, 12.5), zoom_start=10, tiles='cartodbpositron') |
| 17 | + marker_cluster = folium.plugins.MarkerCluster(name='cluster').add_to(m) |
| 18 | + folium.GeoJson(data_url, embed=False).add_to(marker_cluster) |
| 19 | + folium.GeoJson(data_url, embed=False, show=False, name='geojson').add_to(m) |
| 20 | + folium.LayerControl(collapsed=False).add_to(m) |
| 21 | + |
| 22 | + html = m.get_root().render() |
| 23 | + with temp_html_filepath(html) as filepath: |
| 24 | + driver.get_file(filepath) |
| 25 | + assert driver.wait_until('.folium-map') |
| 26 | + driver.verify_js_logs() |
| 27 | + # Verify the marker cluster is shown, it's a yellow icon with '18' in it. |
| 28 | + icon = driver.wait_until('.leaflet-marker-icon.marker-cluster > div > span') |
| 29 | + assert icon.text == '18' |
| 30 | + # Verify the second GeoJson layer is not shown, because we used show=False. |
| 31 | + control_label = driver.wait_until( |
| 32 | + '.leaflet-control-layers-overlays > label:nth-of-type(2)' |
| 33 | + ) |
| 34 | + assert control_label.text == 'geojson' |
| 35 | + control_input = control_label.find_element_by_css_selector('input') |
| 36 | + assert control_input.get_attribute('checked') is None |
0 commit comments