Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
 def test_get_contex_when_map_attrs_None(self):
     widget = MapInput()
     contex = widget.get_context("location_field", None, None)
     self.assertEqual(contex["widget"]["attrs"]["placeholder"],
                      "Pick a location on map below")
     self.assertTrue(contex["widget"]["attrs"]["readonly"])
     self.assertTrue(contex["widget"]["attrs"]["class"].endswith(
         " js-mapbox-input-location-field"))
    def test_get_contex(self):
        widget = MapInput(map_attrs={"readonly": False, "placeholder": "cool location field placeholder"})
        contex = widget.get_context("location_field", None,
                                    {"placeholder": "not cool location field placeholder", "readonly": True, })

        self.assertEqual(contex["widget"]["attrs"]["placeholder"], "cool location field placeholder")
        self.assertFalse(contex["widget"]["attrs"]["readonly"])
        self.assertTrue(contex["widget"]["attrs"]["class"].endswith(" js-mapbox-input-location-field"))
Exemplo n.º 5
0
    def test_render(self):
        settings.MAPBOX_KEY = "MY_COOL_MAPBOX_KEY"
        widget = MapInput(map_attrs={"placeholder": "cool-placeholder"})

        # expected_rend = '<input type="text" name="location" class="form-group js-mapbox-input-location-field" id="id_location" maxlength="63" required readonly placeholder="cool-placeholder">\n\n' + "<div id='secret-id-map-mapbox-location-field' class='location-field-map'></div>\n<div id='secret-id-geocoder-mapbox-location-field' class='location-field-geocoder'></div><script>mapboxgl.accessToken = 'MY_COOL_MAPBOX_KEY';var map_attr_style = 'mapbox://styles/mapbox/outdoors-v11';var map_attr_zoom = '13';var map_attr_center = [17.031645, 51.106715];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;</script>"

        rend = widget.render("location",
                             None,
                             attrs={
                                 "maxlength": 63,
                                 "class": "form-group",
                                 "required": True,
                                 "id": "id_location",
                             })

        rend_list1 = rend.split("\n")
        self.assertEqual(len(rend_list1), 4)

        input = rend_list1[0]
        empty_str = rend_list1[1]
        map_div = rend_list1[2]
        geocoder, js = rend_list1[3].split("<script>")

        self.assertEqual(empty_str, "")
        self.html_element_test(input, "<input ", ">", [
            'type="text"', 'name="location"', 'class="form-group',
            'js-mapbox-input-location-field"', 'id="id_location"',
            'maxlength="63"', 'required', 'readonly',
            'placeholder="cool-placeholder"'
        ])
        self.html_element_test(map_div, "<div ", "></div>", [
            "id='secret-id-map-mapbox-location-field'",
            "class='location-field-map'"
        ])
        self.html_element_test(geocoder, "<div ", "></div>", [
            "id='secret-id-geocoder-mapbox-location-field'",
            "class='location-field-geocoder'"
        ])
        self.assertTrue(js.endswith("</script>"))
        self.equality_of_random_javascript(js[:-9], [
            "mapboxgl.accessToken = 'MY_COOL_MAPBOX_KEY'",
            "var map_attr_style = 'mapbox://styles/mapbox/outdoors-v11'",
            "var map_attr_zoom = '13'",
            'var map_attr_center = [17.031645, 51.106715]',
            "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',
        ])
Exemplo n.º 6
0
    def test_map_attrs_to_javascript(self):
        widget = MapInput()
        map_attrs = {
            "list": [1, 2],
            "tuple": (1, 2),
            "bool": True,
            "string": "cool string",
            "int": 1,
            "float": 1.2,
        }

        javascript = widget.map_attrs_to_javascript(map_attrs)
        expected_js_list = ["var map_attr_list = [1, 2]", "var map_attr_tuple = [1, 2]", "var map_attr_bool = true",
                            "var map_attr_string = 'cool string'", "var map_attr_int = '1'",
                            "var map_attr_float = '1.2'"]
        self.equality_of_random_javascript(javascript, expected_js_list)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
 def test_map_attrs_customized(self):
     widget = MapInput(map_attrs={
         "readonly": False,
         "placeholder": "location",
         "zoom": 14
     })
     self.assertEqual(widget.map_attrs.get("zoom", 0), 14)
     self.assertEqual(widget.placeholder, "location")
     self.assertFalse(widget.readonly)
    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)
Exemplo n.º 10
0
    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])
Exemplo n.º 11
0
 def test_setting_center_point(self):
     widget = MapInput()
     widget.get_context("name", (1234.3, 2352145.6), {})
     self.assertEqual(widget.center_point, '(1234.3, 2352145.6)')
Exemplo n.º 12
0
 def test_map_attrs_defaults(self):
     widget = MapInput()
     self.assertEqual(widget.map_attrs, {})
     self.assertEqual(widget.placeholder, "Pick a location on map below")
     self.assertTrue(widget.readonly)
 def test_map_attrs_customized_language_attrs(self):
     widget = MapInput(map_attrs={"language": "pl", "message_404": "messsage"})
     self.assertEqual(widget.map_attrs.get("message_404", ""), "message")
     self.assertEqual(widget.map_attrs.get("language", ""), "pl")
Exemplo n.º 14
0
 def test_widget(self):
     field = SpatialLocationField()
     self.assertEqual(field.widget.__class__, MapInput().__class__)