mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
[soc2009/multidb] Updated the test runner to support syncing all the databases django knows about so that tests can operate against more than one database
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/multidb@10895 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -2,6 +2,8 @@ from django.conf import settings
|
||||
from django.db import connections
|
||||
from django.test import TestCase
|
||||
|
||||
from models import Book
|
||||
|
||||
class DatabaseSettingTestCase(TestCase):
|
||||
def setUp(self):
|
||||
settings.DATABASES['__test_db'] = {
|
||||
@@ -15,3 +17,20 @@ class DatabaseSettingTestCase(TestCase):
|
||||
def test_db_connection(self):
|
||||
connections['default'].cursor()
|
||||
connections['__test_db'].cursor()
|
||||
|
||||
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 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])
|
||||
|
||||
Reference in New Issue
Block a user