Django

Code

Changeset 3263

Show
Ignore:
Timestamp:
07/03/06 15:47:33 (2 years ago)
Author:
jpellerin
Message:

[multi-db] Added TEST_DATABASES tuple to runtests.py. Now, databases in TEST_DATABASES will be created (if they don't exist or if the user accepts) at the start of the test run and dropped at the end. Those databases will be assigned to settings.DATABASES, with settings other than the database name inherited either from the DATABASES property in the active settings file (if it is present and contains a matching key) or from the default database settings.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/multiple-db-support/tests/runtests.py

    r3241 r3263  
    1212REGRESSION_TESTS_DIR_NAME = 'regressiontests' 
    1313TEST_DATABASE_NAME = 'django_test_db' 
     14TEST_DATABASES = (TEST_DATABASE_NAME + '_a', TEST_DATABASE_NAME + '_b') 
    1415 
    1516error_list = [] 
     
    165166        self.old_databases = settings.DATABASES 
    166167 
    167         db_a = TEST_DATABASE_NAME + '_a' 
    168         db_b = TEST_DATABASE_NAME + '_b' 
    169168        if settings.DATABASE_ENGINE == 'sqlite3': 
    170169            # If we're using SQLite, it's more convenient to test against an 
     
    172171            # after that we have to use temp files.  
    173172            TEST_DATABASE_NAME = ':memory:' 
    174             db_a_name = self._tempfile() 
    175             db_b_name = self._tempfile() 
    176             self.cleanup_files.append(db_a_name) 
    177             self.cleanup_files.append(db_b_name)            
    178         else: 
    179             db_a_name = db_a 
    180             db_b_name = db_b 
    181              
    182         settings.DATABASES = { 
    183             db_a: { 'DATABASE_NAME': db_a_name }, 
    184             db_b: { 'DATABASE_NAME': db_b_name } 
    185             } 
     173         
     174        new_databases = {} 
     175        for db_name in TEST_DATABASES: 
     176            db_st = settings.DATABASES.setdefault(db_name, {}) 
     177            engine = db_st.get('DATABASE_ENGINE', settings.DATABASE_ENGINE) 
     178            if engine == 'sqlite3': 
     179                db_st['DATABASE_NAME'] = self._tempfile() 
     180                self.cleanup_files.append(db_st['DATABASE_NAME']) 
     181            else: 
     182                db_st['DATABASE_NAME'] = db_name 
     183            new_databases[db_name] = db_st 
     184        settings.DATABASES = new_databases 
    186185 
    187186        self.create_test_db(TEST_DATABASE_NAME, connection)