Skip to content

Instantly share code, notes, and snippets.

@mlavin
Created March 16, 2012 23:52
Show Gist options
  • Save mlavin/2053678 to your computer and use it in GitHub Desktop.
Save mlavin/2053678 to your computer and use it in GitHub Desktop.
Unlogged Table Tests
from django.db.backends.postgresql_psycopg2.base import *
def change_to_unlogged(statement):
"""Replace CREATE TABLE statements to be UNLOGGED."""
return statement.replace('CREATE TABLE', 'CREATE UNLOGGED TABLE')
class DatabaseCreation(DatabaseCreation):
def create_test_db(self, verbosity, autoclobber):
"""Patch sql_create_model, create DB and install unaccent extension."""
original_create = self.sql_create_model
try:
self.sql_create_model = self.sql_create_test_model
test_db_name = super(DatabaseCreation, self).create_test_db(verbosity, autoclobber)
finally:
self.sql_create_model = original_create
return test_db_name
def sql_create_test_model(self, model, style, known_models=set()):
"""Changes table create to use unlogged tables."""
style.SQL_KEYWORD = change_to_unlogged
return super(DatabaseCreation, self).sql_create_model(model, style, known_models)
sqlite3
Ran 4689 tests in 475.464s
OK (skipped=112, expected failures=2)
# This is an example test settings file for use with the Django test suite.
#
# The 'sqlite3' backend requires only the ENGINE setting (an in-
# memory database will be used). All other backends will require a
# NAME and potentially authentication information. See the
# following section in the docs for more information:
#
# https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/
#
# The different databases that Django supports behave differently in certain
# situations, so it is recommended to run the test suite against as many
# database backends as possible. You may want to create a separate settings
# file for each of the backends you test against.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django-default',
},
'other': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django-other',
}
}
SECRET_KEY = "django_tests_secret_key"
# This is an example test settings file for use with the Django test suite.
#
# The 'sqlite3' backend requires only the ENGINE setting (an in-
# memory database will be used). All other backends will require a
# NAME and potentially authentication information. See the
# following section in the docs for more information:
#
# https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/
#
# The different databases that Django supports behave differently in certain
# situations, so it is recommended to run the test suite against as many
# database backends as possible. You may want to create a separate settings
# file for each of the backends you test against.
DATABASES = {
'default': {
'ENGINE': 'pg_unlogged',
'NAME': 'django-default',
},
'other': {
'ENGINE': 'pg_unlogged',
'NAME': 'django-other',
}
}
SECRET_KEY = "django_tests_secret_key"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment