Improve type hints for tests/
This commit is contained in:
@@ -37,7 +37,7 @@ class Email(Model):
|
||||
email = fields.CharField(max_length=200, index=True)
|
||||
is_primary = fields.BooleanField(default=False)
|
||||
address = fields.CharField(max_length=200)
|
||||
users = fields.ManyToManyField("models.User")
|
||||
users: fields.ManyToManyRelation[User] = fields.ManyToManyField("models.User")
|
||||
|
||||
|
||||
def default_name():
|
||||
@@ -47,12 +47,14 @@ def default_name():
|
||||
class Category(Model):
|
||||
slug = fields.CharField(max_length=100)
|
||||
name = fields.CharField(max_length=200, null=True, default=default_name)
|
||||
user = fields.ForeignKeyField("models.User", description="User")
|
||||
user: fields.ForeignKeyRelation[User] = fields.ForeignKeyField(
|
||||
"models.User", description="User"
|
||||
)
|
||||
created_at = fields.DatetimeField(auto_now_add=True)
|
||||
|
||||
|
||||
class Product(Model):
|
||||
categories = fields.ManyToManyField("models.Category")
|
||||
categories: fields.ManyToManyRelation[Category] = fields.ManyToManyField("models.Category")
|
||||
name = fields.CharField(max_length=50)
|
||||
view_num = fields.IntField(description="View Num", default=0)
|
||||
sort = fields.IntField()
|
||||
@@ -74,7 +76,9 @@ class Config(Model):
|
||||
key = fields.CharField(max_length=20)
|
||||
value = fields.JSONField()
|
||||
status: Status = fields.IntEnumField(Status)
|
||||
user = fields.ForeignKeyField("models.User", description="User")
|
||||
user: fields.ForeignKeyRelation[User] = fields.ForeignKeyField(
|
||||
"models.User", description="User"
|
||||
)
|
||||
|
||||
|
||||
class NewModel(Model):
|
||||
|
||||
@@ -34,18 +34,24 @@ class User(Model):
|
||||
class Email(Model):
|
||||
email = fields.CharField(max_length=200)
|
||||
is_primary = fields.BooleanField(default=False)
|
||||
user = fields.ForeignKeyField("models_second.User", db_constraint=False)
|
||||
user: fields.ForeignKeyRelation[User] = fields.ForeignKeyField(
|
||||
"models_second.User", db_constraint=False
|
||||
)
|
||||
|
||||
|
||||
class Category(Model):
|
||||
slug = fields.CharField(max_length=200)
|
||||
name = fields.CharField(max_length=200)
|
||||
user = fields.ForeignKeyField("models_second.User", description="User")
|
||||
user: fields.ForeignKeyRelation[User] = fields.ForeignKeyField(
|
||||
"models_second.User", description="User"
|
||||
)
|
||||
created_at = fields.DatetimeField(auto_now_add=True)
|
||||
|
||||
|
||||
class Product(Model):
|
||||
categories = fields.ManyToManyField("models_second.Category")
|
||||
categories: fields.ManyToManyRelation[Category] = fields.ManyToManyField(
|
||||
"models_second.Category"
|
||||
)
|
||||
name = fields.CharField(max_length=50)
|
||||
view_num = fields.IntField(description="View Num")
|
||||
sort = fields.IntField()
|
||||
|
||||
@@ -35,18 +35,22 @@ class User(Model):
|
||||
class Email(Model):
|
||||
email = fields.CharField(max_length=200)
|
||||
is_primary = fields.BooleanField(default=False)
|
||||
user = fields.ForeignKeyField("models.User", db_constraint=False)
|
||||
user: fields.ForeignKeyRelation[User] = fields.ForeignKeyField(
|
||||
"models.User", db_constraint=False
|
||||
)
|
||||
|
||||
|
||||
class Category(Model):
|
||||
slug = fields.CharField(max_length=200)
|
||||
name = fields.CharField(max_length=200)
|
||||
user = fields.ForeignKeyField("models.User", description="User")
|
||||
user: fields.ForeignKeyRelation[User] = fields.ForeignKeyField(
|
||||
"models.User", description="User"
|
||||
)
|
||||
created_at = fields.DatetimeField(auto_now_add=True)
|
||||
|
||||
|
||||
class Product(Model):
|
||||
categories = fields.ManyToManyField("models.Category")
|
||||
categories: fields.ManyToManyRelation[Category] = fields.ManyToManyField("models.Category")
|
||||
name = fields.CharField(max_length=50)
|
||||
view_num = fields.IntField(description="View Num")
|
||||
sort = fields.IntField()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
@@ -971,14 +970,13 @@ def test_sort_all_version_files(mocker):
|
||||
]
|
||||
|
||||
|
||||
async def test_empty_migration(mocker) -> None:
|
||||
async def test_empty_migration(mocker, tmp_path: Path) -> None:
|
||||
mocker.patch("os.listdir", return_value=[])
|
||||
Migrate.app = "foo"
|
||||
expected_content = MIGRATE_TEMPLATE.format(upgrade_sql="", downgrade_sql="")
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
Migrate.migrate_location = temp_dir
|
||||
Migrate.migrate_location = tmp_path
|
||||
|
||||
migration_file = await Migrate.migrate("update", True)
|
||||
migration_file = await Migrate.migrate("update", True)
|
||||
|
||||
with open(Path(temp_dir, migration_file), "r") as f:
|
||||
assert f.read() == expected_content
|
||||
f = tmp_path / migration_file
|
||||
assert f.read_text() == expected_content
|
||||
|
||||
Reference in New Issue
Block a user