summaryrefslogtreecommitdiff
path: root/tests/basic
diff options
context:
space:
mode:
authoroliver <myungsekyo@gmail.com>2018-11-07 09:32:40 +0900
committerTim Graham <timograham@gmail.com>2018-11-06 19:32:40 -0500
commit0ce2ad9ca4623cfd6dc2515430c0ae8a1717a607 (patch)
tree4246c75aa09645f333cd07f2ae77d3fc7417777e /tests/basic
parentb3b1d3d45fc066367f4fcacf0b06f72fcd00a9c6 (diff)
downloaddjango-0ce2ad9ca4623cfd6dc2515430c0ae8a1717a607.tar.gz
Used QuerySet.bulk_create() in a couple tests.
Diffstat (limited to 'tests/basic')
-rw-r--r--tests/basic/tests.py36
1 files changed, 10 insertions, 26 deletions
diff --git a/tests/basic/tests.py b/tests/basic/tests.py
index d12322b705..342c39ea34 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)