mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +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:
parent
8ad4ea7b04
commit
b7b5493fc3
@ -8,7 +8,7 @@ in the application directory, on in one of the directories named in the
|
||||
``FIXTURE_DIRS`` setting.
|
||||
"""
|
||||
|
||||
from django.db import models
|
||||
from django.db import models, DEFAULT_DB_ALIAS
|
||||
from django.conf import settings
|
||||
|
||||
class Category(models.Model):
|
||||
@ -100,7 +100,7 @@ __test__ = {'API_TESTS': """
|
||||
|
||||
# Database flushing does not work on MySQL with the default storage engine
|
||||
# because it requires transaction support.
|
||||
if settings.DATABASE_ENGINE != 'mysql':
|
||||
if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] != 'mysql':
|
||||
__test__['API_TESTS'] += \
|
||||
"""
|
||||
# Reset the database representation of this app. This will delete all data.
|
||||
|
@ -4,7 +4,7 @@
|
||||
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
|
||||
|
||||
class Article(models.Model):
|
||||
@ -35,7 +35,7 @@ __test__ = {'API_TESTS': r"""
|
||||
>>> 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"""
|
||||
# text matching tests for PostgreSQL 8.3
|
||||
>>> 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"""
|
||||
# grouping and backreferences
|
||||
>>> Article.objects.filter(headline__regex=r'b(.).*b\1')
|
||||
|
@ -7,7 +7,7 @@ commit-on-success behavior. Alternatively, you can manage the transaction
|
||||
manually.
|
||||
"""
|
||||
|
||||
from django.db import models
|
||||
from django.db import models, DEFAULT_DB_ALIAS
|
||||
|
||||
class Reporter(models.Model):
|
||||
first_name = models.CharField(max_length=30)
|
||||
@ -28,7 +28,7 @@ from django.conf import settings
|
||||
|
||||
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'] += """
|
||||
# the default behavior is to autocommit after each save() action
|
||||
>>> def create_a_reporter_then_fail(first, last):
|
||||
|
@ -1,7 +1,7 @@
|
||||
# coding: utf-8
|
||||
import pickle
|
||||
|
||||
from django.db import connection, models
|
||||
from django.db import connection, models, DEFAULT_DB_ALIAS
|
||||
from django.conf import settings
|
||||
|
||||
try:
|
||||
@ -327,7 +327,7 @@ def run_stddev_tests():
|
||||
Stddev and Variance are not guaranteed to be available for SQLite, and
|
||||
are not available for PostgreSQL before 8.2.
|
||||
"""
|
||||
if settings.DATABASE_ENGINE == 'sqlite3':
|
||||
if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] == 'sqlite3':
|
||||
return False
|
||||
|
||||
class StdDevPop(object):
|
||||
|
@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Unit and doctests for specific database backends.
|
||||
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.conf import settings
|
||||
|
||||
@ -10,7 +10,7 @@ class Callproc(unittest.TestCase):
|
||||
def test_dbms_session(self):
|
||||
# If the backend is Oracle, test that we can call a standard
|
||||
# stored procedure through our cursor wrapper.
|
||||
if settings.DATABASE_ENGINE == 'oracle':
|
||||
if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] == 'oracle':
|
||||
cursor = connection.cursor()
|
||||
cursor.callproc('DBMS_SESSION.SET_IDENTIFIER',
|
||||
['_django_testing!',])
|
||||
@ -33,6 +33,21 @@ class LongString(unittest.TestCase):
|
||||
c.execute('DROP TABLE ltext')
|
||||
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):
|
||||
print 'connection_created signal'
|
||||
|
||||
@ -63,7 +78,7 @@ __test__ = {'API_TESTS': """
|
||||
# Unfortunately with sqlite3 the in-memory test database cannot be
|
||||
# closed, and so it cannot be re-opened during testing, and so we
|
||||
# sadly disable this test for now.
|
||||
if settings.DATABASE_ENGINE != 'sqlite3':
|
||||
if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] != 'sqlite3':
|
||||
__test__['API_TESTS'] += """
|
||||
>>> connection_created.connect(connection_created_test)
|
||||
>>> connection.close() # Ensure the connection is closed
|
||||
|
@ -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.
|
||||
"""
|
||||
|
||||
from django.db import models
|
||||
from django.db import models, DEFAULT_DB_ALIAS
|
||||
from django.conf import settings
|
||||
|
||||
class Donut(models.Model):
|
||||
@ -93,7 +93,7 @@ u'Outstanding'
|
||||
|
||||
# Regression test for #8354: the MySQL backend should raise an error if given
|
||||
# a timezone-aware datetime object.
|
||||
if settings.DATABASE_ENGINE == 'mysql':
|
||||
if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] == 'mysql':
|
||||
__test__['API_TESTS'] += """
|
||||
>>> from django.utils import tzinfo
|
||||
>>> dt = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=tzinfo.FixedOffset(0))
|
||||
|
@ -1,5 +1,5 @@
|
||||
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.test import TransactionTestCase
|
||||
|
||||
@ -8,17 +8,18 @@ class Book(models.Model):
|
||||
|
||||
# Can't run this test under SQLite, because you can't
|
||||
# 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):
|
||||
def setUp(self):
|
||||
# Create a second connection to the database
|
||||
conn_settings = settings.DATABASES[DEFAULT_DB_ALIAS]
|
||||
self.conn2 = backend.DatabaseWrapper({
|
||||
'DATABASE_HOST': settings.DATABASE_HOST,
|
||||
'DATABASE_NAME': settings.DATABASE_NAME,
|
||||
'DATABASE_OPTIONS': settings.DATABASE_OPTIONS,
|
||||
'DATABASE_PASSWORD': settings.DATABASE_PASSWORD,
|
||||
'DATABASE_PORT': settings.DATABASE_PORT,
|
||||
'DATABASE_USER': settings.DATABASE_USER,
|
||||
'DATABASE_HOST': conn_settings['DATABASE_HOST'],
|
||||
'DATABASE_NAME': conn_settings['DATABASE_NAME'],
|
||||
'DATABASE_OPTIONS': conn_settings['DATABASE_OPTIONS'],
|
||||
'DATABASE_PASSWORD': conn_settings['DATABASE_PASSWORD'],
|
||||
'DATABASE_PORT': conn_settings['DATABASE_PORT'],
|
||||
'DATABASE_USER': conn_settings['DATABASE_USER'],
|
||||
'TIME_ZONE': settings.TIME_ZONE,
|
||||
})
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
Spanning tests for all the operations that F() expressions can perform.
|
||||
"""
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.db import models, DEFAULT_DB_ALIAS
|
||||
|
||||
#
|
||||
# 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.
|
||||
if settings.DATABASE_ENGINE != 'oracle':
|
||||
if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] != 'oracle':
|
||||
__test__['API_TESTS'] += """
|
||||
|
||||
>>> _ = Number.objects.filter(pk=n.pk).update(integer=42, float=15.5)
|
||||
|
@ -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.conf import settings
|
||||
import os
|
||||
@ -35,7 +35,8 @@ class Stuff(models.Model):
|
||||
# Oracle doesn't distinguish between None and the empty string.
|
||||
# This hack makes the test case pass using Oracle.
|
||||
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
|
||||
return unicode(name) + u' is owned by ' + unicode(self.owner)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
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.utils import functional
|
||||
|
||||
@ -80,7 +80,7 @@ class IntrospectionTests(TestCase):
|
||||
['IntegerField', 'CharField', 'CharField', 'CharField'])
|
||||
|
||||
# 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):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("CREATE TABLE django_ixn_real_test_table (number REAL);")
|
||||
|
@ -13,7 +13,7 @@ from cStringIO import StringIO
|
||||
|
||||
from django.utils.functional import curry
|
||||
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.conf import settings
|
||||
|
||||
@ -326,7 +326,7 @@ The end."""),
|
||||
# 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
|
||||
# tests.
|
||||
if settings.DATABASE_ENGINE == 'oracle':
|
||||
if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] == 'oracle':
|
||||
test_data = [data for data in test_data
|
||||
if not (data[0] == data_obj 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
|
||||
# This won't work on MySQL since it won't let you create an object
|
||||
# with a primary key of 0,
|
||||
if settings.DATABASE_ENGINE != 'mysql':
|
||||
if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] != 'mysql':
|
||||
test_data.extend([
|
||||
(data_obj, 0, Anchor, "Anchor 0"),
|
||||
(fk_obj, 465, FKData, 0),
|
||||
|
Loading…
x
Reference in New Issue
Block a user