|
| 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 |
| 9 | +from django.contrib.gis.geos import GEOSGeometry |
7 | 10 | from django.contrib.staticfiles.testing import StaticLiveServerTestCase |
8 | 11 | from django.core import signing |
9 | 12 | from django.db import connection |
|
14 | 17 |
|
15 | 18 | from debug_toolbar.middleware import DebugToolbarMiddleware, show_toolbar |
16 | 19 | from debug_toolbar.panels import Panel |
| 20 | +from debug_toolbar.panels.sql.forms import SQLSelectForm |
17 | 21 | from debug_toolbar.toolbar import DebugToolbar |
18 | 22 |
|
19 | 23 | from .base import BaseTestCase, IntegrationTestCase |
@@ -236,6 +240,26 @@ def test_sql_explain_checks_show_toolbar(self): |
236 | 240 | ) |
237 | 241 | self.assertEqual(response.status_code, 404) |
238 | 242 |
|
| 243 | + @unittest.skipUnless(settings.USE_GIS, "Test only valid with gis support") |
| 244 | + def test_sql_explain_gis(self): |
| 245 | + from .models import Location |
| 246 | + |
| 247 | + db_table = Location._meta.db_table |
| 248 | + |
| 249 | + url = "/__debug__/sql_explain/" |
| 250 | + geom = GEOSGeometry("POLYGON((0 0, 0 1, 1 1, 0 0))") |
| 251 | + data = { |
| 252 | + "sql": f'SELECT "{db_table}"."point" FROM "{db_table}" WHERE "{db_table}"."point" @ {geom.hex} LIMIT 1', |
| 253 | + "raw_sql": f'SELECT "{db_table}"."point" FROM "{db_table}" WHERE "{db_table}"."point" @ %s LIMIT 1', |
| 254 | + "params": json.dumps([geom.hex]), |
| 255 | + "alias": "default", |
| 256 | + "duration": "0", |
| 257 | + } |
| 258 | + data["hash"] = SQLSelectForm().make_hash(data) |
| 259 | + |
| 260 | + response = self.client.post(url, data=data) |
| 261 | + self.assertEqual(response.status_code, 200) |
| 262 | + |
239 | 263 | @unittest.skipUnless( |
240 | 264 | connection.vendor == "postgresql", "Test valid only on PostgreSQL" |
241 | 265 | ) |
|
0 commit comments