From d70f658fb15e99a6c473dd6f66cfd65f84d03949 Mon Sep 17 00:00:00 2001 From: collerek Date: Wed, 9 Dec 2020 16:30:46 +0100 Subject: [PATCH] change test to string format to compare to milisecond --- tests/test_inheritance_mixins.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/test_inheritance_mixins.py b/tests/test_inheritance_mixins.py index f63f1d9..f99068b 100644 --- a/tests/test_inheritance_mixins.py +++ b/tests/test_inheritance_mixins.py @@ -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