예제 #1
0
    def test_settings_validations(self):
        with override_settings(
                MAP_WIDGETS="invalid_map_widgets_settings_type"):
            self.assertRaises(
                TypeError,
                lambda: getattr(MapWidgetSettings(), "GooglePointFieldWidget"))

        invalid_tuple_settings = {
            "GooglePointFieldWidget": (("zoom", 12, "invalid_value"), )
        }

        with override_settings(MAP_WIDGETS=invalid_tuple_settings):
            self.assertRaises(
                ValueError,
                lambda: getattr(MapWidgetSettings(), "GooglePointFieldWidget"))

        # test custom settings parameter validations
        self.assertRaises(TypeError, lambda: MapWidgetSettings(app_settings=1))

        # test defaults parameter with invalid value
        self.assertRaises(
            ValueError,
            lambda: getattr(MapWidgetSettings(defaults=invalid_tuple_settings),
                            "GooglePointFieldWidget"),
        )
    def test_custom_settings_values(self):
        zoom = 11
        map_center = [34.5073509, -30.12775829]
        static_map_size = "320x320"

        custom_settings = {
            "GooglePointFieldWidget": (
                ("zoom", zoom),
                ("mapCenterLocation", map_center),
            ),
            "GoogleStaticMapWidget": (
                ("zoom", zoom),
                ("size", static_map_size),
            )
        }

        with override_settings(MAP_WIDGETS=custom_settings):
            mw_settings = MapWidgetSettings()

            google_point_widget_settings = mw_settings.GooglePointFieldWidget
            self.assertEqual(google_point_widget_settings.get("zoom"), zoom)
            self.assertEqual(
                google_point_widget_settings.get("mapCenterLocation"),
                map_center)

            google_point_static_widget_settings = mw_settings.GoogleStaticMapWidget
            self.assertEqual(google_point_static_widget_settings.get("zoom"),
                             zoom)
            self.assertEqual(google_point_static_widget_settings.get("size"),
                             static_map_size)
예제 #3
0
    def map_options(self):
        if not self.settings:  # pragma: no cover
            raise ImproperlyConfigured('%s requires either a definition of "settings"' % self.__class__.__name__)

        if not self.settings_namespace:  # pragma: no cover
            raise ImproperlyConfigured('%s requires either a definition of "settings_namespace"' % self.__class__.__name__)

        if self.custom_settings:
            custom_settings = MapWidgetSettings(app_settings=self.settings)
            return json.dumps(getattr(custom_settings, self.settings_namespace))
        return json.dumps(self.settings)
    def test_default_settings_values(self):
        mw_settings = MapWidgetSettings()

        google_point_widget_default_settings = OrderedDict(
            DEFAULTS["GooglePointFieldWidget"])
        self.assertEqual(mw_settings.GooglePointFieldWidget,
                         google_point_widget_default_settings)

        google_static_widget_default_settings = OrderedDict(
            DEFAULTS["GoogleStaticMapWidget"])
        self.assertEqual(mw_settings.GoogleStaticMapWidget,
                         google_static_widget_default_settings)

        google_static_widget_marker_default_settings = OrderedDict(
            DEFAULTS["GoogleStaticMapMarkerSettings"])
        self.assertEqual(mw_settings.GoogleStaticMapMarkerSettings,
                         google_static_widget_marker_default_settings)

        google_static_overlay_widget_default_settings = OrderedDict(
            DEFAULTS["GoogleStaticOverlayMapWidget"])
        self.assertEqual(mw_settings.GoogleStaticOverlayMapWidget,
                         google_static_overlay_widget_default_settings)