[nosetests] Add some basics for integration testing.

Run tests with $nosetests tests.
Run two instances of django with their own manage, settings and db files.
Here, only test connection with users in db.
This commit is contained in:
Mikaël Ates 2010-10-18 18:39:40 +02:00
parent 2e7c3dfe5c
commit 80786ddd05
8 changed files with 549 additions and 0 deletions

View File

@ -0,0 +1,49 @@
import sys
import os
import signal
import subprocess
import time
import twill
import urllib2
import os.path
import re
TEST_PATH = os.path.dirname(os.path.abspath(__file__))
def waitforport(port, start):
while True:
if time.time() - start > 900:
raise Exception('Servers did not start in 90 seconds')
time.sleep(1)
try:
urllib2.urlopen('http://localhost:%s' % port)
except urllib2.URLError:
continue
else:
break
pids = []
def setup():
idp_command = ['python', os.path.join(TEST_PATH, 'idp_manage.py'), 'runserver', 'localhost:10000', '--verbosity=2']
p = subprocess.Popen(idp_command)
pids.append(p.pid)
sp_command = ['python', os.path.join(TEST_PATH, 'sp_manage.py'), 'runserver', 'localhost:10001', '--verbosity=2']
p = subprocess.Popen(sp_command)
pids.append(p.pid)
# Wait for the daemons to load themselves
starttime = time.time()
waitforport(10000, starttime)
waitforport(10001, starttime)
def teardown():
for pid in pids:
try:
# TODO: do something better...
if os.path.exists("/proc/" + str(pid+2)):
os.kill(pid+2, signal.SIGINT) # In status check the Ppid
os.kill(pid, signal.SIGINT)
except OSError:
print >> sys.stderr, 'failed to kill pid %s or its son' % pid

Binary file not shown.

View File

@ -0,0 +1,10 @@
from django.core.management import *
try:
import idp_settings as settings
except ImportError:
import sys
sys.stderr.write("Error: Unable to import settings from %s!\n" % __file__)
sys.exit(1)
if __name__ == "__main__":
execute_manager(settings)

View File

