# Path: mapwidgets/settings.py
# class MapWidgetSettings(object):
# 
#     def __init__(self, app_settings=None, defaults=None):
#         if app_settings:
#             if not isinstance(app_settings, (dict, tuple)):
#                 raise TypeError(_("MapWidget settings must be a tuple or dictionary"))
#             self._app_settings = app_settings
# 
#         self.defaults = defaults or DEFAULTS
# 
#     @property
#     def app_settings(self):
#         if not hasattr(self, '_app_settings'):
#             app_settings = getattr(django_settings, 'MAP_WIDGETS', {})
#             if not isinstance(app_settings, (dict, tuple)):
#                 raise TypeError(_("MapWidget settings must be a tuple or dictionary"))
# 
#             self._app_settings = getattr(django_settings, 'MAP_WIDGETS', {})
#         return self._app_settings
# 
#     def __getattr__(self, attr):
#         if attr not in self.defaults.keys():
#             raise AttributeError("Invalid settings key: '%s'. Please check the settings documentation http://django-map-widgets.readthedocs.io/en/latest/widgets/settings.html" % attr)
# 
#         try:
#             # Check if present attr in user settings
#             val = self.app_settings[attr]
# 
#             # Merge app tuple settings with defaults
#             if isinstance(val, tuple):
#                 try:
#                     app_bundle = OrderedDict(val)
#                     default_bundle = OrderedDict(self.defaults[attr])
#                     default_bundle.update(app_bundle)
#                     val = default_bundle
#                 except ValueError:
#                     raise ValueError(_("Invalid %s settings value. Please check the settings documentation http://django-map-widgets.readthedocs.io/en/latest/widgets/settings.html" % attr))
# 
#             # Merge app dict settings with defaults
#             if isinstance(val, dict):
#                 default_bundle = OrderedDict(self.defaults[attr])
#                 default_bundle.update(val)
#                 val = default_bundle
# 
#         except KeyError:
#             # Fall back to defaults
#             val = self.defaults[attr]
#             if isinstance(val, tuple):
#                 try:
#                     val = OrderedDict(val)
#                 except ValueError:
#                     raise ValueError(_("Invalid %s settings value. Please check the settings documentation http://django-map-widgets.readthedocs.io/en/latest/widgets/settings.html" % attr))
# 
#         # Cache the result
#         setattr(self, attr, val)
#         return val
# 
# DEFAULTS = {
#     "GooglePointFieldWidget": (
#         ("mapCenterLocationName", None),
#         ("mapCenterLocation", TIMEZONE_COORDINATES.get(getattr(django_settings, "TIME_ZONE", "UTC"))),
#         ("zoom", 6),
#         ("GooglePlaceAutocompleteOptions", {}),
#         ("markerFitZoom", 15),
#         ("streetViewControl", True),
#     ),
# 
#     "MapboxPointFieldWidget": (
#         ("mapCenterLocationName", None),
#         ("mapCenterLocation", TIMEZONE_COORDINATES.get(getattr(django_settings, "TIME_ZONE", "UTC"))),
#         ("zoom", 6),
#         ("markerFitZoom", 15),
#         ("access_token", ""),
#     ),
# 
#     "GoogleStaticMapWidget": (
#         ("zoom", 15),
#         ("size", "480x480"),
#         ("scale", ""),
#         ("format", ""),
#         ("maptype", ""),
#         ("path", ""),
#         ("visible", ""),
#         ("style", ""),
#         ("language", ""),
#         ("region", "")
#     ),
# 
#     "GoogleStaticMapMarkerSettings": (
#         ("size", "normal"),
#         ("color", ""),
#         ("icon", ""),
#     ),
# 
#     "GoogleStaticOverlayMapWidget": (
#         ("zoom", 15),
#         ("size", "480x480"),
#         ("thumbnail_size", "160x160"),
#         ("scale", ""),
#         ("format", ""),
#         ("maptype", ""),
#         ("path", ""),
#         ("visible", ""),
#         ("style", ""),
#         ("language", ""),
#         ("region", "")
#     ),
#     "LANGUAGE": "en",
#     "LIBRARIES": "places",
#     "MINIFED": not django_settings.DEBUG,
#     "GOOGLE_MAP_API_SIGNATURE": "",
#     "GOOGLE_MAP_API_KEY": "",
#     "MAPBOX_API_KEY": "",
# }


from collections import OrderedDict
from django.test import TestCase
from django.test.utils import override_settings
from mapwidgets.settings import MapWidgetSettings, DEFAULTS
        with override_settings(MAP_WIDGETS={}):
            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)

    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):

