Ask Your Question
1

Running Askbot test suites

asked 2011-12-20 08:14:57 -0500

Jacob Oscarson gravatar image Jacob Oscarson
11 2 1 3

updated 2011-12-20 09:42:42 -0500

Hello,

I'm preparing some customizations that might go a bit deeper than skin customization. Therefore I'm investigating the tests found in askbot/tests. However, I don't find any obvious way to run them (I see there's a tox specification file in there, though). Are there descriptions somewhere on how to run them?

And if I get them running, how much of the test suites are expected to pass?

Edit: here's my settings.py:

## Django settings for ASKBOT enabled project.
import os.path
import logging
import sys
import askbot

#this line is added so that we can import pre-packaged askbot dependencies
sys.path.append(os.path.join(os.path.dirname(askbot.__file__), 'deps'))

DEBUG = False#set to True to enable debugging
TEMPLATE_DEBUG = False#keep false when debugging jinja2 templates
INTERNAL_IPS = ('127.0.0.1',)

ADMINS = (
    ('Your Name', 'your_email@domain.com'),
)

MANAGERS = ADMINS

DATABASE_ENGINE = 'django.db.backends.sqlite3' # only postgres (>8.3) and mysql are supported so far others have not been tested yet
DATABASE_NAME = ':memory:'             # Or path to database file if using sqlite3.
DATABASE_USER = ''             # Not used with sqlite3.
DATABASE_PASSWORD = ''         # Not used with sqlite3.
DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.

#outgoing mail server settings
SERVER_EMAIL = ''
DEFAULT_FROM_EMAIL = ''
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_SUBJECT_PREFIX = ''
EMAIL_HOST=''
EMAIL_PORT=''
EMAIL_USE_TLS=False
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

#incoming mail settings
#after filling out these settings - please
#go to the site's live settings and enable the feature
#"Email settings" -> "allow asking by email"
#
#   WARNING: command post_emailed_questions DELETES all
#            emails from the mailbox each time
#            do not use your personal mail box here!!!
#
IMAP_HOST = ''
IMAP_HOST_USER = ''
IMAP_HOST_PASSWORD = ''
IMAP_PORT = ''
IMAP_USE_TLS = False

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
LANGUAGE_CODE = 'en'

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
ASKBOT_FILE_UPLOAD_DIR = os.path.join(os.path.dirname(__file__), 'askbot', 'upfiles')

PROJECT_ROOT = os.path.dirname(__file__)

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/admin/media/'

# Make up some unique string, and don't share it with anybody.
SECRET_KEY = 'sdljdfjkldsflsdjkhsjkldgjlsdgfs s '

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.load_template_source',
    'django.template.loaders.app_directories.load_template_source',
    #below is askbot stuff for this tuple
    'askbot.skins.loaders.filesystem_load_template_source',
    #'django.template.loaders.eggs.load_template_source',
)


MIDDLEWARE_CLASSES = (
    #'django.middleware.gzip.GZipMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    #'django.middleware.cache.UpdateCacheMiddleware',
    'django.middleware.common.CommonMiddleware',
    #'django.middleware.cache.FetchFromCacheMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    #'django.middleware.sqlprint.SqlPrintingMiddleware',

    #below is askbot stuff for this tuple
    'askbot.middleware.anon_user.ConnectToSessionMessagesMiddleware',
    'askbot.middleware.forum_mode.ForumModeMiddleware',
    'askbot.middleware.pagesize.QuestionsPageSizeMiddleware',
    'askbot.middleware.cancel.CancelActionMiddleware',
    'django.middleware.transaction.TransactionMiddleware',
    #'debug_toolbar.middleware.DebugToolbarMiddleware',
    'askbot.middleware.view_log.ViewLogMiddleware',
    'askbot.middleware.spaceless.SpacelessMiddleware',
)


ROOT_URLCONF = os.path.basename(os.path.dirname(__file__)) + '.urls'


#UPLOAD SETTINGS
FILE_UPLOAD_TEMP_DIR = os.path.join(
                                os.path.dirname(__file__),
                                'tmp'
                            ).replace('\\','/')

