Fixes the test suite.
This commit is contained in:
parent
2f56831316
commit
762456415a
|
@ -30,7 +30,7 @@ class APITestCase(TransactionTestCase):
|
|||
with connection.cursor() as cursor:
|
||||
cursor.execute(
|
||||
"INSERT INTO cachalot_test (name, public) "
|
||||
"VALUES ('test2', %s);", [1 if self.is_sqlite else 'true'])
|
||||
"VALUES ('test2', %s);", [1 if self.is_sqlite else True])
|
||||
|
||||
with self.assertNumQueries(0):
|
||||
data2 = list(Test.objects.values_list('name', flat=True))
|
||||
|
@ -51,7 +51,7 @@ class APITestCase(TransactionTestCase):
|
|||
with connection.cursor() as cursor:
|
||||
cursor.execute(
|
||||
"INSERT INTO cachalot_test (name, public) "
|
||||
"VALUES ('test2', %s);", [1 if self.is_sqlite else 'true'])
|
||||
"VALUES ('test2', %s);", [1 if self.is_sqlite else True])
|
||||
|
||||
with self.assertNumQueries(0):
|
||||
data2 = list(Test.objects.values_list('name', flat=True))
|
||||
|
|
|
@ -32,6 +32,8 @@ class Migration(migrations.Migration):
|
|||
('a_decimal', models.DecimalField(null=True, blank=True, max_digits=5, decimal_places=2)),
|
||||
('bin', models.BinaryField(null=True, blank=True)),
|
||||
('ip', models.GenericIPAddressField(null=True, blank=True)),
|
||||
('duration', models.DurationField(null=True, blank=True)),
|
||||
('uuid', models.UUIDField(null=True, blank=True)),
|
||||
],
|
||||
options={
|
||||
'ordering': ('name',),
|
||||
|
@ -53,10 +55,6 @@ class Migration(migrations.Migration):
|
|||
],
|
||||
bases=('cachalot.testparent',),
|
||||
),
|
||||
migrations.AddField('Test', 'duration',
|
||||
models.DurationField(null=True, blank=True)),
|
||||
migrations.AddField('Test', 'uuid',
|
||||
models.UUIDField(null=True, blank=True)),
|
||||
migrations.RunSQL('CREATE EXTENSION hstore;',
|
||||
hints={'extension': 'hstore'}),
|
||||
migrations.RunSQL('CREATE EXTENSION unaccent;',
|
||||
|
|
|
@ -638,7 +638,8 @@ class ReadTestCase(TransactionTestCase):
|
|||
for f in Test._meta.fields]
|
||||
attnames = [t[0] for t in attname_column_list]
|
||||
columns = [t[1] for t in attname_column_list]
|
||||
sql = 'SELECT %s FROM %s;' % (', '.join(columns), Test._meta.db_table)
|
||||
sql = "SELECT CAST('é' AS CHAR), %s FROM %s;" % (', '.join(columns),
|
||||
Test._meta.db_table)
|
||||
|
||||
with self.assertNumQueries(1):
|
||||
with connection.cursor() as cursor:
|
||||
|
@ -649,15 +650,19 @@ class ReadTestCase(TransactionTestCase):
|
|||
cursor.execute(sql)
|
||||
data2 = list(cursor.fetchall())
|
||||
self.assertListEqual(data2, data1)
|
||||
self.assertListEqual(data2, list(Test.objects.values_list(*attnames)))
|
||||
self.assertListEqual(
|
||||
data2,
|
||||
[('é',) + l for l in Test.objects.values_list(*attnames)])
|
||||
|
||||
@skipIf(connection.vendor == 'sqlite',
|
||||
'SQLite doesn’t accept bytes as raw query.')
|
||||
def test_cursor_execute_bytes(self):
|
||||
attname_column_list = [f.get_attname_column()
|
||||
for f in Test._meta.fields]
|
||||
attnames = [t[0] for t in attname_column_list]
|
||||
columns = [t[1] for t in attname_column_list]
|
||||
sql = "SELECT 'é', %s FROM %s;" % (', '.join(columns),
|
||||
Test._meta.db_table)
|
||||
sql = "SELECT CAST('é' AS CHAR), %s FROM %s;" % (', '.join(columns),
|
||||
Test._meta.db_table)
|
||||
sql = sql.encode('utf-8')
|
||||
|
||||
with self.assertNumQueries(1):
|
||||
|
@ -714,7 +719,8 @@ class ReadTestCase(TransactionTestCase):
|
|||
class ParameterTypeTestCase(TransactionTestCase):
|
||||
def setUp(self):
|
||||
self.is_sqlite = connection.vendor == 'sqlite'
|
||||
if connection.vendor == 'mysql':
|
||||
self.is_mysql = connection.vendor == 'mysql'
|
||||
if self.is_mysql:
|
||||
# We need to reopen the connection or Django
|
||||
# will execute an extra SQL request below.
|
||||
connection.cursor()
|
||||
|
@ -734,8 +740,6 @@ class ParameterTypeTestCase(TransactionTestCase):
|
|||
of a bulk_create of n objects from 1 to n.
|
||||
"""
|
||||
|
||||
is_mysql = connection.vendor == 'mysql'
|
||||
|
||||
with self.assertNumQueries(1):
|
||||
list(Test.objects.filter(bin=None))
|
||||
with self.assertNumQueries(0):
|
||||
|
@ -743,12 +747,12 @@ class ParameterTypeTestCase(TransactionTestCase):
|
|||
|
||||
with self.assertNumQueries(1):
|
||||
list(Test.objects.filter(bin=b'abc'))
|
||||
with self.assertNumQueries(0 if is_mysql else 1):
|
||||
with self.assertNumQueries(0 if self.is_mysql else 1):
|
||||
list(Test.objects.filter(bin=b'abc'))
|
||||
|
||||
with self.assertNumQueries(1):
|
||||
list(Test.objects.filter(bin=b'def'))
|
||||
with self.assertNumQueries(0 if is_mysql else 1):
|
||||
with self.assertNumQueries(0 if self.is_mysql else 1):
|
||||
list(Test.objects.filter(bin=b'def'))
|
||||
|
||||
def test_float(self):
|
||||
|
|
|
@ -838,7 +838,7 @@ class WriteTestCase(TransactionTestCase):
|
|||
with connection.cursor() as cursor:
|
||||
cursor.execute(
|
||||
"INSERT INTO cachalot_test (name, public) "
|
||||
"VALUES ('test1', %s)", [1 if self.is_sqlite else 'true'])
|
||||
"VALUES ('test1', %s)", [1 if self.is_sqlite else True])
|
||||
|
||||
with self.assertNumQueries(1):
|
||||
self.assertListEqual(
|
||||
|
@ -849,7 +849,7 @@ class WriteTestCase(TransactionTestCase):
|
|||
with connection.cursor() as cursor:
|
||||
cursor.execute(
|
||||
"INSERT INTO cachalot_test (name, public) "
|
||||
"VALUES ('test2', %s)", [1 if self.is_sqlite else 'true'])
|
||||
"VALUES ('test2', %s)", [1 if self.is_sqlite else True])
|
||||
|
||||
with self.assertNumQueries(1):
|
||||
self.assertListEqual(
|
||||
|
@ -860,7 +860,7 @@ class WriteTestCase(TransactionTestCase):
|
|||
with connection.cursor() as cursor:
|
||||
cursor.executemany(
|
||||
"INSERT INTO cachalot_test (name, public) "
|
||||
"VALUES ('test3', %s)", [[1 if self.is_sqlite else 'true']])
|
||||
"VALUES ('test3', %s)", [[1 if self.is_sqlite else True]])
|
||||
|
||||
with self.assertNumQueries(1):
|
||||
self.assertListEqual(
|
||||
|
|
Loading…
Reference in New Issue