@ -0,0 +1,219 @@
# Django settings for authentic project.
import os
gettext_noop = lambda s: s
DEBUG = True
USE_DEBUG_TOOLBAR = True
STATIC_SERVE = True
TEMPLATE_DEBUG = DEBUG
TEST_PATH = os.path.dirname(os.path.abspath(__file__))
#TODO: tests must be run from the authentic directory: nosetests tests/integration/saml2
PROJECT_PATH = os.path.abspath('')
ADMINS = (
# ('Your Name', 'your_email@domain.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(TEST_PATH, 'idp.db'),
},
}
#session cookie parameters
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SESSION_COOKIE_AGE = 36000
# 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 = 'Europe/Paris'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en'
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
LANGUAGES = (
('en', gettext_noop('English')),
('fr', gettext_noop('French')),
)
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media')
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = '/media/'
# 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 = '/media/admin/'
# Make this unique, and don't share it with anybody.
SECRET_KEY = '0!=(1kc6kri-ui+tmj@mr+*0bvj!(p*r0duu2n=)7@!p=pvf9n'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.request',
'django.contrib.messages.context_processors.messages',
'authentic.core.context_processors.auth_settings',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.csrf.middleware.CsrfMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'authentic.admin_log_view.middleware.LoggerMiddleware',
)
ROOT_URLCONF = 'authentic.urls'
TEMPLATE_DIRS = (
os.path.join(PROJECT_PATH, 'templates'),
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.admin',
'django.contrib.sites',
'authentic.saml',
'authentic.idp',
'authentic.idp.saml',
'registration',
'authentic.sslauth',
'authentic.admin_log_view',
)
MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
# Registration settings
ACCOUNT_ACTIVATION_DAYS = 2
EMAIL_HOST = 'localhost'
DEFAULT_FROM_EMAIL = 'webmaster@entrouvert.com'
LOGIN_REDIRECT_URL = '/'
INTERNAL_IPS = ('127.0.0.1',)
DEBUG_TOOLBAR_CONFIG = {'INTERCEPT_REDIRECTS': False}
# SAML settings
# Only RSA private keys are currently supported
IDP_SAML2 = True
IDP_IDFF12 = True
SAML_PRIVATE_KEY = '''-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAvxFkfPdndlGgQPDZgFGXbrNAc/79PULZBuNdWFHDD9P5hNhZ
n9Kqm4Cp06Pe/A6u+g5wLnYvbZQcFCgfQAEzziJtb3J55OOlB7iMEI/T2AX2WzrU
H8QT8NGhABONKU2Gg4XiyeXNhH5R7zdHlUwcWq3ZwNbtbY0TVc+n665EbrfV/59x
ihSqsoFrkmBLH0CoepUXtAzA7WDYn8AzusIuMx3n8844pJwgxhTB7Gjuboptlz9H
ri8JRdXiVT9OS9Wt69ubcNoM6zuKASmtm48U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DvZ8/R/MexTA/1204u/mBecMJiO/jPw3GdIJ5phv2omHe1MSuSNsDfN8Sbap
gmsgaiMCgYB/nrTk89Fp7050VKCNnIt1mHAcO9cBwDV8qrJ5O3rIVmrg1T6vn0aY
wRiVcNacaP+BivkrMjr4BlsUM6yH4MOBsNhLURiiCL+tLJV7U0DWlCse/doWij4U
TKX6tp6oI+7MIJE6ySZ0cBqOiydAkBePZhu57j6ToBkTa0dbHjn1WA==
-----END RSA PRIVATE KEY-----'''
SAML_METADATA_ROOT = os.path.join(PROJECT_PATH, 'metadata')
# SSL settings
AUTH_SSL = True
SSLAUTH_CREATE_USER = True
AUTHENTICATION_BACKENDS = (
'authentic.idp.auth_backends.LogginBackend',
'django.contrib.auth.backends.ModelBackend',
'authentic.sslauth.backends.SSLAuthBackend',
)
#AuthSAML2 Configuration
INSTALLED_APPS += ('authentic.authsaml2',)
SAML2_BACKEND = 'authentic.authsaml2.backends.AuthSAML2Backend'
AUTHENTICATION_BACKENDS += (SAML2_BACKEND,)
TEMPLATE_CONTEXT_PROCESSORS += ('authentic.idp.views.authsaml2_login_page',)
# OpenID settings
AUTH_OPENID = True
IDP_OPENID = False
IDPOI_PATH = ''
# Logging settings
LOG_FILENAME = 'log.log'
LOG_FILE_LEVEL = 10 #CRITICAL 50 ERROR 40 WARNING 30 INFO 20 DEBUG 10
LOG_SYSLOG = True
LOG_SYS_LEVEL = 10
#import pdb
#pdb.set_trace()
# local_settings.py can be used to override environment-specific settings
# like database and email that differ between development and production.
#try:
# from local_settings import *
#except ImportError:
# pass
if USE_DEBUG_TOOLBAR:
MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)
INSTALLED_APPS += ('debug_toolbar',)
if AUTH_OPENID:
MIDDLEWARE_CLASSES += ('django_authopenid.middleware.OpenIDMiddleware',)
INSTALLED_APPS += ('django_authopenid',)
if IDP_OPENID:
INSTALLED_APPS += ('django_openid_provider',
'openid_provider',)
TEMPLATE_DIRS = (
os.path.join(PROJECT_PATH, 'templates/django_openid_provider'),
)

Binary file not shown.

View File

@ -0,0 +1,11 @@
from django.core.management import *
try:
import sp_settings as settings
except ImportError:
import sys
sys.stderr.write("Error: Unable to import settings from %s!\n" % __file__)
sys.exit(1)
if __name__ == "__main__":
execute_manager(settings)

View File

