change test to string format to compare to milisecond
This commit is contained in:
@ -57,7 +57,6 @@ def create_test_database():
|
||||
|
||||
def test_field_redefining_raises_error():
|
||||
with pytest.raises(ModelDefinitionError):
|
||||
|
||||
class WrongField(ormar.Model, DateFieldsMixins): # pragma: no cover
|
||||
class Meta(ormar.ModelMeta):
|
||||
tablename = "wrongs"
|
||||
@ -78,7 +77,6 @@ def test_field_redefining_in_second_raises_error():
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
|
||||
with pytest.raises(ModelDefinitionError):
|
||||
|
||||
class WrongField(ormar.Model, DateFieldsMixins): # pragma: no cover
|
||||
class Meta(ormar.ModelMeta):
|
||||
tablename = "wrongs"
|
||||
@ -89,6 +87,12 @@ def test_field_redefining_in_second_raises_error():
|
||||
created_date: datetime.datetime = ormar.DateTime()
|
||||
|
||||
|
||||
def round_date_to_seconds(date: datetime.datetime) -> datetime.datetime:
|
||||
if date.microsecond >= 500000:
|
||||
date = date + datetime.timedelta(seconds=1)
|
||||
return date.replace(microsecond=0)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_fields_inherited_from_mixin():
|
||||
async with db:
|
||||
@ -122,15 +126,13 @@ async def test_fields_inherited_from_mixin():
|
||||
|
||||
sub2 = (
|
||||
await Subject.objects.select_related("category")
|
||||
.order_by("-created_date")
|
||||
.exclude_fields("updated_date")
|
||||
.get()
|
||||
.order_by("-created_date")
|
||||
.exclude_fields("updated_date")
|
||||
.get()
|
||||
)
|
||||
assert sub2.created_date.strftime("%Y-%m-%d %H:%M:%S") == sub.created_date.strftime("%Y-%m-%d %H:%M:%S")
|
||||
assert sub2.created_date == round_date_to_seconds(sub.created_date)
|
||||
assert sub2.category.updated_date is not None
|
||||
assert sub2.category.created_date.strftime(
|
||||
"%Y-%m-%d %H:%M:%S"
|
||||
) == cat.created_date.strftime("%Y-%m-%d %H:%M:%S")
|
||||
assert sub2.category.created_date == round_date_to_seconds(cat.created_date)
|
||||
assert sub2.updated_date is None
|
||||
assert sub2.category.created_by == "Sam"
|
||||
assert sub2.category.updated_by == cat.updated_by
|
||||
|
||||
Reference in New Issue
Block a user