Ticket #14415: 14415.1.diff

File 14415.1.diff, 2.7 KB (added by Ramiro Morales, 14 years ago)
  • django/db/backends/creation.py

    diff -r 41150ab49bb8 django/db/backends/creation.py
    a b  
    1919
    2020    def __init__(self, connection):
    2121        self.connection = connection
     22        self.test_database_name = None
    2223
    2324    def _digest(self, *args):
    2425        """
     
    343344        if verbosity >= 1:
    344345            print "Creating test database '%s'..." % self.connection.alias
    345346
    346         test_database_name = self._create_test_db(verbosity, autoclobber)
     347        self.test_database_name = self._create_test_db(verbosity, autoclobber)
    347348
    348349        self.connection.close()
    349         self.connection.settings_dict["NAME"] = test_database_name
     350        self.connection.settings_dict['NAME'] = self.test_database_name
    350351
    351352        # Confirm the feature set of the test database
    352353        self.connection.features.confirm()
     
    367368        # the side effect of initializing the test database.
    368369        cursor = self.connection.cursor()
    369370
    370         return test_database_name
     371        return self.test_database_name
    371372
    372373    def _create_test_db(self, verbosity, autoclobber):
    373374        "Internal implementation - creates the test db tables."
     
    414415        if verbosity >= 1:
    415416            print "Destroying test database '%s'..." % self.connection.alias
    416417        self.connection.close()
    417         test_database_name = self.connection.settings_dict['NAME']
     418        test_database_name = self.test_database_name
    418419        self.connection.settings_dict['NAME'] = old_database_name
    419420
    420421        self._destroy_test_db(test_database_name, verbosity)
     
    428429        cursor = self.connection.cursor()
    429430        self.set_autocommit()
    430431        time.sleep(1) # To avoid "database is being accessed by other users" errors.
    431         cursor.execute("DROP DATABASE %s" % self.connection.ops.quote_name(test_database_name))
     432        cursor.execute("DROP DATABASE IF EXISTS %s" % self.connection.ops.quote_name(test_database_name))
    432433        self.connection.close()
    433434
    434435    def set_autocommit(self):
  • django/db/backends/sqlite3/creation.py

    diff -r 41150ab49bb8 django/db/backends/sqlite3/creation.py
    a b  
    6161        return test_database_name
    6262
    6363    def _destroy_test_db(self, test_database_name, verbosity):
    64         if test_database_name and test_database_name != ":memory:":
     64        if test_database_name and test_database_name != ":memory:" and os.access(test_database_name, os.F_OK):
    6565            # Remove the SQLite database file
    6666            os.remove(test_database_name)
Back to Top