From 448145092c23074b5c3b6c0502358c1d7eface8b Mon Sep 17 00:00:00 2001 From: Alexander Filimonov Date: Fri, 17 Dec 2021 20:40:22 +0300 Subject: [PATCH] Refs #27674 -- Added tests for GISModelAdmin.gis_widget_kwargs. --- tests/gis_tests/geoadmin/models.py | 12 ++++++++++++ tests/gis_tests/geoadmin/tests.py | 18 +++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/gis_tests/geoadmin/models.py b/tests/gis_tests/geoadmin/models.py index 68390990397..115ed0624e0 100644 --- a/tests/gis_tests/geoadmin/models.py +++ b/tests/gis_tests/geoadmin/models.py @@ -14,8 +14,20 @@ class City(models.Model): return self.name +class CityAdminCustomWidgetKwargs(admin.GISModelAdmin): + gis_widget_kwargs = { + 'attrs': { + 'default_lat': 55, + 'default_lon': 37, + }, + } + + site = admin.AdminSite(name='gis_admin_modeladmin') site.register(City, admin.ModelAdmin) site_gis = admin.AdminSite(name='gis_admin_gismodeladmin') site_gis.register(City, admin.GISModelAdmin) + +site_gis_custom = admin.AdminSite(name='gis_admin_gismodeladmin') +site_gis_custom.register(City, CityAdminCustomWidgetKwargs) diff --git a/tests/gis_tests/geoadmin/tests.py b/tests/gis_tests/geoadmin/tests.py index 00191e193f0..2e4e4903ec0 100644 --- a/tests/gis_tests/geoadmin/tests.py +++ b/tests/gis_tests/geoadmin/tests.py @@ -1,7 +1,7 @@ from django.contrib.gis.geos import Point from django.test import SimpleTestCase, override_settings -from .models import City, site, site_gis +from .models import City, site, site_gis, site_gis_custom @override_settings(ROOT_URLCONF='django.contrib.gis.tests.geoadmin.urls') @@ -57,3 +57,19 @@ class GeoAdminTest(SimpleTestCase): class GISAdminTests(GeoAdminTest): admin_site = site_gis # GISModelAdmin + + def test_default_gis_widget_kwargs(self): + geoadmin = self.admin_site._registry[City] + form = geoadmin.get_changelist_form(None)() + widget = form['point'].field.widget + self.assertEqual(widget.attrs['default_lat'], 47) + self.assertEqual(widget.attrs['default_lon'], 5) + self.assertEqual(widget.attrs['default_zoom'], 12) + + def test_custom_gis_widget_kwargs(self): + geoadmin = site_gis_custom._registry[City] + form = geoadmin.get_changelist_form(None)() + widget = form['point'].field.widget + self.assertEqual(widget.attrs['default_lat'], 55) + self.assertEqual(widget.attrs['default_lon'], 37) + self.assertEqual(widget.attrs['default_zoom'], 12)