FILE_UPLOAD_HANDLERS = (
    'django.core.files.uploadhandler.MemoryFileUploadHandler',
    'django.core.files.uploadhandler.TemporaryFileUploadHandler',
)
ASKBOT_ALLOWED_UPLOAD_FILE_TYPES = ('.jpg', '.jpeg', '.gif', '.bmp', '.png', '.tiff')
ASKBOT_MAX_UPLOAD_FILE_SIZE = 1024 * 1024 #result in bytes
DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'


#TEMPLATE_DIRS = (,) #template have no effect in askbot, use the variable below
#ASKBOT_EXTRA_SKIN_DIR = #path to your private skin collection
#take a look here http://askbot.org/en/question/207/

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.request',
    'askbot.context.application_settings',
    #'django.core.context_processors.i18n',
    'askbot.user_messages.context_processors.user_messages',#must be before auth
    'django.core.context_processors.auth', #this is required for admin
    'django.core.context_processors.csrf', #necessary for csrf protection
)


INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',

    #all of these are needed for the askbot
    'django.contrib.admin',
    'django.contrib.humanize',
    'django.contrib.sitemaps',
    #'debug_toolbar',
    'askbot',
    'askbot.deps.django_authopenid',
    #'askbot.importers.stackexchange', #se loader
    'south',
    'askbot.deps.livesettings',
    'keyedcache',
    'robots',
    'django_countries',
    'djcelery',
    'djkombu',
    'followit',
    #'avatar',#experimental use git clone git://github.com/ericflo/django-avatar.git$
    #requires setting of MEDIA_ROOT and MEDIA_URL
    #values of which can be the same as ASKBOT_FILE_UPLOAD_DIR and ASKBOT_UPLOADED_FILES_URL,
    #respectively
)


#setup memcached for production use!
#see http://docs.djangoproject.com/en/1.1/topics/cache/ for details
CACHE_BACKEND = 'locmem://'
#needed for django-keyedcache
CACHE_TIMEOUT = 6000
CACHE_PREFIX = 'askbot' #make this unique
CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
#If you use memcache you may want to uncomment the following line to enable memcached based sessions
#SESSION_ENGINE = 'django.contrib.sessions.backends.cache_db'

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'askbot.deps.django_authopenid.backends.AuthBackend',
)

#logging settings
LOG_FILENAME = 'askbot.log'
logging.basicConfig(
    filename=os.path.join(os.path.dirname(__file__), 'log', LOG_FILENAME),
    level=logging.CRITICAL,
    format='%(pathname)s TIME: %(asctime)s MSG: %(filename)s:%(funcName)s:%(lineno)d %(message)s',
)

###########################
#
#   this will allow running your forum with url like http://site.com/forum
#
#   ASKBOT_URL = 'forum/'
#
ASKBOT_URL = '' #no leading slash, default = '' empty string
ASKBOT_TRANSLATE_URL = True #translate specific URLs
_ = lambda v:v #fake translation function for the login url
LOGIN_URL = '/%s%s%s' % (ASKBOT_URL,_('account/'),_('signin/'))
LOGIN_REDIRECT_URL = ASKBOT_URL #adjust, if needed
#note - it is important that upload dir url is NOT translated!!!
#also, this url must not have the leading slash
ASKBOT_UPLOADED_FILES_URL = '%s%s' % (ASKBOT_URL, 'upfiles/')
ALLOW_UNICODE_SLUGS = False
ASKBOT_USE_STACKEXCHANGE_URLS = False #mimic url scheme of stackexchange

#Celery Settings
BROKER_TRANSPORT = "djkombu.transport.DatabaseTransport"
CELERY_ALWAYS_EAGER = True

import djcelery
djcelery.setup_loader()
DOMAIN_NAME = 'dev.com'

CSRF_COOKIE_NAME = 'dev.com_csrf'
CSRF_COOKIE_DOMAIN = DOMAIN_NAME
delete close flag offensive retag edit

Comments

Try using on-disk database, not :memory: and before running the tests do python manage.py syncdb --migrate, I've just tried your setup and found out that with in-memory database the test runner does not work.

