1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed various tests on MySQL with MyISAM storage engine.

This commit is contained in:
Mariusz Felisiak 2022-04-14 12:54:27 +02:00
parent 331a460f8f
commit 8e89dfe1c2
8 changed files with 54 additions and 34 deletions

View File

@ -1440,19 +1440,18 @@ class ListFiltersTests(TestCase):
filterspec = changelist.get_filters(request)[0][-1]
self.assertEqual(filterspec.title, "department")
choices = list(filterspec.choices(changelist))
self.assertEqual(choices[0]["display"], "All")
self.assertIs(choices[0]["selected"], True)
self.assertEqual(choices[0]["query_string"], "?")
self.assertEqual(choices[1]["display"], "Development")
self.assertIs(choices[1]["selected"], False)
self.assertEqual(choices[1]["query_string"], "?department__code__exact=DEV")
self.assertEqual(choices[2]["display"], "Design")
self.assertIs(choices[2]["selected"], False)
self.assertEqual(choices[2]["query_string"], "?department__code__exact=DSN")
choices = [
(choice["display"], choice["selected"], choice["query_string"])
for choice in filterspec.choices(changelist)
]
self.assertCountEqual(
choices,
[
("All", True, "?"),
("Development", False, "?department__code__exact=DEV"),
("Design", False, "?department__code__exact=DSN"),
],
)
# Filter by Department=='Development' --------------------------------
@ -1466,19 +1465,18 @@ class ListFiltersTests(TestCase):
filterspec = changelist.get_filters(request)[0][-1]
self.assertEqual(filterspec.title, "department")
choices = list(filterspec.choices(changelist))
self.assertEqual(choices[0]["display"], "All")
self.assertIs(choices[0]["selected"], False)
self.assertEqual(choices[0]["query_string"], "?")
self.assertEqual(choices[1]["display"], "Development")
self.assertIs(choices[1]["selected"], True)
self.assertEqual(choices[1]["query_string"], "?department__code__exact=DEV")
self.assertEqual(choices[2]["display"], "Design")
self.assertIs(choices[2]["selected"], False)
self.assertEqual(choices[2]["query_string"], "?department__code__exact=DSN")
choices = [
(choice["display"], choice["selected"], choice["query_string"])
for choice in filterspec.choices(changelist)
]
self.assertCountEqual(
choices,
[
("All", False, "?"),
("Development", True, "?department__code__exact=DEV"),
("Design", False, "?department__code__exact=DSN"),
],
)
def test_lookup_with_dynamic_value(self):
"""

View File

@ -16,6 +16,9 @@ class Router:
db_for_write = db_for_read
def allow_relation(self, obj1, obj2, **hints):
return True
site = admin.AdminSite(name="test_adminsite")
site.register(Book)

View File

@ -15,6 +15,9 @@ class Router:
db_for_write = db_for_read
def allow_relation(self, obj1, obj2, **hints):
return True
site = admin.AdminSite(name="test_adminsite")
site.register(User, admin_class=UserAdmin)

View File

@ -694,8 +694,12 @@ class FkConstraintsTests(TransactionTestCase):
a.reporter_id = 30
with connection.constraint_checks_disabled():
a.save()
with self.assertRaises(IntegrityError):
try:
connection.check_constraints(table_names=[Article._meta.db_table])
except IntegrityError:
pass
else:
self.skipTest("This backend does not support integrity checks.")
transaction.set_rollback(True)
def test_check_constraints_sql_keywords(self):
@ -705,8 +709,12 @@ class FkConstraintsTests(TransactionTestCase):
obj.reporter_id = 30
with connection.constraint_checks_disabled():
obj.save()
with self.assertRaises(IntegrityError):
try:
connection.check_constraints(table_names=["order"])
except IntegrityError:
pass
else:
self.skipTest("This backend does not support integrity checks.")
transaction.set_rollback(True)

View File

@ -288,6 +288,9 @@ class TestRouter:
def db_for_write(self, model, **hints):
return "default"
def allow_relation(self, obj1, obj2, **hints):
return True
@override_settings(DATABASE_ROUTERS=[TestRouter()])
class ContentTypesMultidbTests(TestCase):

View File

@ -21,6 +21,9 @@ class Category(models.Model):
slug = models.SlugField(max_length=20)
url = models.CharField("The URL", max_length=40)
class Meta:
ordering = ("pk",)
def __str__(self):
return self.name

View File

@ -310,7 +310,7 @@ class RawQueryTests(TestCase):
("book_count", 1),
("book_count", 0),
)
authors = Author.objects.all()
authors = Author.objects.order_by("pk")
self.assertSuccessfulRawQuery(Author, query, authors, expected_annotations)
def test_white_space_query(self):

View File

@ -78,11 +78,13 @@ def natural_key_test(self, format):
# Deserialize and test.
books = list(serializers.deserialize(format, string_data))
self.assertEqual(len(books), 2)
self.assertEqual(books[0].object.title, book1["title"])
self.assertEqual(books[0].object.pk, adrian.pk)
self.assertEqual(books[1].object.title, book2["title"])
self.assertIsNone(books[1].object.pk)
self.assertCountEqual(
[(book.object.title, book.object.pk) for book in books],
[
(book1["title"], adrian.pk),
(book2["title"], None),
],
)
def natural_pk_mti_test(self, format):