diff --git a/agave/version.py b/agave/version.py index 7525d199..66a87bb6 100644 --- a/agave/version.py +++ b/agave/version.py @@ -1 +1 @@ -__version__ = '0.1.4' +__version__ = '0.1.5' diff --git a/requirements.txt b/requirements.txt index f2153d1f..093007ab 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ blinker==1.4 chalice==1.22.1 mongoengine==0.22.1 -cuenca-validations==0.8.0 +cuenca-validations==0.9.0 dnspython==2.1.0 diff --git a/setup.py b/setup.py index 08b5edee..3c84bda3 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ python_requires='>=3.8', install_requires=[ 'chalice>=1.16.0,<1.22.2', - 'cuenca-validations>=0.7,<0.9', + 'cuenca-validations>=0.9.0,<0.10.0', 'blinker>=1.4,<1.5', 'mongoengine>=0.20.0,<0.23.0', 'dnspython>=2.0.0,<2.2.0', diff --git a/tests/lib/test_model_helpers.py b/tests/lib/test_model_helpers.py index f1069bfd..9eeb467e 100644 --- a/tests/lib/test_model_helpers.py +++ b/tests/lib/test_model_helpers.py @@ -1,6 +1,10 @@ +import re from datetime import datetime as dt +from decimal import Decimal from enum import Enum +from typing import ClassVar +import pytest from mongoengine import ( BooleanField, ComplexDateTimeField, @@ -20,21 +24,24 @@ from agave.lib.mongoengine.enum_field import EnumField from agave.lib.mongoengine.model_helpers import mongo_to_dict +from agave.models.base import BaseModel -class Reference(Document): - pass +class Reference(Document, BaseModel): + meta: ClassVar = { + 'collection': 'references', + } class EnumType(Enum): member = 'name' -class Embedded(EmbeddedDocument): +class Embedded(EmbeddedDocument, BaseModel): name = StringField() -class TestModel(Document): +class TestModel(Document, BaseModel): str_field = StringField() int_field = IntField(default=1) float_field = FloatField(default=1.1) @@ -55,14 +62,22 @@ class TestModel(Document): __test__ = False -def test_mongo_to_dict(): - assert not mongo_to_dict(None) +@pytest.fixture +def model(): reference = Reference() reference.save() model = TestModel( - embedded_list_field=[Embedded(name='')], lazzy_list_field=[reference] + embedded_list_field=[Embedded(name='')], + lazzy_field=reference, + lazzy_list_field=[reference], ) model.save() + model.reload() + return model + + +def test_mongo_to_dict(model): + assert not mongo_to_dict(None) model_dict = mongo_to_dict(model, exclude_fields=['str_field']) assert 'id' in model_dict @@ -70,7 +85,7 @@ def test_mongo_to_dict(): assert 'complex_date_time_field' in model_dict assert model_dict['int_field'] == 1 assert model_dict['float_field'] == '1.1' - assert model_dict['decimal_field'] == 1.2 + assert model_dict['decimal_field'] == Decimal('1.2') assert model_dict['dict_field']['one'] == 1 assert model_dict['enum_field'] == 'name' assert model_dict['boolean_field'] is True @@ -78,6 +93,11 @@ def test_mongo_to_dict(): assert model_dict['enum_list_field'] == ['name'] assert model_dict['embedded_list_field'] == [{'name': ''}] assert model_dict['embedded_field'] == {} - assert model_dict['lazzy_field_uri'] is None + reference_reg = re.compile(r'\/references\/.{24}') + assert reference_reg.match(model_dict['lazzy_field_uri']) + assert len(model_dict['lazzy_list_field_uris']) == 1 + assert all( + reference_reg.match(field) + for field in model_dict['lazzy_list_field_uris'] + ) assert model_dict['generic_lazzy_field_uri'] is None - assert model_dict['lazzy_list_field_uris'] == ["Reference object"]