Refs #28574 -- Added test for XML format output to Queryset.explain().

This commit is contained in:
Wu Haotian 2021-07-05 14:17:31 +08:00 committed by Mariusz Felisiak
parent e4da365436
commit b3b04ad211
1 changed files with 8 additions and 0 deletions

View File

@ -1,4 +1,5 @@
import unittest import unittest
import xml.etree.ElementTree
from django.db import NotSupportedError, connection, transaction from django.db import NotSupportedError, connection, transaction
from django.db.models import Count from django.db.models import Count
@ -31,6 +32,13 @@ class ExplainTests(TestCase):
self.assertTrue(captured_queries[0]['sql'].startswith(connection.ops.explain_prefix)) self.assertTrue(captured_queries[0]['sql'].startswith(connection.ops.explain_prefix))
self.assertIsInstance(result, str) self.assertIsInstance(result, str)
self.assertTrue(result) self.assertTrue(result)
if format == 'xml':
try:
xml.etree.ElementTree.fromstring(result)
except xml.etree.ElementTree.ParseError as e:
self.fail(
f'QuerySet.explain() result is not valid XML: {e}'
)
@skipUnlessDBFeature('validates_explain_options') @skipUnlessDBFeature('validates_explain_options')
def test_unknown_options(self): def test_unknown_options(self):