fix coverage
This commit is contained in:
@ -12,3 +12,17 @@ repos:
|
|||||||
rev: v0.910
|
rev: v0.910
|
||||||
hooks:
|
hooks:
|
||||||
- id: mypy
|
- id: mypy
|
||||||
|
args: [--no-strict-optional, --ignore-missing-imports]
|
||||||
|
additional_dependencies: [
|
||||||
|
types-ujson>=0.1.1,
|
||||||
|
types-PyMySQL>=1.0.2,
|
||||||
|
types-ipaddress>=1.0.0,
|
||||||
|
types-enum34>=1.1.0,
|
||||||
|
types-cryptography>=3.3.5,
|
||||||
|
types-orjson>=3.6.0,
|
||||||
|
types-aiofiles>=0.1.9,
|
||||||
|
types-pkg-resources>=0.1.3,
|
||||||
|
types-requests>=2.25.9,
|
||||||
|
types-toml>=0.10.0,
|
||||||
|
pydantic>=1.8.2
|
||||||
|
]
|
||||||
|
|||||||
@ -63,7 +63,11 @@ def is_auto_primary_key(primary_key: bool, autoincrement: bool) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def convert_choices_if_needed(
|
def convert_choices_if_needed(
|
||||||
field_type: "Type", choices: Set, nullable: bool, scale: int = None
|
field_type: "Type",
|
||||||
|
choices: Set,
|
||||||
|
nullable: bool,
|
||||||
|
scale: int = None,
|
||||||
|
represent_as_str: bool = False,
|
||||||
) -> Set:
|
) -> Set:
|
||||||
"""
|
"""
|
||||||
Converts dates to isoformat as fastapi can check this condition in routes
|
Converts dates to isoformat as fastapi can check this condition in routes
|
||||||
@ -74,10 +78,14 @@ def convert_choices_if_needed(
|
|||||||
|
|
||||||
:param field_type: type o the field
|
:param field_type: type o the field
|
||||||
:type field_type: Type
|
:type field_type: Type
|
||||||
:param nullable: set of choices
|
:param choices: set of choices
|
||||||
:type nullable: Set
|
:type choices: Set
|
||||||
:param scale: scale for decimals
|
:param scale: scale for decimals
|
||||||
:type scale: int
|
:type scale: int
|
||||||
|
:param nullable: flag if field_nullable
|
||||||
|
:type nullable: bool
|
||||||
|
:param represent_as_str: flag for bytes fields
|
||||||
|
:type represent_as_str: bool
|
||||||
:param scale: scale for decimals
|
:param scale: scale for decimals
|
||||||
:type scale: int
|
:type scale: int
|
||||||
:return: value, choices list
|
:return: value, choices list
|
||||||
@ -88,6 +96,8 @@ def convert_choices_if_needed(
|
|||||||
if field_type == decimal.Decimal:
|
if field_type == decimal.Decimal:
|
||||||
precision = scale
|
precision = scale
|
||||||
choices = {encoder(o, precision) for o in choices}
|
choices = {encoder(o, precision) for o in choices}
|
||||||
|
elif field_type == bytes:
|
||||||
|
choices = {encoder(o, represent_as_str) for o in choices}
|
||||||
elif encoder:
|
elif encoder:
|
||||||
choices = {encoder(o) for o in choices}
|
choices = {encoder(o) for o in choices}
|
||||||
if nullable:
|
if nullable:
|
||||||
@ -138,6 +148,7 @@ class ModelFieldFactory:
|
|||||||
choices=choices,
|
choices=choices,
|
||||||
nullable=nullable,
|
nullable=nullable,
|
||||||
scale=kwargs.get("scale", None),
|
scale=kwargs.get("scale", None),
|
||||||
|
represent_as_str=kwargs.get("represent_as_base64_str", False),
|
||||||
)
|
)
|
||||||
|
|
||||||
namespace = dict(
|
namespace = dict(
|
||||||
|
|||||||
@ -63,6 +63,9 @@ def convert_value_if_needed(field: "BaseField", value: Any) -> Any:
|
|||||||
if field.__type__ == decimal.Decimal:
|
if field.__type__ == decimal.Decimal:
|
||||||
precision = field.scale # type: ignore
|
precision = field.scale # type: ignore
|
||||||
value = encoder(value, precision)
|
value = encoder(value, precision)
|
||||||
|
elif field.__type__ == bytes:
|
||||||
|
represent_as_string = field.represent_as_base64_str
|
||||||
|
value = encoder(value, represent_as_string)
|
||||||
elif encoder:
|
elif encoder:
|
||||||
value = encoder(value)
|
value = encoder(value)
|
||||||
return value
|
return value
|
||||||
|
|||||||
@ -121,8 +121,6 @@ def test_all_endpoints():
|
|||||||
"blob_col": blob.decode("utf-8"),
|
"blob_col": blob.decode("utf-8"),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if response.status_code != 200:
|
|
||||||
print(response.text)
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
item = Organisation(**response.json())
|
item = Organisation(**response.json())
|
||||||
assert item.pk is not None
|
assert item.pk is not None
|
||||||
|
|||||||
@ -14,7 +14,7 @@ class BaseMeta(ormar.ModelMeta):
|
|||||||
metadata = metadata
|
metadata = metadata
|
||||||
|
|
||||||
|
|
||||||
class TestModel(ormar.Model):
|
class NewTestModel(ormar.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
database = database
|
database = database
|
||||||
metadata = metadata
|
metadata = metadata
|
||||||
@ -37,5 +37,5 @@ def create_test_database():
|
|||||||
|
|
||||||
|
|
||||||
def test_model_field_order():
|
def test_model_field_order():
|
||||||
TestCreate = TestModel.get_pydantic(exclude={"a"})
|
TestCreate = NewTestModel.get_pydantic(exclude={"a"})
|
||||||
assert list(TestCreate.__fields__.keys()) == ["b", "c", "d", "e", "f"]
|
assert list(TestCreate.__fields__.keys()) == ["b", "c", "d", "e", "f"]
|
||||||
|
|||||||
Reference in New Issue
Block a user