Fix querying an embedded document field by an invalid value (#1440)
This commit is contained in:
committed by
Stefan Wójcik
parent
96d20756ca
commit
9f4b04ea0f
@@ -1266,7 +1266,7 @@ class QuerySetTest(unittest.TestCase):
|
||||
|
||||
def test_find_embedded(self):
|
||||
"""Ensure that an embedded document is properly returned from
|
||||
a query.
|
||||
different manners of querying.
|
||||
"""
|
||||
class User(EmbeddedDocument):
|
||||
name = StringField()
|
||||
@@ -1277,8 +1277,9 @@ class QuerySetTest(unittest.TestCase):
|
||||
|
||||
BlogPost.drop_collection()
|
||||
|
||||
user = User(name='Test User')
|
||||
BlogPost.objects.create(
|
||||
author=User(name='Test User'),
|
||||
author=user,
|
||||
content='Had a good coffee today...'
|
||||
)
|
||||
|
||||
@@ -1286,6 +1287,19 @@ class QuerySetTest(unittest.TestCase):
|
||||
self.assertTrue(isinstance(result.author, User))
|
||||
self.assertEqual(result.author.name, 'Test User')
|
||||
|
||||
result = BlogPost.objects.get(author__name=user.name)
|
||||
self.assertTrue(isinstance(result.author, User))
|
||||
self.assertEqual(result.author.name, 'Test User')
|
||||
|
||||
result = BlogPost.objects.get(author={'name': user.name})
|
||||
self.assertTrue(isinstance(result.author, User))
|
||||
self.assertEqual(result.author.name, 'Test User')
|
||||
|
||||
# Fails, since the string is not a type that is able to represent the
|
||||
# author's document structure (should be dict)
|
||||
with self.assertRaises(InvalidQueryError):
|
||||
BlogPost.objects.get(author=user.name)
|
||||
|
||||
def test_find_empty_embedded(self):
|
||||
"""Ensure that you can save and find an empty embedded document."""
|
||||
class User(EmbeddedDocument):
|
||||
|
||||
Reference in New Issue
Block a user