From 0ce2ad9ca4623cfd6dc2515430c0ae8a1717a607 Mon Sep 17 00:00:00 2001 From: oliver Date: Wed, 7 Nov 2018 09:32:40 +0900 Subject: [PATCH] Used QuerySet.bulk_create() in a couple tests. --- tests/basic/tests.py | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/tests/basic/tests.py b/tests/basic/tests.py index d12322b7057..342c39ea340 100644 --- a/tests/basic/tests.py +++ b/tests/basic/tests.py @@ -238,19 +238,11 @@ class ModelTest(TestCase): def test_extra_method_select_argument_with_dashes_and_values(self): # The 'select' argument to extra() supports names with dashes in # them, as long as you use values(). - Article.objects.create( - headline="Article 10", - pub_date=datetime(2005, 7, 31, 12, 30, 45), - ) - Article.objects.create( - headline='Article 11', - pub_date=datetime(2008, 1, 1), - ) - Article.objects.create( - headline='Article 12', - pub_date=datetime(2008, 12, 31, 23, 59, 59, 999999), - ) - + Article.objects.bulk_create([ + Article(headline='Article 10', pub_date=datetime(2005, 7, 31, 12, 30, 45)), + Article(headline='Article 11', pub_date=datetime(2008, 1, 1)), + Article(headline='Article 12', pub_date=datetime(2008, 12, 31, 23, 59, 59, 999999)), + ]) dicts = Article.objects.filter( pub_date__year=2008).extra( select={'dashed-value': '1'}).values('headline', 'dashed-value') @@ -263,19 +255,11 @@ class ModelTest(TestCase): # If you use 'select' with extra() and names containing dashes on a # query that's *not* a values() query, those extra 'select' values # will silently be ignored. - Article.objects.create( - headline="Article 10", - pub_date=datetime(2005, 7, 31, 12, 30, 45), - ) - Article.objects.create( - headline='Article 11', - pub_date=datetime(2008, 1, 1), - ) - Article.objects.create( - headline='Article 12', - pub_date=datetime(2008, 12, 31, 23, 59, 59, 999999), - ) - + Article.objects.bulk_create([ + Article(headline='Article 10', pub_date=datetime(2005, 7, 31, 12, 30, 45)), + Article(headline='Article 11', pub_date=datetime(2008, 1, 1)), + Article(headline='Article 12', pub_date=datetime(2008, 12, 31, 23, 59, 59, 999999)), + ]) articles = Article.objects.filter( pub_date__year=2008).extra(select={'dashed-value': '1', 'undashedvalue': '2'}) self.assertEqual(articles[0].undashedvalue, 2)