From 8ad4ea7b042658cd47f362712e2f1f07c506c3b2 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Thu, 6 Aug 2009 00:27:53 +0000 Subject: [PATCH] [soc2009/multidb] Fix a number of tests that were looking at settings.DATABASE_ENGINE, which has been deprecated in favor of the DATABASES interface git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/multidb@11406 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/basic/models.py | 6 +++--- tests/modeltests/custom_pk/models.py | 4 ++-- tests/regressiontests/model_regress/models.py | 5 ++--- tests/regressiontests/queries/models.py | 6 +++--- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/modeltests/basic/models.py b/tests/modeltests/basic/models.py index 2dbde58256..07f5a1c55e 100644 --- a/tests/modeltests/basic/models.py +++ b/tests/modeltests/basic/models.py @@ -16,7 +16,7 @@ try: except NameError: from django.utils.itercompat import sorted -from django.db import models +from django.db import models, DEFAULT_DB_ALIAS class Article(models.Model): headline = models.CharField(max_length=100, default='Default headline') @@ -365,7 +365,7 @@ from django.conf import settings building_docs = getattr(settings, 'BUILDING_DOCS', False) -if building_docs or settings.DATABASE_ENGINE == 'postgresql': +if building_docs or settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] == 'postgresql': __test__['API_TESTS'] += """ # In PostgreSQL, microsecond-level precision is available. >>> a9 = Article(headline='Article 9', pub_date=datetime(2005, 7, 31, 12, 30, 45, 180)) @@ -374,7 +374,7 @@ if building_docs or settings.DATABASE_ENGINE == 'postgresql': datetime.datetime(2005, 7, 31, 12, 30, 45, 180) """ -if building_docs or settings.DATABASE_ENGINE == 'mysql': +if building_docs or settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] == 'mysql': __test__['API_TESTS'] += """ # In MySQL, microsecond-level precision isn't available. You'll lose # microsecond-level precision once the data is saved. diff --git a/tests/modeltests/custom_pk/models.py b/tests/modeltests/custom_pk/models.py index b88af16782..225b6316a2 100644 --- a/tests/modeltests/custom_pk/models.py +++ b/tests/modeltests/custom_pk/models.py @@ -7,7 +7,7 @@ this behavior by explicitly adding ``primary_key=True`` to a field. """ from django.conf import settings -from django.db import models, transaction, IntegrityError +from django.db import models, transaction, IntegrityError, DEFAULT_DB_ALIAS from fields import MyAutoField @@ -156,7 +156,7 @@ True # SQLite lets objects be saved with an empty primary key, even though an # integer is expected. So we can't check for an error being raised in that case # for SQLite. Remove it from the suite for this next bit. -if settings.DATABASE_ENGINE != 'sqlite3': +if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] != 'sqlite3': __test__["API_TESTS"] += """ # The primary key must be specified, so an error is raised if you try to create # an object without it. diff --git a/tests/regressiontests/model_regress/models.py b/tests/regressiontests/model_regress/models.py index 668acd830a..de7579dbe8 100644 --- a/tests/regressiontests/model_regress/models.py +++ b/tests/regressiontests/model_regress/models.py @@ -2,7 +2,7 @@ import datetime from django.conf import settings -from django.db import models +from django.db import models, DEFAULT_DB_ALIAS from django.utils import tzinfo CHOICES = ( @@ -149,7 +149,7 @@ datetime.datetime(2000, 1, 1, 6, 1, 1) """} -if settings.DATABASE_ENGINE not in ("mysql", "oracle"): +if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] not in ("mysql", "oracle"): __test__["timezone-tests"] = """ # Saving an updating with timezone-aware datetime Python objects. Regression # test for #10443. @@ -167,4 +167,3 @@ if settings.DATABASE_ENGINE not in ("mysql", "oracle"): 1 """ - diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py index 0d28926149..b19bb9f51b 100644 --- a/tests/regressiontests/queries/models.py +++ b/tests/regressiontests/queries/models.py @@ -7,7 +7,7 @@ import pickle import sys from django.conf import settings -from django.db import models +from django.db import models, DEFAULT_DB_ALIAS from django.db.models.query import Q, ITER_CHUNK_SIZE # Python 2.3 doesn't have sorted() @@ -1209,13 +1209,13 @@ FieldError: Infinite loop caused by ordering. # In Oracle, we expect a null CharField to return u'' instead of None. -if settings.DATABASE_ENGINE == "oracle": +if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] == "oracle": __test__["API_TESTS"] = __test__["API_TESTS"].replace("", "u''") else: __test__["API_TESTS"] = __test__["API_TESTS"].replace("", "None") -if settings.DATABASE_ENGINE == "mysql": +if settings.DATABASES[DEFAULT_DB_ALIAS]['DATABASE_ENGINE'] == "mysql": __test__["API_TESTS"] += """ When grouping without specifying ordering, we add an explicit "ORDER BY NULL" portion in MySQL to prevent unnecessary sorting.