fix quoting in order_by, add get_or_none

This commit is contained in:
collerek
2021-03-23 17:36:20 +01:00
parent b08d616dc0
commit 4ad843a6a5
14 changed files with 214 additions and 2 deletions

View File

@ -83,6 +83,18 @@ async def test_not_saved_raises_error(cleanup):
await post.categories.add(news)
@pytest.mark.asyncio
async def test_not_existing_raises_error(cleanup):
async with database:
guido = await Author(first_name="Guido", last_name="Van Rossum").save()
post = await Post.objects.create(title="Hello, M2M", author=guido)
with pytest.raises(NoMatch):
await post.categories.get()
assert await post.categories.get_or_none() is None
@pytest.mark.asyncio
async def test_assigning_related_objects(cleanup):
async with database:
@ -95,6 +107,9 @@ async def test_assigning_related_objects(cleanup):
# or from the other end:
await news.posts.add(post)
assert await post.categories.get_or_none(name="no exist") is None
assert await post.categories.get_or_none(name="News") == news
# Creating columns object from instance:
await post.categories.create(name="Tips")
assert len(post.categories) == 2