Fixed #31888 -- Avoided module-level MySQL queries in tests.

This commit is contained in:
Ahmad A. Hussein 2020-08-14 22:07:37 +02:00 committed by Mariusz Felisiak
parent 632ccffc49
commit 493b26bbfc
4 changed files with 31 additions and 34 deletions

View File

@ -1,7 +1,6 @@
import datetime import datetime
import re import re
from decimal import Decimal from decimal import Decimal
from unittest import skipIf
from django.core.exceptions import FieldError from django.core.exceptions import FieldError
from django.db import connection from django.db import connection
@ -1204,16 +1203,16 @@ class AggregateTestCase(TestCase):
]) ])
@skipUnlessDBFeature('supports_subqueries_in_group_by') @skipUnlessDBFeature('supports_subqueries_in_group_by')
@skipIf(
connection.vendor == 'mysql' and 'ONLY_FULL_GROUP_BY' in connection.sql_mode,
'GROUP BY optimization does not work properly when ONLY_FULL_GROUP_BY '
'mode is enabled on MySQL, see #31331.',
)
def test_aggregation_subquery_annotation_multivalued(self): def test_aggregation_subquery_annotation_multivalued(self):
""" """
Subquery annotations must be included in the GROUP BY if they use Subquery annotations must be included in the GROUP BY if they use
potentially multivalued relations (contain the LOOKUP_SEP). potentially multivalued relations (contain the LOOKUP_SEP).
""" """
if connection.vendor == 'mysql' and 'ONLY_FULL_GROUP_BY' in connection.sql_mode:
self.skipTest(
'GROUP BY optimization does not work properly when '
'ONLY_FULL_GROUP_BY mode is enabled on MySQL, see #31331.'
)
subquery_qs = Author.objects.filter( subquery_qs = Author.objects.filter(
pk=OuterRef('pk'), pk=OuterRef('pk'),
book__name=OuterRef('book__name'), book__name=OuterRef('book__name'),

View File

@ -1,6 +1,5 @@
import datetime import datetime
from decimal import Decimal from decimal import Decimal
from unittest import skipIf
from django.core.exceptions import FieldDoesNotExist, FieldError from django.core.exceptions import FieldDoesNotExist, FieldError
from django.db import connection from django.db import connection
@ -647,12 +646,12 @@ class NonAggregateAnnotationTestCase(TestCase):
datetime.date(2008, 11, 3), datetime.date(2008, 11, 3),
]) ])
@skipIf(
connection.vendor == 'mysql' and 'ONLY_FULL_GROUP_BY' in connection.sql_mode,
'GROUP BY optimization does not work properly when ONLY_FULL_GROUP_BY '
'mode is enabled on MySQL, see #31331.',
)
def test_annotation_aggregate_with_m2o(self): def test_annotation_aggregate_with_m2o(self):
if connection.vendor == 'mysql' and 'ONLY_FULL_GROUP_BY' in connection.sql_mode:
self.skipTest(
'GROUP BY optimization does not work properly when '
'ONLY_FULL_GROUP_BY mode is enabled on MySQL, see #31331.'
)
qs = Author.objects.filter(age__lt=30).annotate( qs = Author.objects.filter(age__lt=30).annotate(
max_pages=Case( max_pages=Case(
When(book_contact_set__isnull=True, then=Value(0)), When(book_contact_set__isnull=True, then=Value(0)),

View File

@ -2,7 +2,7 @@ import datetime
import itertools import itertools
import unittest import unittest
from copy import copy from copy import copy
from unittest import mock, skipIf from unittest import mock
from django.core.management.color import no_style from django.core.management.color import no_style
from django.db import ( from django.db import (
@ -710,13 +710,13 @@ class SchemaTests(TransactionTestCase):
editor.alter_field(Foo, old_field, new_field, strict=True) editor.alter_field(Foo, old_field, new_field, strict=True)
Foo.objects.create() Foo.objects.create()
@skipIf( def test_alter_not_unique_field_to_primary_key(self):
if (
connection.vendor == 'mysql' and connection.vendor == 'mysql' and
connection.mysql_is_mariadb and connection.mysql_is_mariadb and
(10, 4, 3) < connection.mysql_version < (10, 5, 2), (10, 4, 3) < connection.mysql_version < (10, 5, 2)
'https://jira.mariadb.org/browse/MDEV-19598', ):
) self.skipTest('https://jira.mariadb.org/browse/MDEV-19598')
def test_alter_not_unique_field_to_primary_key(self):
# Create the table. # Create the table.
with connection.schema_editor() as editor: with connection.schema_editor() as editor:
editor.create_model(Author) editor.create_model(Author)
@ -2950,17 +2950,17 @@ class SchemaTests(TransactionTestCase):
editor.alter_field(Author, new_field, old_field, strict=True) editor.alter_field(Author, new_field, old_field, strict=True)
self.assertEqual(self.get_constraints_for_column(Author, 'weight'), []) self.assertEqual(self.get_constraints_for_column(Author, 'weight'), [])
@skipIf(
connection.vendor == 'mysql' and
connection.mysql_is_mariadb and
(10, 4, 12) < connection.mysql_version < (10, 5),
'https://jira.mariadb.org/browse/MDEV-22775',
)
def test_alter_pk_with_self_referential_field(self): def test_alter_pk_with_self_referential_field(self):
""" """
Changing the primary key field name of a model with a self-referential Changing the primary key field name of a model with a self-referential
foreign key (#26384). foreign key (#26384).
""" """
if (
connection.vendor == 'mysql' and
connection.mysql_is_mariadb and
(10, 4, 12) < connection.mysql_version < (10, 5)
):
self.skipTest('https://jira.mariadb.org/browse/MDEV-22775')
with connection.schema_editor() as editor: with connection.schema_editor() as editor:
editor.create_model(Node) editor.create_model(Node)
old_field = Node._meta.get_field('node_id') old_field = Node._meta.get_field('node_id')

View File

@ -378,21 +378,20 @@ if connection.features.interprets_empty_strings_as_nulls:
data[2]._meta.get_field('data').empty_strings_allowed and data[2]._meta.get_field('data').empty_strings_allowed and
data[3] is None)] data[3] is None)]
# Regression test for #8651 -- a FK to an object with PK of 0
# This won't work on MySQL without the NO_AUTO_VALUE_ON_ZERO SQL mode since it
# won't let you create an object with an autoincrement primary key of 0.
if connection.features.allows_auto_pk_0:
test_data.extend([
(data_obj, 0, Anchor, "Anchor 0"),
(fk_obj, 465, FKData, 0),
])
class SerializerDataTests(TestCase): class SerializerDataTests(TestCase):
pass pass
def serializerTest(self, format): def serializerTest(self, format):
# FK to an object with PK of 0. This won't work on MySQL without the
# NO_AUTO_VALUE_ON_ZERO SQL mode since it won't let you create an object
# with an autoincrement primary key of 0.
if connection.features.allows_auto_pk_0:
test_data.extend([
(data_obj, 0, Anchor, 'Anchor 0'),
(fk_obj, 465, FKData, 0),
])
# Create all the objects defined in the test data # Create all the objects defined in the test data
objects = [] objects = []