diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-05-29 13:09:48 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-05-29 13:09:48 +0000 |
| commit | ddae2ecfe42a4135850a435e1eefc79dfecaa062 (patch) | |
| tree | d6d1e432938cf2fa3594264a7ca287c465e5b201 /django/test/utils.py | |
| parent | fa1a0532d35ee5ff342c19821ad290ad48771aa4 (diff) | |
unicode: Merged from trunk up to [5380].
git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5381 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/test/utils.py')
| -rw-r--r-- | django/test/utils.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/django/test/utils.py b/django/test/utils.py index b18b178820..b0f4a8e53d 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -73,6 +73,20 @@ def _set_autocommit(connection): elif hasattr(connection.connection, "set_isolation_level"): connection.connection.set_isolation_level(0) +def get_mysql_create_suffix(): + suffix = [] + if settings.TEST_DATABASE_CHARSET: + suffix.append('CHARACTER SET %s' % settings.TEST_DATABASE_CHARSET) + if settings.TEST_DATABASE_COLLATION: + suffix.append('COLLATE %s' % settings.TEST_DATABASE_COLLATION) + return ' '.join(suffix) + +def get_postgresql_create_suffix(): + assert settings.TEST_DATABASE_COLLATION is None, "PostgreSQL does not support collation setting at database creation time." + if settings.TEST_DATABASE_CHARSET: + return "WITH ENCODING '%s'" % settings.TEST_DATABASE_CHARSET + return '' + def create_test_db(verbosity=1, autoclobber=False): if verbosity >= 1: print "Creating test database..." @@ -81,6 +95,12 @@ def create_test_db(verbosity=1, autoclobber=False): if settings.DATABASE_ENGINE == "sqlite3": TEST_DATABASE_NAME = ":memory:" else: + suffix = { + 'postgresql': get_postgresql_create_suffix, + 'postgresql_psycopg2': get_postgresql_create_suffix, + 'mysql': get_mysql_create_suffix, + 'mysql_old': get_mysql_create_suffix, + }.get(settings.DATABASE_ENGINE, lambda: '')() if settings.TEST_DATABASE_NAME: TEST_DATABASE_NAME = settings.TEST_DATABASE_NAME else: @@ -92,7 +112,7 @@ def create_test_db(verbosity=1, autoclobber=False): cursor = connection.cursor() _set_autocommit(connection) try: - cursor.execute("CREATE DATABASE %s" % backend.quote_name(TEST_DATABASE_NAME)) + cursor.execute("CREATE DATABASE %s %s" % (backend.quote_name(TEST_DATABASE_NAME), suffix)) except Exception, e: sys.stderr.write("Got an error creating the test database: %s\n" % e) if not autoclobber: @@ -104,7 +124,7 @@ def create_test_db(verbosity=1, autoclobber=False): cursor.execute("DROP DATABASE %s" % backend.quote_name(TEST_DATABASE_NAME)) if verbosity >= 1: print "Creating test database..." - cursor.execute("CREATE DATABASE %s" % backend.quote_name(TEST_DATABASE_NAME)) + cursor.execute("CREATE DATABASE %s %s" % (backend.quote_name(TEST_DATABASE_NAME), suffix)) except Exception, e: sys.stderr.write("Got an error recreating the test database: %s\n" % e) sys.exit(2) |
