Rewrote the backends test to be more portable. Was previously failing on MySQL.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6354 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
14754fa6d4
commit
7a6e9f7633
|
@ -1,4 +1,5 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.db import connection
|
||||||
|
|
||||||
class Square(models.Model):
|
class Square(models.Model):
|
||||||
root = models.IntegerField()
|
root = models.IntegerField()
|
||||||
|
@ -7,18 +8,27 @@ class Square(models.Model):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return "%s ** 2 == %s" % (self.root, self.square)
|
return "%s ** 2 == %s" % (self.root, self.square)
|
||||||
|
|
||||||
|
if connection.features.uses_case_insensitive_names:
|
||||||
|
t_convert = lambda x: x.upper()
|
||||||
|
else:
|
||||||
|
t_convert = lambda x: x
|
||||||
|
qn = connection.ops.quote_name
|
||||||
|
|
||||||
__test__ = {'API_TESTS': """
|
__test__ = {'API_TESTS': """
|
||||||
|
|
||||||
#4896: Test cursor.executemany
|
#4896: Test cursor.executemany
|
||||||
>>> from django.db import connection
|
>>> from django.db import connection
|
||||||
>>> cursor = connection.cursor()
|
>>> cursor = connection.cursor()
|
||||||
>>> cursor.executemany('INSERT INTO BACKENDS_SQUARE (ROOT, SQUARE) VALUES (%s, %s)',
|
>>> opts = Square._meta
|
||||||
... [(i, i**2) for i in range(-5, 6)]) and None or None
|
>>> f1, f2 = opts.get_field('root'), opts.get_field('square')
|
||||||
|
>>> query = ('INSERT INTO %s (%s, %s) VALUES (%%s, %%s)'
|
||||||
|
... % (t_convert(opts.db_table), qn(f1.column), qn(f2.column)))
|
||||||
|
>>> cursor.executemany(query, [(i, i**2) for i in range(-5, 6)]) and None or None
|
||||||
>>> Square.objects.order_by('root')
|
>>> Square.objects.order_by('root')
|
||||||
[<Square: -5 ** 2 == 25>, <Square: -4 ** 2 == 16>, <Square: -3 ** 2 == 9>, <Square: -2 ** 2 == 4>, <Square: -1 ** 2 == 1>, <Square: 0 ** 2 == 0>, <Square: 1 ** 2 == 1>, <Square: 2 ** 2 == 4>, <Square: 3 ** 2 == 9>, <Square: 4 ** 2 == 16>, <Square: 5 ** 2 == 25>]
|
[<Square: -5 ** 2 == 25>, <Square: -4 ** 2 == 16>, <Square: -3 ** 2 == 9>, <Square: -2 ** 2 == 4>, <Square: -1 ** 2 == 1>, <Square: 0 ** 2 == 0>, <Square: 1 ** 2 == 1>, <Square: 2 ** 2 == 4>, <Square: 3 ** 2 == 9>, <Square: 4 ** 2 == 16>, <Square: 5 ** 2 == 25>]
|
||||||
|
|
||||||
#4765: executemany with params=[] does nothing
|
#4765: executemany with params=[] does nothing
|
||||||
>>> cursor.executemany('INSERT INTO BACKENDS_SQUARE (ROOT, SQUARE) VALUES (%s, %s)', []) and None or None
|
>>> cursor.executemany(query, []) and None or None
|
||||||
>>> Square.objects.count()
|
>>> Square.objects.count()
|
||||||
11
|
11
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue