Test embedded Model.DoesNotExist error
This commit is contained in:
parent
ef58e854c1
commit
b80addbb13
2 changed files with 15 additions and 14 deletions
|
@ -92,11 +92,7 @@ class RedisModelError(Exception):
|
||||||
|
|
||||||
|
|
||||||
class NotFoundError(Exception):
|
class NotFoundError(Exception):
|
||||||
"""
|
"""A query found no results."""
|
||||||
A query found no results.
|
|
||||||
|
|
||||||
TODO: embed in Model class?
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class Operators(Enum):
|
class Operators(Enum):
|
||||||
|
@ -671,14 +667,13 @@ class ModelMeta(ModelMetaclass):
|
||||||
key = f"{new_class.__module__}.{new_class.__name__}"
|
key = f"{new_class.__module__}.{new_class.__name__}"
|
||||||
model_registry[key] = new_class
|
model_registry[key] = new_class
|
||||||
|
|
||||||
if not hasattr(new_class, 'NotFoundError'):
|
|
||||||
new_class.add_to_class(
|
new_class.add_to_class(
|
||||||
'NotFoundError',
|
'NotFoundError',
|
||||||
subclass_exception(
|
subclass_exception(
|
||||||
'NotFoundError',
|
'NotFoundError',
|
||||||
tuple(
|
tuple(
|
||||||
x.NotFoundError for x in bases if hasattr(x, '_meta') and not issubclass(x, abc.ABC)
|
x.NotFoundError for x in bases if hasattr(x, '_meta') and not issubclass(x, abc.ABC)
|
||||||
),
|
) or (NotFoundError,),
|
||||||
attrs['__module__'],
|
attrs['__module__'],
|
||||||
attached_to=new_class))
|
attached_to=new_class))
|
||||||
|
|
||||||
|
|
|
@ -310,6 +310,12 @@ def test_sorting(members):
|
||||||
Member.find().sort_by('join_date').all()
|
Member.find().sort_by('join_date').all()
|
||||||
|
|
||||||
|
|
||||||
|
def test_not_found():
|
||||||
|
with pytest.raises(Member.NotFoundError):
|
||||||
|
# This ID does not exist.
|
||||||
|
Member.get(1000)
|
||||||
|
|
||||||
|
|
||||||
def test_schema():
|
def test_schema():
|
||||||
class Address(BaseHashModel):
|
class Address(BaseHashModel):
|
||||||
a_string: str = Field(index=True)
|
a_string: str = Field(index=True)
|
||||||
|
|
Loading…
Reference in a new issue