Changeset 5380
- Timestamp:
- 05/29/07 07:42:08 (1 year ago)
- Files:
-
- django/trunk/django/conf/global_settings.py (modified) (1 diff)
- django/trunk/django/test/utils.py (modified) (4 diffs)
- django/trunk/docs/settings.txt (modified) (2 diffs)
- django/trunk/docs/testing.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/conf/global_settings.py
r5379 r5380 333 333 TEST_DATABASE_NAME = None 334 334 335 # Strings used to set the character set and collation order for the test 336 # database. These values are passed literally to the server, so they are 337 # backend-dependent. If None, no special settings are sent (system defaults are 338 # used). 339 TEST_DATABASE_CHARSET = None 340 TEST_DATABASE_COLLATION = None 341 335 342 ############ 336 343 # FIXTURES # django/trunk/django/test/utils.py
r5173 r5380 74 74 connection.connection.set_isolation_level(0) 75 75 76 def get_mysql_create_suffix(): 77 suffix = [] 78 if settings.TEST_DATABASE_CHARSET: 79 suffix.append('CHARACTER SET %s' % settings.TEST_DATABASE_CHARSET) 80 if settings.TEST_DATABASE_COLLATION: 81 suffix.append('COLLATE %s' % settings.TEST_DATABASE_COLLATION) 82 return ' '.join(suffix) 83 84 def get_postgresql_create_suffix(): 85 assert settings.TEST_DATABASE_COLLATION is None, "PostgreSQL does not support collation setting at database creation time." 86 if settings.TEST_DATABASE_CHARSET: 87 return "WITH ENCODING '%s'" % settings.TEST_DATABASE_CHARSET 88 return '' 89 76 90 def create_test_db(verbosity=1, autoclobber=False): 77 91 if verbosity >= 1: … … 82 96 TEST_DATABASE_NAME = ":memory:" 83 97 else: 98 suffix = { 99 'postgresql': get_postgresql_create_suffix, 100 'postgresql_psycopg2': get_postgresql_create_suffix, 101 'mysql': get_mysql_create_suffix, 102 'mysql_old': get_mysql_create_suffix, 103 }.get(settings.DATABASE_ENGINE, lambda: '')() 84 104 if settings.TEST_DATABASE_NAME: 85 105 TEST_DATABASE_NAME = settings.TEST_DATABASE_NAME … … 93 113 _set_autocommit(connection) 94 114 try: 95 cursor.execute("CREATE DATABASE %s " % backend.quote_name(TEST_DATABASE_NAME))115 cursor.execute("CREATE DATABASE %s %s" % (backend.quote_name(TEST_DATABASE_NAME), suffix)) 96 116 except Exception, e: 97 117 sys.stderr.write("Got an error creating the test database: %s\n" % e) … … 105 125 if verbosity >= 1: 106 126 print "Creating test database..." 107 cursor.execute("CREATE DATABASE %s " % backend.quote_name(TEST_DATABASE_NAME))127 cursor.execute("CREATE DATABASE %s %s" % (backend.quote_name(TEST_DATABASE_NAME), suffix)) 108 128 except Exception, e: 109 129 sys.stderr.write("Got an error recreating the test database: %s\n" % e) django/trunk/docs/settings.txt
r5379 r5380 827 827 .. _How invalid variables are handled: ../templates_python/#how-invalid-variables-are-handled 828 828 829 TEST_DATABASE_CHARSET 830 --------------------- 831 832 **New in Django development version** 833 834 Default: ``None`` 835 836 The character set encoding used to create the test database. The value of this 837 string is passed directly through to the database, so its format is 838 backend-specific. 839 840 Supported for the PostgreSQL_ (``postgresql``, ``postgresql_psycopg2``) and MySQL_ (``mysql``, ``mysql_old``) backends. 841 842 .. _PostgreSQL: http://www.postgresql.org/docs/8.2/static/multibyte.html 843 .. _MySQL: http://www.mysql.org/doc/refman/5.0/en/charset-database.html 844 845 TEST_DATABASE_COLLATION 846 ------------------------ 847 848 **New in Django development version** 849 850 Default: ``None`` 851 852 The collation order to use when creating the test database. This value is 853 passed directly to the backend, so it's format is backend-specific. 854 855 Only supported for ``mysql`` and ``mysql_old`` backends (see `section 10.3.2`_ 856 of the MySQL manual for details). 857 858 .. _section 10.3.2: http://www.mysql.org/doc/refman/5.0/en/charset-database.html 859 860 TEST_DATABASE_NAME 861 ------------------ 862 863 Default: ``None`` 864 865 The name of database to use when running the test suite. If a value of 866 ``None`` is specified, the test database will use the name ``'test_' + settings.DATABASE_NAME``. See `Testing Django Applications`_. 867 868 .. _Testing Django Applications: ../testing/ 869 829 870 TEST_RUNNER 830 871 ----------- … … 832 873 Default: ``'django.test.simple.run_tests'`` 833 874 834 The name of the method to use for starting the test suite. See 875 The name of the method to use for starting the test suite. See 835 876 `Testing Django Applications`_. 836 837 .. _Testing Django Applications: ../testing/838 839 TEST_DATABASE_NAME840 ------------------841 842 Default: ``None``843 844 The name of database to use when running the test suite. If a value of845 ``None`` is specified, the test database will use the name ``'test_' + settings.DATABASE_NAME``. See `Testing Django Applications`_.846 877 847 878 .. _Testing Django Applications: ../testing/ django/trunk/docs/testing.txt
r5367 r5380 571 571 If you wish to use a name other than the default for the test database, 572 572 you can use the ``TEST_DATABASE_NAME`` setting to provide a name. 573 574 575 **New in Django development version:** If you wish to have fine-grained 576 control over the character set encoding used in your database, you can control 577 this with the ``TEST_DATABASE_CHARSET`` setting. For MySQL users, you can also 578 control the particular collation used by the test database with the 579 ``TEST_DATABASE_COLLATION`` setting. Refer to the settings_ documentation for 580 details of these advanced settings. 581 582 .. _settings: ../settings.txt 573 583 574 584 The test database is created by the user in the ``DATABASE_USER`` setting.
