|
| 1 | +import json |
1 | 2 | import os |
2 | 3 | import re |
3 | 4 | import unittest |
4 | 5 |
|
5 | 6 | import django |
6 | 7 | import html5lib |
| 8 | +from django.conf import settings |
7 | 9 | from django.contrib.staticfiles.testing import StaticLiveServerTestCase |
8 | 10 | from django.core import signing |
9 | 11 | from django.core.cache import cache |
|
16 | 18 | from debug_toolbar.forms import SignedDataForm |
17 | 19 | from debug_toolbar.middleware import DebugToolbarMiddleware, show_toolbar |
18 | 20 | from debug_toolbar.panels import Panel |
| 21 | +from debug_toolbar.panels.sql.forms import SQLSelectForm |
19 | 22 | from debug_toolbar.toolbar import DebugToolbar |
20 | 23 |
|
21 | 24 | from .base import BaseTestCase, IntegrationTestCase |
@@ -293,6 +296,27 @@ def test_sql_explain_checks_show_toolbar(self): |
293 | 296 | ) |
294 | 297 | self.assertEqual(response.status_code, 404) |
295 | 298 |
|
| 299 | + @unittest.skipUnless(settings.USE_GIS, "Test only valid with gis support") |
| 300 | + def test_sql_explain_gis(self): |
| 301 | + from django.contrib.gis.geos import GEOSGeometry |
| 302 | + from .models import Location |
| 303 | + |
| 304 | + db_table = Location._meta.db_table |
| 305 | + |
| 306 | + url = "/__debug__/sql_explain/" |
| 307 | + geom = GEOSGeometry("POLYGON((0 0, 0 1, 1 1, 0 0))") |
| 308 | + data = { |
| 309 | + "sql": f'SELECT "{db_table}"."point" FROM "{db_table}" WHERE "{db_table}"."point" @ {geom.hex} LIMIT 1', |
| 310 | + "raw_sql": f'SELECT "{db_table}"."point" FROM "{db_table}" WHERE "{db_table}"."point" @ %s LIMIT 1', |
| 311 | + "params": json.dumps([geom.hex]), |
| 312 | + "alias": "default", |
| 313 | + "duration": "0", |
| 314 | + } |
| 315 | + data["hash"] = SQLSelectForm().make_hash(data) |
| 316 | + |
| 317 | + response = self.client.post(url, data=data) |
| 318 | + self.assertEqual(response.status_code, 200) |
| 319 | + |
296 | 320 | @unittest.skipUnless( |
297 | 321 | connection.vendor == "postgresql", "Test valid only on PostgreSQL" |
298 | 322 | ) |
|
0 commit comments