Add QuerySet.first_or_none (#1137)
* Add QuerySet.first_or_none * restore docstrings for exceptions --------- Co-authored-by: collerek <collerek@gmail.com>
This commit is contained in:
@ -451,6 +451,11 @@ async def test_offset():
|
||||
async def test_model_first():
|
||||
async with base_ormar_config.database:
|
||||
async with base_ormar_config.database.transaction(force_rollback=True):
|
||||
with pytest.raises(ormar.NoMatch):
|
||||
await User.objects.first()
|
||||
|
||||
assert await User.objects.first_or_none() is None
|
||||
|
||||
tom = await User.objects.create(name="Tom")
|
||||
jane = await User.objects.create(name="Jane")
|
||||
|
||||
@ -460,6 +465,9 @@ async def test_model_first():
|
||||
with pytest.raises(NoMatch):
|
||||
await User.objects.filter(name="Lucy").first()
|
||||
|
||||
assert await User.objects.first_or_none(name="Lucy") is None
|
||||
assert await User.objects.filter(name="Lucy").first_or_none() is None
|
||||
|
||||
assert await User.objects.order_by("name").first() == jane
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user