change test to string format to compare to milisecond

This commit is contained in:
collerek
2020-12-09 16:30:46 +01:00
parent 0f876a0cd9
commit d70f658fb1

View File

@ -57,7 +57,6 @@ def create_test_database():
def test_field_redefining_raises_error(): def test_field_redefining_raises_error():
with pytest.raises(ModelDefinitionError): with pytest.raises(ModelDefinitionError):
class WrongField(ormar.Model, DateFieldsMixins): # pragma: no cover class WrongField(ormar.Model, DateFieldsMixins): # pragma: no cover
class Meta(ormar.ModelMeta): class Meta(ormar.ModelMeta):
tablename = "wrongs" tablename = "wrongs"
@ -78,7 +77,6 @@ def test_field_redefining_in_second_raises_error():
id: int = ormar.Integer(primary_key=True) id: int = ormar.Integer(primary_key=True)
with pytest.raises(ModelDefinitionError): with pytest.raises(ModelDefinitionError):
class WrongField(ormar.Model, DateFieldsMixins): # pragma: no cover class WrongField(ormar.Model, DateFieldsMixins): # pragma: no cover
class Meta(ormar.ModelMeta): class Meta(ormar.ModelMeta):
tablename = "wrongs" tablename = "wrongs"
@ -89,6 +87,12 @@ def test_field_redefining_in_second_raises_error():
created_date: datetime.datetime = ormar.DateTime() 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 @pytest.mark.asyncio
async def test_fields_inherited_from_mixin(): async def test_fields_inherited_from_mixin():
async with db: async with db:
@ -126,11 +130,9 @@ async def test_fields_inherited_from_mixin():
.exclude_fields("updated_date") .exclude_fields("updated_date")
.get() .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.updated_date is not None
assert sub2.category.created_date.strftime( assert sub2.category.created_date == round_date_to_seconds(cat.created_date)
"%Y-%m-%d %H:%M:%S"
) == cat.created_date.strftime("%Y-%m-%d %H:%M:%S")
assert sub2.updated_date is None assert sub2.updated_date is None
assert sub2.category.created_by == "Sam" assert sub2.category.created_by == "Sam"
assert sub2.category.updated_by == cat.updated_by assert sub2.category.updated_by == cat.updated_by