1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

[soc2009/multidb] Fixed the usage of using() on QuerySets in conjuction with create(), added tests for this

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/multidb@10922 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor
2009-06-04 16:13:14 +00:00
parent 96cf08295d
commit fbb6fda5f6
4 changed files with 10 additions and 34 deletions

View File

@@ -20,17 +20,11 @@ class DatabaseSettingTestCase(TestCase):
class ConnectionTestCase(TestCase):
def test_queries(self):
for connection in connections.all():
qn = connection.ops.quote_name
cursor = connection.cursor()
cursor.execute("""INSERT INTO %(table)s (%(col)s) VALUES (%%s)""" % {
'table': qn(Book._meta.db_table),
'col': qn(Book._meta.get_field_by_name('title')[0].column),
}, ('Dive Into Python',))
for db in connections:
Book.objects.using(db).create(title="Dive into Python")
for connection in connections.all():
qn = connection.ops.quote_name
cursor = connection.cursor()
cursor.execute("""SELECT * FROM %(table)s""" % {'table': qn(Book._meta.db_table)})
data = cursor.fetchall()
self.assertEqual('Dive Into Python', data[0][1])
for db in connections:
books = Book.objects.all().using(db)
self.assertEqual(books.count(), 1)
self.assertEqual(len(books), 1)
self.assertEqual(books[0].title, "Dive into Python")