# Path: mapwidgets/settings.py
# class MapWidgetSettings(object):
# 
#     def __init__(self, app_settings=None, defaults=None):
#         if app_settings:
#             if not isinstance(app_settings, (dict, tuple)):
#                 raise TypeError(_("MapWidget settings must be a tuple or dictionary"))
#             self._app_settings = app_settings
# 
#         self.defaults = defaults or DEFAULTS
# 
#     @property
#     def app_settings(self):
#         if not hasattr(self, '_app_settings'):
#             app_settings = getattr(django_settings, 'MAP_WIDGETS', {})
#             if not isinstance(app_settings, (dict, tuple)):
#                 raise TypeError(_("MapWidget settings must be a tuple or dictionary"))
# 
#             self._app_settings = getattr(django_settings, 'MAP_WIDGETS', {})
#         return self._app_settings
# 
#     def __getattr__(self, attr):
#         if attr not in self.defaults.keys():
#             raise AttributeError("Invalid settings key: '%s'. Please check the settings documentation http://django-map-widgets.readthedocs.io/en/latest/widgets/settings.html" % attr)
# 
#         try:
#             # Check if present attr in user settings
#             val = self.app_settings[attr]
# 
#             # Merge app tuple settings with defaults
#             if isinstance(val, tuple):
#                 try:
#                     app_bundle = OrderedDict(val)
#                     default_bundle = OrderedDict(self.defaults[attr])
#                     default_bundle.update(app_bundle)
#                     val = default_bundle
#                 except ValueError:
#                     raise ValueError(_("Invalid %s settings value. Please check the settings documentation http://django-map-widgets.readthedocs.io/en/latest/widgets/settings.html" % attr))
# 
#             # Merge app dict settings with defaults
#             if isinstance(val, dict):
#                 default_bundle = OrderedDict(self.defaults[attr])
#                 default_bundle.update(val)
#                 val = default_bundle
# 
#         except KeyError:
#             # Fall back to defaults
#             val = self.defaults[attr]
#             if isinstance(val, tuple):
#                 try:
#                     val = OrderedDict(val)
#                 except ValueError:
#                     raise ValueError(_("Invalid %s settings value. Please check the settings documentation http://django-map-widgets.readthedocs.io/en/latest/widgets/settings.html" % attr))
# 
#         # Cache the result
#         setattr(self, attr, val)
#         return val
# 
# DEFAULTS = {
#     "GooglePointFieldWidget": (
#         ("mapCenterLocationName", None),
#         ("mapCenterLocation", TIMEZONE_COORDINATES.get(getattr(django_settings, "TIME_ZONE", "UTC"))),
#         ("zoom", 6),
#         ("GooglePlaceAutocompleteOptions", {}),
#         ("markerFitZoom", 15),
#         ("streetViewControl", True),
#     ),
# 
#     "MapboxPointFieldWidget": (
#         ("mapCenterLocationName", None),
#         ("mapCenterLocation", TIMEZONE_COORDINATES.get(getattr(django_settings, "TIME_ZONE", "UTC"))),
#         ("zoom", 6),
#         ("markerFitZoom", 15),
#         ("access_token", ""),
#     ),
# 
#     "GoogleStaticMapWidget": (
#         ("zoom", 15),
#         ("size", "480x480"),
#         ("scale", ""),
#         ("format", ""),
#         ("maptype", ""),
#         ("path", ""),
#         ("visible", ""),
#         ("style", ""),
#         ("language", ""),
#         ("region", "")
#     ),
# 
#     "GoogleStaticMapMarkerSettings": (
#         ("size", "normal"),
#         ("color", ""),
#         ("icon", ""),
#     ),
# 
#     "GoogleStaticOverlayMapWidget": (
#         ("zoom", 15),
#         ("size", "480x480"),
#         ("thumbnail_size", "160x160"),
#         ("scale", ""),
#         ("format", ""),
#         ("maptype", ""),
#         ("path", ""),
#         ("visible", ""),
#         ("style", ""),
#         ("language", ""),
#         ("region", "")
#     ),
#     "LANGUAGE": "en",
#     "LIBRARIES": "places",
#     "MINIFED": not django_settings.DEBUG,
#     "GOOGLE_MAP_API_SIGNATURE": "",
#     "GOOGLE_MAP_API_KEY": "",
#     "MAPBOX_API_KEY": "",
# }


# Path: tests/testapp/widgets/tests/test_settings.py
from collections import OrderedDict
from django.test import TestCase
from django.test.utils import override_settings
from mapwidgets.settings import MapWidgetSettings, DEFAULTS

        with override_settings(MAP_WIDGETS={}):
            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)

    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()