1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

[soc2009/multidb] Fix the remaining tests that were depending on the out of date setting.

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/multidb@11407 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor 2009-08-06 00:46:53 +00:00
parent 8ad4ea7b04
commit b7b5493fc3
11 changed files with 61 additions and 44 deletions

View File

@ -8,7 +8,7 @@ in the application directory, on in one of the directories named in the
``FIXTURE_DIRS`` setting. ``FIXTURE_DIRS`` setting.
""" """
from django.db import models from django.db import models, DEFAULT_DB_ALIAS
from django.conf import settings from django.conf import settings
class Category(models.Model): class Category(models.Model):
@ -100,7 +100,7 @@ __test__ = {'API_TESTS': """
# Database flushing does not work on MySQL with the default storage engine # Database flushing does not work on MySQL with the default storage engine
# because it requires transaction support. # because it requires transaction support.
if settings.DATABASE_ENGINE != 'mysql': if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] != 'mysql':
__test__['API_TESTS'] += \ __test__['API_TESTS'] += \
""" """
# Reset the database representation of this app. This will delete all data. # Reset the database representation of this app. This will delete all data.

View File

@ -4,7 +4,7 @@
This demonstrates features of the database API. This demonstrates features of the database API.
""" """
from django.db import models from django.db import models, DEFAULT_DB_ALIAS
from django.conf import settings from django.conf import settings
class Article(models.Model): class Article(models.Model):
@ -35,7 +35,7 @@ __test__ = {'API_TESTS': r"""
>>> a7.save() >>> a7.save()
"""} """}
if settings.DATABASE_ENGINE in ('postgresql', 'postgresql_pysycopg2'): if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] in ('postgresql', 'postgresql_pysycopg2'):
__test__['API_TESTS'] += r""" __test__['API_TESTS'] += r"""
# text matching tests for PostgreSQL 8.3 # text matching tests for PostgreSQL 8.3
>>> Article.objects.filter(id__iexact='1') >>> Article.objects.filter(id__iexact='1')
@ -391,7 +391,7 @@ FieldError: Join on field 'headline' not permitted. Did you misspell 'starts' fo
""" """
if settings.DATABASE_ENGINE != 'mysql': if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] != 'mysql':
__test__['API_TESTS'] += r""" __test__['API_TESTS'] += r"""
# grouping and backreferences # grouping and backreferences
>>> Article.objects.filter(headline__regex=r'b(.).*b\1') >>> Article.objects.filter(headline__regex=r'b(.).*b\1')

View File

@ -7,7 +7,7 @@ commit-on-success behavior. Alternatively, you can manage the transaction
manually. manually.
""" """
from django.db import models from django.db import models, DEFAULT_DB_ALIAS
class Reporter(models.Model): class Reporter(models.Model):
first_name = models.CharField(max_length=30) first_name = models.CharField(max_length=30)
@ -28,7 +28,7 @@ from django.conf import settings
building_docs = getattr(settings, 'BUILDING_DOCS', False) building_docs = getattr(settings, 'BUILDING_DOCS', False)
if building_docs or settings.DATABASE_ENGINE != 'mysql': if building_docs or settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] != 'mysql':
__test__['API_TESTS'] += """ __test__['API_TESTS'] += """
# the default behavior is to autocommit after each save() action # the default behavior is to autocommit after each save() action
>>> def create_a_reporter_then_fail(first, last): >>> def create_a_reporter_then_fail(first, last):

View File

