Skip to content

Commit 5836aee

Browse files
committed
Fix errors in test_operations
1 parent 7981048 commit 5836aee

File tree

1 file changed

+23
-61
lines changed

1 file changed

+23
-61
lines changed

tests/testapp/test_operations.py

Lines changed: 23 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66
from django.db import connection, migrations, models, transaction
7+
from django.db.migrations.operations.base import Operation
78
from django.db.migrations.state import ProjectState
89
from django.test import TransactionTestCase
910
from django.test.utils import CaptureQueriesContext
@@ -12,24 +13,26 @@
1213
from django_mysql.test.utils import override_mysql_variables
1314

1415

15-
def plugin_exists(plugin_name):
16+
def plugin_exists(plugin_name: str) -> bool:
1617
with connection.cursor() as cursor:
1718
cursor.execute(
1819
"""SELECT COUNT(*) FROM INFORMATION_SCHEMA.PLUGINS
1920
WHERE PLUGIN_NAME = %s""",
2021
(plugin_name,),
2122
)
22-
return cursor.fetchone()[0] > 0
23+
count: int = cursor.fetchone()[0]
24+
return count > 0
2325

2426

25-
def table_storage_engine(table_name):
27+
def table_storage_engine(table_name: str) -> str:
2628
with connection.cursor() as cursor:
2729
cursor.execute(
2830
"""SELECT ENGINE FROM INFORMATION_SCHEMA.TABLES
2931
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = %s""",
3032
(table_name,),
3133
)
32-
return cursor.fetchone()[0]
34+
engine: str = cursor.fetchone()[0]
35+
return engine
3336

3437

3538
class PluginOperationTests(TransactionTestCase):
@@ -168,21 +171,18 @@ def test_running_without_changes(self):
168171
operation.database_backwards("test_arstd", editor, new_state, project_state)
169172
assert table_storage_engine("test_arstd_pony") == "MyISAM"
170173

171-
# Copied from django core migration tests
174+
# Adapted from django core migration tests:
172175

173176
def set_up_test_model(
174177
self,
175-
app_label,
176-
second_model=False,
177-
third_model=False,
178-
related_model=False,
179-
mti_model=False,
180-
proxy_model=False,
181-
unique_together=False,
182-
options=False,
183-
db_table=None,
184-
index_together=False,
185-
): # pragma: no cover
178+
app_label: str,
179+
*,
180+
proxy_model: bool = False,
181+
unique_together: bool = False,
182+
options: bool = False,
183+
db_table: str | None = None,
184+
index_together: bool = False,
185+
) -> ProjectState: # pragma: no cover
186186
"""
187187
Creates a test model state and database table.
188188
"""
@@ -220,7 +220,7 @@ def set_up_test_model(
220220
model_options["permissions"] = [("can_groom", "Can groom")]
221221
if db_table:
222222
model_options["db_table"] = db_table
223-
operations = [
223+
operations: list[Operation] = [
224224
migrations.CreateModel(
225225
"Pony",
226226
[
@@ -231,49 +231,6 @@ def set_up_test_model(
231231
options=model_options,
232232
)
233233
]
234-
if second_model:
235-
operations.append(
236-
migrations.CreateModel(
237-
"Stable", [("id", models.AutoField(primary_key=True))]
238-
)
239-
)
240-
if third_model:
241-
operations.append(
242-
migrations.CreateModel(
243-
"Van", [("id", models.AutoField(primary_key=True))]
244-
)
245-
)
246-
if related_model:
247-
operations.append(
248-
migrations.CreateModel(
249-
"Rider",
250-
[
251-
("id", models.AutoField(primary_key=True)),
252-
("pony", models.ForeignKey("Pony")),
253-
("friend", models.ForeignKey("self")),
254-
],
255-
)
256-
)
257-
if mti_model:
258-
operations.append(
259-
migrations.CreateModel(
260-
"ShetlandPony",
261-
fields=[
262-
(
263-
"pony_ptr",
264-
models.OneToOneField(
265-
auto_created=True,
266-
primary_key=True,
267-
to_field="id",
268-
serialize=False,
269-
to="Pony",
270-
),
271-
),
272-
("cuteness", models.IntegerField(default=1)),
273-
],
274-
bases=["%s.Pony" % app_label],
275-
)
276-
)
277234
if proxy_model:
278235
operations.append(
279236
migrations.CreateModel(
@@ -286,7 +243,12 @@ def set_up_test_model(
286243

287244
return self.apply_operations(app_label, ProjectState(), operations)
288245

289-
def apply_operations(self, app_label, project_state, operations):
246+
def apply_operations(
247+
self,
248+
app_label: str,
249+
project_state: ProjectState,
250+
operations: list[Operation],
251+
) -> ProjectState:
290252
migration = migrations.Migration("name", app_label)
291253
migration.operations = operations
292254
with connection.schema_editor() as editor:

0 commit comments

Comments
 (0)