diff --git a/tests/modeltests/fixtures/models.py b/tests/modeltests/fixtures/models.py index 75ff99867a..661a81e5ab 100644 --- a/tests/modeltests/fixtures/models.py +++ b/tests/modeltests/fixtures/models.py @@ -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. diff --git a/tests/modeltests/lookup/models.py b/tests/modeltests/lookup/models.py index 11e2b079f0..cdd1acc8ca 100644 --- a/tests/modeltests/lookup/models.py +++ b/tests/modeltests/lookup/models.py @@ -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') diff --git a/tests/modeltests/transactions/models.py b/tests/modeltests/transactions/models.py index 6763144ca5..df63667d02 100644 --- a/tests/modeltests/transactions/models.py +++ b/tests/modeltests/transactions/models.py @@ -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): diff --git a/tests/regressiontests/aggregation_regress/models.py b/tests/regressiontests/aggregation_regress/models.py index 4476b86d64..d561106546 100644 --- a/tests/regressiontests/aggregation_regress/models.py +++ b/tests/regressiontests/aggregation_regress/models.py @@ -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): diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py index aff27369ad..b12239f0c2 100644 --- a/tests/regressiontests/backends/tests.py +++ b/tests/regressiontests/backends/tests.py @@ -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 diff --git a/tests/regressiontests/datatypes/models.py b/tests/regressiontests/datatypes/models.py index 0ad809a45d..633253dd3b 100644 --- a/tests/regressiontests/datatypes/models.py +++ b/tests/regressiontests/datatypes/models.py @@ -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,11 +93,11 @@ 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)) ->>> d = Donut(name='Bear claw', consumed_at=dt) +>>> from django.utils import tzinfo +>>> dt = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=tzinfo.FixedOffset(0)) +>>> d = Donut(name='Bear claw', consumed_at=dt) >>> d.save() Traceback (most recent call last): .... diff --git a/tests/regressiontests/delete_regress/models.py b/tests/regressiontests/delete_regress/models.py index 93cadc58fa..ffb06b6c8a 100644 --- a/tests/regressiontests/delete_regress/models.py +++ b/tests/regressiontests/delete_regress/models.py @@ -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, }) diff --git a/tests/regressiontests/expressions_regress/models.py b/tests/regressiontests/expressions_regress/models.py index 7c9ca61ccc..fe25ee9922 100644 --- a/tests/regressiontests/expressions_regress/models.py +++ b/tests/regressiontests/expressions_regress/models.py @@ -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) diff --git a/tests/regressiontests/fixtures_regress/models.py b/tests/regressiontests/fixtures_regress/models.py index e33471646c..09f12897d6 100644 --- a/tests/regressiontests/fixtures_regress/models.py +++ b/tests/regressiontests/fixtures_regress/models.py @@ -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) diff --git a/tests/regressiontests/introspection/tests.py b/tests/regressiontests/introspection/tests.py index 7072dc8e9e..b7cd2404da 100644 --- a/tests/regressiontests/introspection/tests.py +++ b/tests/regressiontests/introspection/tests.py @@ -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);") diff --git a/tests/regressiontests/serializers_regress/tests.py b/tests/regressiontests/serializers_regress/tests.py index de7ddcc9f7..94d082e56d 100644 --- a/tests/regressiontests/serializers_regress/tests.py +++ b/tests/regressiontests/serializers_regress/tests.py @@ -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 @@ -260,19 +260,19 @@ The end."""), (fk_obj, 452, FKDataToField, None), (fk_obj, 460, FKDataToO2O, 300), - + (im2m_obj, 470, M2MIntermediateData, None), - + #testing post- and prereferences and extra fields (im_obj, 480, Intermediate, {'right': 300, 'left': 470}), - (im_obj, 481, Intermediate, {'right': 300, 'left': 490}), - (im_obj, 482, Intermediate, {'right': 500, 'left': 470}), - (im_obj, 483, Intermediate, {'right': 500, 'left': 490}), - (im_obj, 484, Intermediate, {'right': 300, 'left': 470, 'extra': "extra"}), - (im_obj, 485, Intermediate, {'right': 300, 'left': 490, 'extra': "extra"}), - (im_obj, 486, Intermediate, {'right': 500, 'left': 470, 'extra': "extra"}), - (im_obj, 487, Intermediate, {'right': 500, 'left': 490, 'extra': "extra"}), - + (im_obj, 481, Intermediate, {'right': 300, 'left': 490}), + (im_obj, 482, Intermediate, {'right': 500, 'left': 470}), + (im_obj, 483, Intermediate, {'right': 500, 'left': 490}), + (im_obj, 484, Intermediate, {'right': 300, 'left': 470, 'extra': "extra"}), + (im_obj, 485, Intermediate, {'right': 300, 'left': 490, 'extra': "extra"}), + (im_obj, 486, Intermediate, {'right': 500, 'left': 470, 'extra': "extra"}), + (im_obj, 487, Intermediate, {'right': 500, 'left': 490, 'extra': "extra"}), + (im2m_obj, 490, M2MIntermediateData, []), (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 # 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),