1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Used QuerySet.bulk_create() in lookup.tests.

This commit is contained in:
JangHyukJin 2019-03-31 21:23:06 +09:00 committed by Mariusz Felisiak
parent 8335d59200
commit 0027ca76c7
2 changed files with 35 additions and 27 deletions

View File

@ -341,6 +341,7 @@ answer newbie questions, and generally made Django that much better:
Honza Král <honza.kral@gmail.com> Honza Král <honza.kral@gmail.com>
Horst Gutmann <zerok@zerokspot.com> Horst Gutmann <zerok@zerokspot.com>
Hugo Osvaldo Barrera <hugo@barrera.io> Hugo Osvaldo Barrera <hugo@barrera.io>
HyukJin Jang <wkdgurwls00@naver.com>
Hyun Mi Ae Hyun Mi Ae
Iacopo Spalletti <i.spalletti@nephila.it> Iacopo Spalletti <i.spalletti@nephila.it>
Ian A Wilson <http://ianawilson.com> Ian A Wilson <http://ianawilson.com>

View File

@ -478,10 +478,11 @@ class LookupTests(TestCase):
) )
def test_exclude(self): def test_exclude(self):
Article.objects.create(headline='Article_ with underscore', pub_date=datetime(2005, 11, 20)) Article.objects.bulk_create([
Article.objects.create(headline='Article% with percent sign', pub_date=datetime(2005, 11, 21)) Article(headline='Article_ with underscore', pub_date=datetime(2005, 11, 20)),
Article.objects.create(headline='Article with \\ backslash', pub_date=datetime(2005, 11, 22)) Article(headline='Article% with percent sign', pub_date=datetime(2005, 11, 21)),
Article(headline='Article with \\ backslash', pub_date=datetime(2005, 11, 22)),
])
# exclude() is the opposite of filter() when doing lookups: # exclude() is the opposite of filter() when doing lookups:
self.assertQuerysetEqual( self.assertQuerysetEqual(
Article.objects.filter(headline__contains='Article').exclude(headline__contains='with'), Article.objects.filter(headline__contains='Article').exclude(headline__contains='with'),
@ -606,15 +607,17 @@ class LookupTests(TestCase):
for a in Article.objects.all(): for a in Article.objects.all():
a.delete() a.delete()
now = datetime.now() now = datetime.now()
Article.objects.create(pub_date=now, headline='f') Article.objects.bulk_create([
Article.objects.create(pub_date=now, headline='fo') Article(pub_date=now, headline='f'),
Article.objects.create(pub_date=now, headline='foo') Article(pub_date=now, headline='fo'),
Article.objects.create(pub_date=now, headline='fooo') Article(pub_date=now, headline='foo'),
Article.objects.create(pub_date=now, headline='hey-Foo') Article(pub_date=now, headline='fooo'),
Article.objects.create(pub_date=now, headline='bar') Article(pub_date=now, headline='hey-Foo'),
Article.objects.create(pub_date=now, headline='AbBa') Article(pub_date=now, headline='bar'),
Article.objects.create(pub_date=now, headline='baz') Article(pub_date=now, headline='AbBa'),
Article.objects.create(pub_date=now, headline='baxZ') Article(pub_date=now, headline='baz'),
Article(pub_date=now, headline='baxZ'),
])
# zero-or-more # zero-or-more
self.assertQuerysetEqual( self.assertQuerysetEqual(
Article.objects.filter(headline__regex=r'fo*'), Article.objects.filter(headline__regex=r'fo*'),
@ -664,13 +667,15 @@ class LookupTests(TestCase):
) )
# and more articles: # and more articles:
Article.objects.create(pub_date=now, headline='foobar') Article.objects.bulk_create([
Article.objects.create(pub_date=now, headline='foobaz') Article(pub_date=now, headline='foobar'),
Article.objects.create(pub_date=now, headline='ooF') Article(pub_date=now, headline='foobaz'),
Article.objects.create(pub_date=now, headline='foobarbaz') Article(pub_date=now, headline='ooF'),
Article.objects.create(pub_date=now, headline='zoocarfaz') Article(pub_date=now, headline='foobarbaz'),
Article.objects.create(pub_date=now, headline='barfoobaz') Article(pub_date=now, headline='zoocarfaz'),
Article.objects.create(pub_date=now, headline='bazbaRFOO') Article(pub_date=now, headline='barfoobaz'),
Article(pub_date=now, headline='bazbaRFOO'),
])
# alternation # alternation
self.assertQuerysetEqual( self.assertQuerysetEqual(
@ -723,13 +728,15 @@ class LookupTests(TestCase):
def test_regex_backreferencing(self): def test_regex_backreferencing(self):
# grouping and backreferences # grouping and backreferences
now = datetime.now() now = datetime.now()
Article.objects.create(pub_date=now, headline='foobar') Article.objects.bulk_create([
Article.objects.create(pub_date=now, headline='foobaz') Article(pub_date=now, headline='foobar'),
Article.objects.create(pub_date=now, headline='ooF') Article(pub_date=now, headline='foobaz'),
Article.objects.create(pub_date=now, headline='foobarbaz') Article(pub_date=now, headline='ooF'),
Article.objects.create(pub_date=now, headline='zoocarfaz') Article(pub_date=now, headline='foobarbaz'),
Article.objects.create(pub_date=now, headline='barfoobaz') Article(pub_date=now, headline='zoocarfaz'),
Article.objects.create(pub_date=now, headline='bazbaRFOO') Article(pub_date=now, headline='barfoobaz'),
Article(pub_date=now, headline='bazbaRFOO'),
])
self.assertQuerysetEqual( self.assertQuerysetEqual(
Article.objects.filter(headline__regex=r'b(.).*b\1'), Article.objects.filter(headline__regex=r'b(.).*b\1'),
['<Article: barfoobaz>', '<Article: bazbaRFOO>', '<Article: foobarbaz>'] ['<Article: barfoobaz>', '<Article: bazbaRFOO>', '<Article: foobarbaz>']