summaryrefslogtreecommitdiff
path: root/tests/raw_query
diff options
context:
space:
mode:
authorShai Berger <shai@platonix.com>2013-06-28 06:15:03 +0300
committerShai Berger <shai@platonix.com>2013-06-28 06:59:10 +0300
commitd097417025e71286ad5bbde6e0a79caacabbbd64 (patch)
tree007c58c8787cee32cf68d08683b7c5294e8a4ad1 /tests/raw_query
parent7c0b72a826a3637b30a57553ac83f6b913c33134 (diff)
downloaddjango-d097417025e71286ad5bbde6e0a79caacabbbd64.tar.gz
Support 'pyformat' style parameters in raw queries, Refs #10070
Add support for Oracle, fix an issue with the repr of RawQuerySet, add tests and documentations. Also added a 'supports_paramstyle_pyformat' database feature, True by default, False for SQLite. Thanks Donald Stufft for review of documentation.
Diffstat (limited to 'tests/raw_query')
-rw-r--r--tests/raw_query/tests.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/tests/raw_query/tests.py b/tests/raw_query/tests.py
index e404c8b065..7242b8309b 100644
--- a/tests/raw_query/tests.py
+++ b/tests/raw_query/tests.py
@@ -3,7 +3,7 @@ from __future__ import absolute_import
from datetime import date
from django.db.models.query_utils import InvalidQuery
-from django.test import TestCase
+from django.test import TestCase, skipUnlessDBFeature
from .models import Author, Book, Coffee, Reviewer, FriendlyAuthor
@@ -123,10 +123,27 @@ class RawQueryTests(TestCase):
query = "SELECT * FROM raw_query_author WHERE first_name = %s"
author = Author.objects.all()[2]
params = [author.first_name]
- results = list(Author.objects.raw(query, params=params))
+ qset = Author.objects.raw(query, params=params)
+ results = list(qset)
self.assertProcessed(Author, results, [author])
self.assertNoAnnotations(results)
self.assertEqual(len(results), 1)
+ self.assertIsInstance(repr(qset), str)
+
+ @skipUnlessDBFeature('supports_paramstyle_pyformat')
+ def testPyformatParams(self):
+ """
+ Test passing optional query parameters
+ """
+ query = "SELECT * FROM raw_query_author WHERE first_name = %(first)s"
+ author = Author.objects.all()[2]
+ params = {'first': author.first_name}
+ qset = Author.objects.raw(query, params=params)
+ results = list(qset)
+ self.assertProcessed(Author, results, [author])
+ self.assertNoAnnotations(results)
+ self.assertEqual(len(results), 1)
+ self.assertIsInstance(repr(qset), str)
def testManyToMany(self):
"""