Evgeny ( 2011-12-20 11:34:17 -0500 )edit

I did get it to run a bit further, using this commit.

Jacob Oscarson ( 2011-12-20 15:08:21 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2011-12-20 08:24:16 -0500

Evgeny gravatar image Evgeny flag of Chile
11009 50 84 182
http://askbot.org/

The tests can be run this way:

python manage.py test askbot
link publish delete flag offensive edit

Comments

This implies that you have created a project? (I have sources cloned in another directory than my project for experimentation)

Jacob Oscarson ( 2011-12-20 08:34:20 -0500 )edit

hmm, if askbot is in the installed apps, then the tests should run that way, regardless of where the app files are. But if you have issues with the command - like no tests run when you type the command - the test library might need to be debugged - insert import pdb; pdb.set_trace() line in the beginning of askbot/tests/__init__.py then step through. There might be some import error or something like that. On my development box the tests run ok.

Evgeny ( 2011-12-20 08:37:53 -0500 )edit

I've created a lab project (calling it 'dev' here) in my cloned directory. When running python dev/manage.py test askbot against that I get a long traceback ending like this: File "/Users/jacob/src/oss/askbot-dev/src/askbot/askbot/deps/livesettings/values.py", line 336, in _value raise SettingNotSet("Startup error, couldn't load %s.%s" %(self.group.key, self.key)) askbot.deps.livesettings.models.SettingNotSet: ("Startup error, couldn't load EXTERNAL_KEYS.RECAPTCHA_SECRET", None)

Jacob Oscarson ( 2011-12-20 08:38:04 -0500 )edit

This error is hard to debug. Can you send me sources of your project? Maybe something is missing in settings.py did you use settings.py that comes with askbot as a starting point and then added your app or the other way around? There are a couple of issues associated with the live settings module that I would like to resolve, but need failing test cases for that.

Evgeny ( 2011-12-20 08:43:10 -0500 )edit

We will look hard into this issue, I actually have a branch with that exact error, I will look again.

Evgeny ( 2011-12-20 08:54:22 -0500 )edit
0

answered 2011-12-20 10:13:03 -0500

Jacob Oscarson gravatar image Jacob Oscarson
11 2 1 3

updated 2011-12-20 10:16:16 -0500

I managed to get a test run that seems more promising by modifying the manage.py of the dummy project with the follow code after the import sections:

import sys, os
if 'DJANGO_SETTINGS_MODULE' not in os.environ:
    os.environ['DJANGO_SETTINGS_MODULE'] = 'dev.settings' # <-- name of my dummy project

if 'test' in sys.argv:
    sys.path.append('.')
    from dev import settings # <-- my dev project's settings module here
    settings.LIVESETTINGS_OPTIONS = {
        settings.SITE_ID: {'SETTINGS':
                {'EXTERNAL_KEYS': {
                    'RECAPTCHA_SECRET': 'xxx'
                    }
                 }
            }
    }

    from django.test.utils import setup_test_environment, teardown_test_environment
    setup_test_environment()
    if 'south' in settings.INSTALLED_APPS:
        from south.management.commands import patch_for_test_db_setup
        patch_for_test_db_setup()
    from django.db import connection
    connection.creation.create_test_db(1, True)

The test suites seems to be taking quite long time to run on my machine even with an sqlite3 :memory: database, but I suppose that's to be expected. I'll let it run through when I get time. It does seem to throw occasional failures, though.

SOUTH setup in test environments from my fork of django-pytest.

link publish delete flag offensive edit

Comments

We use development version of South right now as there was some issue with a released one, never heard of django-pytest... The workaround looks interesting, but not sure too many hacks can stand on top of each other:).

Evgeny ( 2011-12-20 11:37:08 -0500 )edit

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Reliable Askbot Hosting

Create your Q&A site at askbot.com. Managed Askbot hosting at just $15/mo. Dedicated hosting, support contracts, consulting services.

create your Q&A site
30 days free trial

Question tools

Follow
1 follower

subscribe to rss feed

Stats

Asked: 2011-12-20 08:14:57 -0500

Seen: 366 times

Last updated: Dec 20 '11