fix quoting in order_by, add get_or_none
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user