compatibility with black
This commit is contained in:
parent
b887ea9623
commit
fbb3bf869c
@ -540,33 +540,34 @@ class IndexesTest(unittest.TestCase):
|
|||||||
BlogPost.objects.hint(("tags", 1)).count()
|
BlogPost.objects.hint(("tags", 1)).count()
|
||||||
|
|
||||||
def test_collation(self):
|
def test_collation(self):
|
||||||
base = {'locale': "en", 'strength': 2}
|
base = {"locale": "en", "strength": 2}
|
||||||
|
|
||||||
class BlogPost(Document):
|
class BlogPost(Document):
|
||||||
name = StringField()
|
name = StringField()
|
||||||
meta = {"indexes": [
|
meta = {
|
||||||
{"fields": ["name"], "name": 'name_index',
|
"indexes": [
|
||||||
'collation': base}
|
{"fields": ["name"], "name": "name_index", "collation": base}
|
||||||
]}
|
]
|
||||||
|
}
|
||||||
|
|
||||||
BlogPost.drop_collection()
|
BlogPost.drop_collection()
|
||||||
|
|
||||||
names = tuple("%sag %i" % ('t' if n % 2 == 0 else 'T', n) for n in range(10))
|
names = tuple("%sag %i" % ("t" if n % 2 == 0 else "T", n) for n in range(10))
|
||||||
for name in names:
|
for name in names:
|
||||||
BlogPost(name=name).save()
|
BlogPost(name=name).save()
|
||||||
|
|
||||||
query_result = BlogPost.objects.collation(base).order_by('name')
|
query_result = BlogPost.objects.collation(base).order_by("name")
|
||||||
self.assertEqual([x.name for x in query_result],
|
self.assertEqual(
|
||||||
sorted(names, key=lambda x: x.lower()))
|
[x.name for x in query_result], sorted(names, key=lambda x: x.lower())
|
||||||
|
)
|
||||||
self.assertEqual(10, query_result.count())
|
self.assertEqual(10, query_result.count())
|
||||||
|
|
||||||
incorrect_collation = {'arndom': 'wrdo'}
|
incorrect_collation = {"arndom": "wrdo"}
|
||||||
with self.assertRaises(OperationFailure):
|
with self.assertRaises(OperationFailure):
|
||||||
BlogPost.objects.collation(incorrect_collation).count()
|
BlogPost.objects.collation(incorrect_collation).count()
|
||||||
|
|
||||||
query_result = BlogPost.objects.collation({}).order_by('name')
|
query_result = BlogPost.objects.collation({}).order_by("name")
|
||||||
self.assertEqual([x.name for x in query_result],
|
self.assertEqual([x.name for x in query_result], sorted(names))
|
||||||
sorted(names))
|
|
||||||
|
|
||||||
def test_unique(self):
|
def test_unique(self):
|
||||||
"""Ensure that uniqueness constraints are applied to fields.
|
"""Ensure that uniqueness constraints are applied to fields.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user