How should it make django test create a default_test database that is using 5 shemas ?

57 views
Skip to first unread message

JAMES DAMILD ETIENNE

unread,
Jan 29, 2016, 6:31:17 PM1/29/16
to Django users
I have a possgres database with 5 shemas , it connects very well to it , but when truing to do unit test on my models or view , the default table created in sqllite3 is saysing  that on of my table is not there :

 return Database.Cursor.execute(self, query, params)
OperationalError: no such table: jamestable

any help please  ?
thank you




aspe...@gmail.com

unread,
Jan 30, 2016, 12:03:18 PM1/30/16
to Django users

show us your settings.py file.
http://dpaste.de

JAMES DAMILD ETIENNE

unread,
Feb 1, 2016, 9:34:53 AM2/1/16
to Django users

here is my settings :

"""
Django settings for james project.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)

DATA_DIR = '/var/lib/james'
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '33333333333333333333333333'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []

import os
import sys
import ConfigParser

c = ConfigParser.ConfigParser()
c.optionxform = str
CONFIG_PATH = '/etc/james/james.cfg'
if not os.path.exists(CONFIG_PATH):
    print 'Config file not found in:', CONFIG_PATH
    CONFIG_PATH = os.path.expanduser('~/.james3.cfg')
    if not os.path.exists(CONFIG_PATH):
        raise Exception('Missing james.cfg file! Not found in /etc/james/james.cfg or ~/.james.cfg.')

print 'Using config:', CONFIG_PATH
c.read(CONFIG_PATH)


BASE_DIR = os.path.dirname(os.path.dirname(__file__))

# Application definition

INSTALLED_APPS = [
    'grappelli',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.sites',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # 'registration',
    'genesis',
    'reversion',
    'django_jinja',
    'status',
    'configuration',
    'administration',
    'old_link',
    'chartjs',
    ]

MIDDLEWARE_CLASSES = [
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'james.util.requestprovider.RequestProvider',
    # TODO: test performance of this middleware
    'reversion.middleware.RevisionMiddleware',
    'james.middleware.CurrentContext'
]

ROOT_URLCONF = 'james.urls'

WSGI_APPLICATION = 'james.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': c.get('default-database', 'ENGINE'),
        'NAME': c.get('default-database', 'NAME'),
        'USER': c.get('default-database', 'USER'),
        'PASSWORD': c.get('default-database', 'PASSWORD'),
        'HOST': c.get('default-database', 'HOST'),
        'PORT': c.get('default-database', 'PORT'),
        'OPTIONS': {
            'options': '-c search_path=store,site,portal'
        },
        }
}

# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
# TIME_ZONE = 'UTC'
TIME_ZONE = 'America/New_York'
USE_I18N = True
USE_L10N = True
USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static_gen")
STATICFILES_DIRS = (
    '/srv/www/james/static/',
    os.path.join(BASE_DIR, "static"),
)

LOGIN_REDIRECT_URL = "/"

TEMPLATES = [
    {
        "BACKEND": "django_jinja.backend.Jinja2",
        "APP_DIRS": True,
        "OPTIONS": {
            "match_extension": ".j2",
            "newstyle_gettext": True,
            "filters": {
                "timestamp2date": "james.filters.timestamp2date",
                "format_datetime": "james.filters.format_datetime",
                },

            "context_processors": [
                "django.contrib.auth.context_processors.auth",
                "django.template.context_processors.debug",
                "django.template.context_processors.i18n",
                "django.template.context_processors.media",
                "django.template.context_processors.static",
                "django.template.context_processors.tz",
                "django.contrib.messages.context_processors.messages",
                'james.context_processors.customers',
                ],

            "extensions": [
                "jinja2.ext.do",
                "jinja2.ext.loopcontrols",
                "jinja2.ext.with_",
                "jinja2.ext.i18n",
                "jinja2.ext.autoescape",
                "django_jinja.builtins.extensions.CsrfExtension",
                "django_jinja.builtins.extensions.CacheExtension",
                "django_jinja.builtins.extensions.TimezoneExtension",
                "django_jinja.builtins.extensions.UrlsExtension",
                "django_jinja.builtins.extensions.StaticFilesExtension",
                "django_jinja.builtins.extensions.DjangoFiltersExtension",
                ],
            "autoescape": True,
            "auto_reload": DEBUG,
            "translation_engine": "django.utils.translation",
            },
        'DIRS': [
            '/srv/www/james/templates/',
            os.path.join(BASE_DIR, "templates"),
            ],
        },
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [],
        "APP_DIRS": True,

        "OPTIONS": {

            "context_processors": [
                "django.contrib.auth.context_processors.auth",
                "django.template.context_processors.debug",
                "django.template.context_processors.i18n",
                "django.template.context_processors.media",
                "django.template.context_processors.static",
                "django.template.context_processors.tz",
                "django.contrib.messages.context_processors.messages",
                ],
            },
        },
    ]


EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = c.get('mail', 'smtp_host')
EMAIL_PORT = 25
EMAIL_USE_TLS = False
EMAIL_USE_SSL = False

SUPPORT_EMAIL = ""
DEFAULT_FROM_EMAIL = ""


LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'standard': {
            'format': "[%(asctime)s] %(levelname)s [%(module)s.%(funcName)s:%(lineno)s] %(process)d %(thread)d %(message)s",
            'datefmt': "%d/%b/%Y %H:%M:%S"
        },
        'exception': {
            'format': "[%(asctime)s] %(levelname)s [%(filename)s:%(funcName)s:%(lineno)s] %(process)d %(thread)d %(message)s",
            'datefmt': "%d/%b/%Y %H:%M:%S"
        },
        },
    'handlers': {
        'stderr': {
            'level': c.get('logging', 'log_level'),
            'class': 'logging.StreamHandler',
            'formatter': 'standard'
        },
        # 'file': {
        #     'level': 'DEBUG',
        #     'class': 'logging.FileHandler',
        #     'filename': '/path/to/django/debug.log',
        # },
    },
    'loggers': {
        'django': {
            'handlers': ['stderr'],
            'propagate': True,
            'level': 'WARNING',
            },
        'james': {
            'handlers': ['stderr'],
            'propagate': True,
            'level': 'DEBUG',
            },
        },
    }

## Later..
# CACHES = {
#     'default': {
#         'BACKEND': 'redis_cache.RedisCache',
#         'LOCATION': ['localhost:6379'],
#         'OPTIONS': {
#             'PARSER_CLASS': 'redis.connection.HiredisParser',
#             'CONNECTION_POOL_CLASS': 'redis.BlockingConnectionPool',
#             'CONNECTION_POOL_CLASS_KWARGS': {
#                 'max_connections': 50,
#                 'timeout': 20,
#             },
#             'MAX_CONNECTIONS': 1000,
#             'PICKLE_VERSION': -1,
#         },
#     },
# }

SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies'

GRAPPELLI_ADMIN_TITLE = 'james / [advanced admin interface]'
GRAPPELLI_CLEAN_INPUT_TYPES = True

# APIs
API_URL_SITES = c.get('api', 'API_URL_SITES')
API_URL_CAPTIVE_PORTAL = c.get('api', 'API_URL_CAPTIVE_PORTAL')
ALLOWED_UPLOAD_EXTENSIONS = ("zip",)
UPLOAD_FOLDER = "/tmp/"

AUTHENTICATION_BACKENDS = (
    'james.auth.EmailAuthBackend',
    'administration.auth.LdapAuthBackend',
)



if 'test' in sys.argv:
        DATABASES['default'] = {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': c.get('default-database', 'NAME'),
            'HOST' : c.get('default-database', 'HOST'),
            'TEST_NAME':'',
            'PORT' : c.get('default-database', 'PORT'),
            'USER' : c.get('default-database', 'USER'),
            'PASSWORD':c.get('default-database', 'PASSWORD'),
            'options': '-c search_path=james,site,portal,public,dvdns'

        }



DATABASE_ROUTERS = []
MIGRATION_MODULES = {
        'ldapauth':'ldapauth.migrations_not_used_in_tests',
        'provisioning':'provisioning.migrations_not_used_in_tests',
        'services':'services.migrations_not_used_in_tests'
    }



SITE_ID = 1
ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window; you may, of course, use a different value.
REGISTRATION_AUTO_LOGIN = True # Automatically log the user in.

JAMES DAMILD ETIENNE

unread,
Feb 1, 2016, 9:38:25 AM2/1/16
to Django users
here is the link
Message has been deleted

JAMES DAMILD ETIENNE

unread,
Feb 4, 2016, 10:27:18 AM2/4/16
to Django users


any help please  ?
thank you

Michal Petrucha

unread,
Feb 4, 2016, 11:18:40 AM2/4/16
to django...@googlegroups.com
In general, it's not a good idea to run tests against a different
database system than the one you're using in production. If your live
application runs with Postgres, then use Postgres for your tests, too.
Just create a new test database, and point the test runner to that.

If you use a different SQL implementation for your tests, sooner or
later, your application will fail in production even though the same
feature will work just fine in your tests. Every SQL implementation is
different, sometimes in obvious ways, sometimes in subtle ones. Do
yourself a favor and learn from the legions of people who learned this
lesson the hard way.

As far as I know, SQLite does not have any support for multiple
schemas in a single database. Therefore I cannot imagine how your code
could ever work against SQLite, if the code expects a schema to be
there.

Good luck,

Michal
signature.asc

JAMES DAMILD ETIENNE

unread,
Feb 4, 2016, 11:28:00 AM2/4/16
to Django users
Ok thanks , make sense , 'ill try to do that thank you




Reply all
Reply to author
Forward
0 new messages