def test_center_on_initial_marker(self): widget = MapInput() widget.center_point = "(123456.864534, 155413452.23)" # tested before that assigned correctly settings.MAPBOX_KEY = "MY_COOL_MAPBOX_KEY" expected_js_list = [ "var map_attr_style = 'mapbox://styles/mapbox/outdoors-v11'", "var map_attr_zoom = '13'", "var map_attr_center = [123456.864534, 155413452.23]", "var map_attr_cursor_style = 'pointer'", "var map_attr_marker_color = 'red'", "var map_attr_rotate = false", "var map_attr_geocoder = true", "var map_attr_fullscreen_button = true", "var map_attr_navigation_buttons = true", "var map_attr_track_location_button = true" ] result = widget.get_config_settings() self.assertTrue( result.startswith( "<script>mapboxgl.accessToken = 'MY_COOL_MAPBOX_KEY';")) self.assertTrue(result.endswith("</script>")) crippled_result = result[52:-9] self.equality_of_random_javascript(crippled_result, expected_js_list)
def test_get_config_settings_updated_with_map_attrs(self): widget = MapInput(map_attrs={ "style": "cool style", "zoom": 90, "center": [1, 5.1], "cursor_style": 'cell', "marker_color": "blue", "rotate": True, "geocoder": False, "fullscreen_button": False, "navigation_buttons": False, "track_location_button": False, }) settings.MAPBOX_KEY = "MY_COOL_MAPBOX_KEY" expected_js_list = ["var map_attr_style = 'cool style'", "var map_attr_zoom = '90'", "var map_attr_center = [1, 5.1]", "var map_attr_cursor_style = 'cell'", "var map_attr_marker_color = 'blue'", "var map_attr_rotate = true", "var map_attr_geocoder = false", "var map_attr_fullscreen_button = false", "var map_attr_navigation_buttons = false", "var map_attr_track_location_button = false"] result = widget.get_config_settings() self.assertTrue(result.startswith("<script>mapboxgl.accessToken = 'MY_COOL_MAPBOX_KEY';")) self.assertTrue(result.endswith("</script>")) crippled_result = result[52:-9] self.equality_of_random_javascript(crippled_result, expected_js_list)
def test_get_config_settings_defaults(self): widget = MapInput() settings.MAPBOX_KEY = "MY_COOL_MAPBOX_KEY" expected_js_list = ["var map_attr_style = 'mapbox://styles/mapbox/outdoors-v11'", "var map_attr_zoom = '13'", "var map_attr_center = [51.106715, 17.031645]", "var map_attr_cursor_style = 'pointer'", "var map_attr_marker_color = 'red'", "var map_attr_rotate = false", "var map_attr_geocoder = true", "var map_attr_fullscreen_button = true", "var map_attr_navigation_buttons = true", "var map_attr_track_location_button = true"] result = widget.get_config_settings() self.assertTrue(result.startswith("<script>mapboxgl.accessToken = 'MY_COOL_MAPBOX_KEY';")) self.assertTrue(result.endswith("</script>")) crippled_result = result[52:-9] self.equality_of_random_javascript(crippled_result, expected_js_list)
def test_get_config_settings_defaults(self): widget = MapInput() settings.MAPBOX_KEY = "MY_COOL_MAPBOX_KEY" expected_map_attrs = { "style": "mapbox://styles/mapbox/outdoors-v11", "zoom": 13, "center": [17.031645, 51.106715], "cursor_style": 'pointer', "marker_color": "red", "rotate": False, "geocoder": True, "fullscreen_button": True, "navigation_buttons": True, "track_location_button": True, "id": "map" } result = widget.get_config_settings() self.assertEqual(result, expected_map_attrs)
def test_get_config_settings_updated_with_map_attrs(self): expected_map_attrs = { "style": "cool style", "zoom": 90, "center": [1, 5.1], "cursor_style": 'cell', "marker_color": "blue", "rotate": True, "geocoder": False, "fullscreen_button": False, "navigation_buttons": False, "track_location_button": False, "id": "test_map_id" } widget = MapInput(map_attrs=expected_map_attrs) result = widget.get_config_settings() for key in expected_map_attrs.keys(): self.assertEqual(result[key], expected_map_attrs[key])