@ -1,7 +1,7 @@
# coding: utf-8 # coding: utf-8
import pickle import pickle
from django.db import connection, models from django.db import connection, models, DEFAULT_DB_ALIAS
from django.conf import settings from django.conf import settings
try: try:
@ -327,7 +327,7 @@ def run_stddev_tests():
Stddev and Variance are not guaranteed to be available for SQLite, and Stddev and Variance are not guaranteed to be available for SQLite, and
are not available for PostgreSQL before 8.2. are not available for PostgreSQL before 8.2.
""" """
if settings.DATABASE_ENGINE == 'sqlite3': if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] == 'sqlite3':
return False return False
class StdDevPop(object): class StdDevPop(object):

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Unit and doctests for specific database backends. # Unit and doctests for specific database backends.
import unittest import unittest
from django.db import connection from django.db import connection, DEFAULT_DB_ALIAS
from django.db.backends.signals import connection_created from django.db.backends.signals import connection_created
from django.conf import settings from django.conf import settings
@ -10,7 +10,7 @@ class Callproc(unittest.TestCase):
def test_dbms_session(self): def test_dbms_session(self):
# If the backend is Oracle, test that we can call a standard # If the backend is Oracle, test that we can call a standard
# stored procedure through our cursor wrapper. # stored procedure through our cursor wrapper.
if settings.DATABASE_ENGINE == 'oracle': if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] == 'oracle':
cursor = connection.cursor() cursor = connection.cursor()
cursor.callproc('DBMS_SESSION.SET_IDENTIFIER', cursor.callproc('DBMS_SESSION.SET_IDENTIFIER',
['_django_testing!',]) ['_django_testing!',])
@ -33,6 +33,21 @@ class LongString(unittest.TestCase):
c.execute('DROP TABLE ltext') c.execute('DROP TABLE ltext')
self.assertEquals(long_str, row[0].read()) self.assertEquals(long_str, row[0].read())
class LongString(unittest.TestCase):
def test_long_string(self):
# If the backend is Oracle, test that we can save a text longer
# than 4000 chars and read it properly
if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] == 'oracle':
c = connection.cursor()
c.execute('CREATE TABLE ltext ("TEXT" NCLOB)')
long_str = ''.join([unicode(x) for x in xrange(4000)])
c.execute('INSERT INTO ltext VALUES (%s)',[long_str])
c.execute('SELECT text FROM ltext')
row = c.fetchone()
c.execute('DROP TABLE ltext')
self.assertEquals(long_str, row[0].read())
def connection_created_test(sender, **kwargs): def connection_created_test(sender, **kwargs):
print 'connection_created signal' print 'connection_created signal'
@ -63,7 +78,7 @@ __test__ = {'API_TESTS': """
# Unfortunately with sqlite3 the in-memory test database cannot be # Unfortunately with sqlite3 the in-memory test database cannot be
# closed, and so it cannot be re-opened during testing, and so we # closed, and so it cannot be re-opened during testing, and so we
# sadly disable this test for now. # sadly disable this test for now.
if settings.DATABASE_ENGINE != 'sqlite3': if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] != 'sqlite3':
__test__['API_TESTS'] += """ __test__['API_TESTS'] += """
>>> connection_created.connect(connection_created_test) >>> connection_created.connect(connection_created_test)
>>> connection.close() # Ensure the connection is closed >>> connection.close() # Ensure the connection is closed

View File

@ -3,7 +3,7 @@ This is a basic model to test saving and loading boolean and date-related
types, which in the past were problematic for some database backends. types, which in the past were problematic for some database backends.
""" """
from django.db import models from django.db import models, DEFAULT_DB_ALIAS
from django.conf import settings from django.conf import settings
class Donut(models.Model): class Donut(models.Model):
@ -93,11 +93,11 @@ u'Outstanding'
# Regression test for #8354: the MySQL backend should raise an error if given # Regression test for #8354: the MySQL backend should raise an error if given
# a timezone-aware datetime object. # a timezone-aware datetime object.
if settings.DATABASE_ENGINE == 'mysql': if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] == 'mysql':
__test__['API_TESTS'] += """ __test__['API_TESTS'] += """
>>> from django.utils import tzinfo >>> from django.utils import tzinfo
>>> dt = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=tzinfo.FixedOffset(0)) >>> dt = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=tzinfo.FixedOffset(0))
>>> d = Donut(name='Bear claw', consumed_at=dt) >>> d = Donut(name='Bear claw', consumed_at=dt)
>>> d.save() >>> d.save()
Traceback (most recent call last): Traceback (most recent call last):
.... ....

View File

@ -1,5 +1,5 @@
from django.conf import settings from django.conf import settings
from django.db import models, backend, connection, transaction from django.db import models, backend, connection, transaction, DEFAULT_DB_ALIAS
from django.db.models import sql, query from django.db.models import sql, query
from django.test import TransactionTestCase from django.test import TransactionTestCase
@ -8,17 +8,18 @@ class Book(models.Model):
# Can't run this test under SQLite, because you can't # Can't run this test under SQLite, because you can't
# get two connections to an in-memory database. # get two connections to an in-memory database.
if settings.DATABASE_ENGINE != 'sqlite3': if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] != 'sqlite3':
class DeleteLockingTest(TransactionTestCase): class DeleteLockingTest(TransactionTestCase):
def setUp(self): def setUp(self):
# Create a second connection to the database # Create a second connection to the database
conn_settings = settings.DATABASES[DEFAULT_DB_ALIAS]
self.conn2 = backend.DatabaseWrapper({ self.conn2 = backend.DatabaseWrapper({
'DATABASE_HOST': settings.DATABASE_HOST, 'DATABASE_HOST': conn_settings['DATABASE_HOST'],
'DATABASE_NAME': settings.DATABASE_NAME, 'DATABASE_NAME': conn_settings['DATABASE_NAME'],
'DATABASE_OPTIONS': settings.DATABASE_OPTIONS, 'DATABASE_OPTIONS': conn_settings['DATABASE_OPTIONS'],
'DATABASE_PASSWORD': settings.DATABASE_PASSWORD, 'DATABASE_PASSWORD': conn_settings['DATABASE_PASSWORD'],
'DATABASE_PORT': settings.DATABASE_PORT, 'DATABASE_PORT': conn_settings['DATABASE_PORT'],
'DATABASE_USER': settings.DATABASE_USER, 'DATABASE_USER': conn_settings['DATABASE_USER'],
'TIME_ZONE': settings.TIME_ZONE, 'TIME_ZONE': settings.TIME_ZONE,
}) })

View File

@ -2,7 +2,7 @@
Spanning tests for all the operations that F() expressions can perform. Spanning tests for all the operations that F() expressions can perform.
""" """
from django.conf import settings from django.conf import settings
from django.db import models from django.db import models, DEFAULT_DB_ALIAS
# #
# Model for testing arithmetic expressions. # Model for testing arithmetic expressions.
@ -121,7 +121,7 @@ Complex expressions of different connection types are possible.
"""} """}
# Oracle doesn't support the Bitwise OR operator. # Oracle doesn't support the Bitwise OR operator.
if settings.DATABASE_ENGINE != 'oracle': if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] != 'oracle':
__test__['API_TESTS'] += """ __test__['API_TESTS'] += """
>>> _ = Number.objects.filter(pk=n.pk).update(integer=42, float=15.5) >>> _ = Number.objects.filter(pk=n.pk).update(integer=42, float=15.5)

View File

@ -1,4 +1,4 @@
from django.db import models from django.db import models, DEFAULT_DB_ALIAS
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.conf import settings from django.conf import settings
import os import os
@ -35,7 +35,8 @@ class Stuff(models.Model):
# Oracle doesn't distinguish between None and the empty string. # Oracle doesn't distinguish between None and the empty string.
# This hack makes the test case pass using Oracle. # This hack makes the test case pass using Oracle.
name = self.name name = self.name
if settings.DATABASE_ENGINE == 'oracle' and name == u'': if (settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] == 'oracle'
and name == u''):
name = None name = None
return unicode(name) + u' is owned by ' + unicode(self.owner) return unicode(name) + u' is owned by ' + unicode(self.owner)

View File

@ -1,5 +1,5 @@
from django.conf import settings from django.conf import settings
from django.db import connection from django.db import connection, DEFAULT_DB_ALIAS
from django.test import TestCase from django.test import TestCase
from django.utils import functional from django.utils import functional
@ -80,7 +80,7 @@ class IntrospectionTests(TestCase):
['IntegerField', 'CharField', 'CharField', 'CharField']) ['IntegerField', 'CharField', 'CharField', 'CharField'])
# Regression test for #9991 - 'real' types in postgres # Regression test for #9991 - 'real' types in postgres
if settings.DATABASE_ENGINE.startswith('postgresql'): if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'].startswith('postgresql'):
def test_postgresql_real_type(self): def test_postgresql_real_type(self):
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute("CREATE TABLE django_ixn_real_test_table (number REAL);") cursor.execute("CREATE TABLE django_ixn_real_test_table (number REAL);")

View File

@ -13,7 +13,7 @@ from cStringIO import StringIO
from django.utils.functional import curry from django.utils.functional import curry
from django.core import serializers from django.core import serializers
from django.db import transaction from django.db import transaction, DEFAULT_DB_ALIAS
from django.core import management from django.core import management
from django.conf import settings from django.conf import settings
@ -260,19 +260,19 @@ The end."""),
(fk_obj, 452, FKDataToField, None), (fk_obj, 452, FKDataToField, None),
(fk_obj, 460, FKDataToO2O, 300), (fk_obj, 460, FKDataToO2O, 300),
(im2m_obj, 470, M2MIntermediateData, None), (im2m_obj, 470, M2MIntermediateData, None),
#testing post- and prereferences and extra fields #testing post- and prereferences and extra fields
(im_obj, 480, Intermediate, {'right': 300, 'left': 470}), (im_obj, 480, Intermediate, {'right': 300, 'left': 470}),
(im_obj, 481, Intermediate, {'right': 300, 'left': 490}), (im_obj, 481, Intermediate, {'right': 300, 'left': 490}),
(im_obj, 482, Intermediate, {'right': 500, 'left': 470}), (im_obj, 482, Intermediate, {'right': 500, 'left': 470}),
(im_obj, 483, Intermediate, {'right': 500, 'left': 490}), (im_obj, 483, Intermediate, {'right': 500, 'left': 490}),
(im_obj, 484, Intermediate, {'right': 300, 'left': 470, 'extra': "extra"}), (im_obj, 484, Intermediate, {'right': 300, 'left': 470, 'extra': "extra"}),
(im_obj, 485, Intermediate, {'right': 300, 'left': 490, 'extra': "extra"}), (im_obj, 485, Intermediate, {'right': 300, 'left': 490, 'extra': "extra"}),
(im_obj, 486, Intermediate, {'right': 500, 'left': 470, 'extra': "extra"}), (im_obj, 486, Intermediate, {'right': 500, 'left': 470, 'extra': "extra"}),
(im_obj, 487, Intermediate, {'right': 500, 'left': 490, 'extra': "extra"}), (im_obj, 487, Intermediate, {'right': 500, 'left': 490, 'extra': "extra"}),
(im2m_obj, 490, M2MIntermediateData, []), (im2m_obj, 490, M2MIntermediateData, []),
(data_obj, 500, Anchor, "Anchor 3"), (data_obj, 500, Anchor, "Anchor 3"),
@ -326,7 +326,7 @@ The end."""),
# Because Oracle treats the empty string as NULL, Oracle is expected to fail # Because Oracle treats the empty string as NULL, Oracle is expected to fail
# when field.empty_strings_allowed is True and the value is None; skip these # when field.empty_strings_allowed is True and the value is None; skip these
# tests. # tests.
if settings.DATABASE_ENGINE == 'oracle': if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] == 'oracle':
test_data = [data for data in test_data test_data = [data for data in test_data
if not (data[0] == data_obj and if not (data[0] == data_obj and
data[2]._meta.get_field('data').empty_strings_allowed and data[2]._meta.get_field('data').empty_strings_allowed and
@ -335,7 +335,7 @@ if settings.DATABASE_ENGINE == 'oracle':
# Regression test for #8651 -- a FK to an object iwth PK of 0 # Regression test for #8651 -- a FK to an object iwth PK of 0
# This won't work on MySQL since it won't let you create an object # This won't work on MySQL since it won't let you create an object
# with a primary key of 0, # with a primary key of 0,
if settings.DATABASE_ENGINE != 'mysql': if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] != 'mysql':
test_data.extend([ test_data.extend([
(data_obj, 0, Anchor, "Anchor 0"), (data_obj, 0, Anchor, "Anchor 0"),
(fk_obj, 465, FKData, 0), (fk_obj, 465, FKData, 0),