Repository: django/django
File: tests/backends/base/test_operations.py (Python)

Code before:
            Book.objects.create(author=author)
            author = Author.objects.create(name="Harper Lee")
            Book.objects.create(author=author)
            Book.objects.create(author=author)
            self.assertIs(Author.objects.exists(), True)
            self.assertIs(Book.objects.exists(), True)

        sql_list = connection.ops.sql_flush(
            no_style(),
            [Author._meta.db_table, Book._meta.db_table],
            reset_sequences=True,
            allow_cascade=True,
        )
        connection.ops.execute_sql_flush(sql_list)

        with transaction.atomic():
            self.assertIs(Author.objects.exists(), False)
            self.assertIs(Book.objects.exists(), False)
            if connection.features.supports_sequence_reset:
                author = Author.objects.create(name="F. Scott Fitzgerald")
                self.assertEqual(author.pk, 1)
                book = Book.objects.create(author=author)
                self.assertEqual(book.pk, 1)


class BulkBatchSizeMixin:
    def test_bulk_batch_size(self):
        if connection.vendor == "postgresql":
            connection.features.__dict__.pop("max_query_params", None)
            mock.patch.object(
                type(connection.features),
                "uses_server_side_binding",
                new_callable=mock.PropertyMock,
                return_value=True,
            ).start()

        max_query_params = connection.features.max_query_params
        objects = range(max_query_params + 1)
        first_name_field = Person._meta.get_field("first_name")
        last_name_field = Person._meta.get_field("last_name")
        composite_pk = models.CompositePrimaryKey("first_name", "last_name")
        composite_pk.fields = [first_name_field, last_name_field]

        self.assertEqual(connection.ops.bulk_batch_size([], objects), len(objects))
        self.assertEqual(
            connection.ops.bulk_batch_size([first_name_field], objects),
            max_query_params,
        )
        self.assertEqual(
            connection.ops.bulk_batch_size(
                [first_name_field, last_name_field], objects

Review comment (refactor):
I tweaked the test so it could still run on MySQL, allowing me to move this test into one of the above test cases and remove the mixin 👍 

Code after:
        with self.assertRaisesMessage(NotSupportedError, msg):
            self.ops.subtract_temporals(duration_field_internal_type, None, None)

    @skipUnlessDBFeature("max_query_params")
    def test_bulk_batch_size_limited(self):
        max_query_params = connection.features.max_query_params
        objects = range(max_query_params + 1)
        first_name_field = Person._meta.get_field("first_name")
        last_name_field = Person._meta.get_field("last_name")
        composite_pk = models.CompositePrimaryKey("first_name", "last_name")
        composite_pk.fields = [first_name_field, last_name_field]

        self.assertEqual(connection.ops.bulk_batch_size([], objects), len(objects))
        self.assertEqual(
            connection.ops.bulk_batch_size([first_name_field], objects),
            max_query_params,
        )
        self.assertEqual(
            connection.ops.bulk_batch_size(
                [first_name_field, last_name_field], objects
            ),
            max_query_params // 2,
        )
        self.assertEqual(
            connection.ops.bulk_batch_size([composite_pk, first_name_field], objects),
            max_query_params // 3,
        )

    @skipIfDBFeature("max_query_params")
    def test_bulk_batch_size_unlimited(self):
        objects = range(2**16 + 1)
        first_name_field = Person._meta.get_field("first_name")
        last_name_field = Person._meta.get_field("last_name")
        composite_pk = models.CompositePrimaryKey("first_name", "last_name")
        composite_pk.fields = [first_name_field, last_name_field]

        self.assertEqual(connection.ops.bulk_batch_size([], objects), len(objects))
        self.assertEqual(
            connection.ops.bulk_batch_size([first_name_field], objects),
            len(objects),
        )
        self.assertEqual(
            connection.ops.bulk_batch_size(
                [first_name_field, last_name_field], objects
            ),
            len(objects),
        )
        self.assertEqual(
            connection.ops.bulk_batch_size([composite_pk, first_name_field], objects),
            len(objects),
        )