@ -0,0 +1,216 @@
# Django settings for authentic project.
import os
gettext_noop = lambda s: s
DEBUG = True
USE_DEBUG_TOOLBAR = True
STATIC_SERVE = True
TEMPLATE_DEBUG = DEBUG
TEST_PATH = os.path.dirname(os.path.abspath(__file__))
#TODO: tests must be run from the authentic directory: nosetests tests/integration/saml2
PROJECT_PATH = os.path.abspath('')
ADMINS = (
# ('Your Name', 'your_email@domain.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(TEST_PATH, 'sp.db'),
},
}
#session cookie parameters
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SESSION_COOKIE_AGE = 36000
# 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 = 'Europe/Paris'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en'
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
LANGUAGES = (
('en', gettext_noop('English')),
('fr', gettext_noop('French')),
)
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media')
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = '/media/'
# 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 = '/media/admin/'
# Make this unique, and don't share it with anybody.
SECRET_KEY = '0!=(1kc6kri-ui+tmj@mr+*0bvj!(p*r0duu2n=)7@!p=pvf9n'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.request',
'django.contrib.messages.context_processors.messages',
'authentic.core.context_processors.auth_settings',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.csrf.middleware.CsrfMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'authentic.admin_log_view.middleware.LoggerMiddleware',
)
ROOT_URLCONF = 'authentic.urls'
TEMPLATE_DIRS = (
os.path.join(PROJECT_PATH, 'templates'),
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.admin',
'django.contrib.sites',
'authentic.saml',
'authentic.idp',
'authentic.idp.saml',
'registration',
'authentic.sslauth',
'authentic.admin_log_view',
)
MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
# Registration settings
ACCOUNT_ACTIVATION_DAYS = 2
EMAIL_HOST = 'localhost'
DEFAULT_FROM_EMAIL = 'webmaster@entrouvert.com'
LOGIN_REDIRECT_URL = '/'
INTERNAL_IPS = ('127.0.0.1',)
DEBUG_TOOLBAR_CONFIG = {'INTERCEPT_REDIRECTS': False}
# SAML settings
# Only RSA private keys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XZC4vs/Vy7lrzTiHDRZk2SG5EkHMSKFA53jN6S/nJ
JWpYZC8lG8w4OHaUfDHFWbptxdGYCgY4//sjeiuXAoGBANuhurJ99R5PnA8AOgEW
4zD1hLc0b4ir8fvshCIcAj9SUB20+afgayRv2ye3Dted1WkUL4WYPxccVhLWKITi
rRtqB03o8m3pG3kJnUr0LIzu0px5J/o8iH3ZOJOTE3iBa+uI/KHmxygc2H+XPGFa
HGeAxuJCNO2kAN0Losbnz5dlAoGAVsCn94gGWPxSjxA0PC7zpTYVnZdwOjbPr/pO
LDE0cEY9GBq98JjrwEd77KibmVMm+Z4uaaT0jXiYhl8pyJ5IFwUS13juCbo1z/u/
ldMoDvZ8/R/MexTA/1204u/mBecMJiO/jPw3GdIJ5phv2omHe1MSuSNsDfN8Sbap
gmsgaiMCgYB/nrTk89Fp7050VKCNnIt1mHAcO9cBwDV8qrJ5O3rIVmrg1T6vn0aY
wRiVcNacaP+BivkrMjr4BlsUM6yH4MOBsNhLURiiCL+tLJV7U0DWlCse/doWij4U
TKX6tp6oI+7MIJE6ySZ0cBqOiydAkBePZhu57j6ToBkTa0dbHjn1WA==
-----END RSA PRIVATE KEY-----'''
SAML_METADATA_ROOT = os.path.join(PROJECT_PATH, 'metadata')
# SSL settings
AUTH_SSL = True
SSLAUTH_CREATE_USER = True
AUTHENTICATION_BACKENDS = (
'authentic.idp.auth_backends.LogginBackend',
'django.contrib.auth.backends.ModelBackend',
'authentic.sslauth.backends.SSLAuthBackend',
)
#AuthSAML2 Configuration
INSTALLED_APPS += ('authentic.authsaml2',)
SAML2_BACKEND = 'authentic.authsaml2.backends.AuthSAML2Backend'
AUTHENTICATION_BACKENDS += (SAML2_BACKEND,)
TEMPLATE_CONTEXT_PROCESSORS += ('authentic.idp.views.authsaml2_login_page',)
# OpenID settings
AUTH_OPENID = True
IDP_OPENID = False
IDPOI_PATH = ''
# Logging settings
LOG_FILENAME = 'log.log'
LOG_FILE_LEVEL = 10 #CRITICAL 50 ERROR 40 WARNING 30 INFO 20 DEBUG 10
LOG_SYSLOG = True
LOG_SYS_LEVEL = 10
# local_settings.py can be used to override environment-specific settings
# like database and email that differ between development and production.
try:
from local_settings import *
except ImportError:
pass
if USE_DEBUG_TOOLBAR:
MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)
INSTALLED_APPS += ('debug_toolbar',)
if AUTH_OPENID:
MIDDLEWARE_CLASSES += ('django_authopenid.middleware.OpenIDMiddleware',)
INSTALLED_APPS += ('django_authopenid',)
if IDP_OPENID:
INSTALLED_APPS += ('django_openid_provider',
'openid_provider',)
TEMPLATE_DIRS = (
os.path.join(PROJECT_PATH, 'templates/django_openid_provider'),
)

View File

@ -0,0 +1,44 @@
import twill
print 'test_00_config'
def test_config_idp():
twill.commands.reset_browser()
twill.execute_string('''
go http://localhost:10000/admin/
fv 1 username root
fv 1 password root
submit
go http://localhost:10000/admin/
find 'dministration'
''')
twill.commands.reset_browser()
twill.execute_string('''
go http://localhost:10000
fv 1 username user1
fv 1 password user1
submit
url http://localhost:10000
find 'You are authenticated'
''')
def test_config_sp():
twill.commands.reset_browser()
twill.execute_string('''
go http://localhost:10001/admin/
fv 1 username root
fv 1 password root
submit
go http://localhost:10001/admin/
find 'dministration'
''')
twill.commands.reset_browser()
twill.execute_string('''
go http://localhost:10001
fv 1 username user2
fv 1 password user2
submit
url http://localhost:10001
find 'You are authenticated'
''')