mirror of
https://github.com/django/django.git
synced 2025-07-05 18:29:11 +00:00
[gsoc2009-testing] Creating a placeholder project for developing the windmill tests against. Also integrated the test_windmill command for the time being, although that needs discussion.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/test-improvements@11015 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
86e7e1b82a
commit
9628ae6c92
102
django/core/management/commands/test_windmill.py
Normal file
102
django/core/management/commands/test_windmill.py
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from windmill.authoring import djangotest
|
||||||
|
import sys, os
|
||||||
|
from time import sleep
|
||||||
|
import types
|
||||||
|
import logging
|
||||||
|
|
||||||
|
class ServerContainer(object):
|
||||||
|
start_test_server = djangotest.start_test_server
|
||||||
|
stop_test_server = djangotest.stop_test_server
|
||||||
|
|
||||||
|
def attempt_import(name, suffix):
|
||||||
|
try:
|
||||||
|
mod = __import__(name+'.'+suffix)
|
||||||
|
except ImportError:
|
||||||
|
mod = None
|
||||||
|
if mod is not None:
|
||||||
|
s = name.split('.')
|
||||||
|
mod = __import__(s.pop(0))
|
||||||
|
for x in s+[suffix]:
|
||||||
|
mod = getattr(mod, x)
|
||||||
|
return mod
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
|
||||||
|
help = "Run windmill tests. Specify a browser, if one is not passed Firefox will be used"
|
||||||
|
|
||||||
|
args = '<label label ...>'
|
||||||
|
label = 'label'
|
||||||
|
|
||||||
|
def handle(self, *labels, **options):
|
||||||
|
|
||||||
|
from windmill.conf import global_settings
|
||||||
|
from windmill.authoring.djangotest import WindmillDjangoUnitTest
|
||||||
|
if 'ie' in labels:
|
||||||
|
global_settings.START_IE = True
|
||||||
|
sys.argv.remove('ie')
|
||||||
|
elif 'safari' in labels:
|
||||||
|
global_settings.START_SAFARI = True
|
||||||
|
sys.argv.remove('safari')
|
||||||
|
elif 'chrome' in labels:
|
||||||
|
global_settings.START_CHROME = True
|
||||||
|
sys.argv.remove('chrome')
|
||||||
|
else:
|
||||||
|
global_settings.START_FIREFOX = True
|
||||||
|
if 'firefox' in labels:
|
||||||
|
sys.argv.remove('firefox')
|
||||||
|
|
||||||
|
if 'manage.py' in sys.argv:
|
||||||
|
sys.argv.remove('manage.py')
|
||||||
|
if 'test_windmill' in sys.argv:
|
||||||
|
sys.argv.remove('test_windmill')
|
||||||
|
server_container = ServerContainer()
|
||||||
|
server_container.start_test_server()
|
||||||
|
|
||||||
|
global_settings.TEST_URL = 'http://localhost:%d' % server_container.server_thread.port
|
||||||
|
|
||||||
|
# import windmill
|
||||||
|
# windmill.stdout, windmill.stdin = sys.stdout, sys.stdin
|
||||||
|
from windmill.authoring import setup_module, teardown_module
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
tests = []
|
||||||
|
for name in settings.INSTALLED_APPS:
|
||||||
|
for suffix in ['tests', 'wmtests', 'windmilltests']:
|
||||||
|
x = attempt_import(name, suffix)
|
||||||
|
if x is not None: tests.append((suffix,x,));
|
||||||
|
|
||||||
|
wmtests = []
|
||||||
|
for (ttype, mod,) in tests:
|
||||||
|
if ttype == 'tests':
|
||||||
|
for ucls in [getattr(mod, x) for x in dir(mod)
|
||||||
|
if ( type(getattr(mod, x, None)) in (types.ClassType,
|
||||||
|
types.TypeType) ) and
|
||||||
|
issubclass(getattr(mod, x), WindmillDjangoUnitTest)
|
||||||
|
]:
|
||||||
|
wmtests.append(ucls.test_dir)
|
||||||
|
|
||||||
|
else:
|
||||||
|
if mod.__file__.endswith('__init__.py') or mod.__file__.endswith('__init__.pyc'):
|
||||||
|
wmtests.append(os.path.join(*os.path.split(os.path.abspath(mod.__file__))[:-1]))
|
||||||
|
else:
|
||||||
|
wmtests.append(os.path.abspath(mod.__file__))
|
||||||
|
|
||||||
|
if len(wmtests) is 0:
|
||||||
|
print 'Sorry, no windmill tests found.'
|
||||||
|
else:
|
||||||
|
testtotals = {}
|
||||||
|
x = logging.getLogger()
|
||||||
|
x.setLevel(0)
|
||||||
|
from windmill.server.proxy import logger
|
||||||
|
from functest import bin
|
||||||
|
from functest import runner
|
||||||
|
runner.CLIRunner.final = classmethod(lambda self, totals: testtotals.update(totals) )
|
||||||
|
import windmill
|
||||||
|
setup_module(tests[0][1])
|
||||||
|
sys.argv = sys.argv + wmtests
|
||||||
|
bin.cli()
|
||||||
|
teardown_module(tests[0][1])
|
||||||
|
if testtotals['fail'] is not 0:
|
||||||
|
sleep(.5)
|
||||||
|
sys.exit(1)
|
@ -166,6 +166,9 @@ def django_tests(verbosity, interactive, test_labels):
|
|||||||
failures = tr.run_tests(test_labels, verbosity=verbosity, interactive=interactive, extra_tests=extra_tests)
|
failures = tr.run_tests(test_labels, verbosity=verbosity, interactive=interactive, extra_tests=extra_tests)
|
||||||
if failures:
|
if failures:
|
||||||
sys.exit(failures)
|
sys.exit(failures)
|
||||||
|
from django.core.management.commands.test_windmill import Command as testwm_cmd
|
||||||
|
windmill_runner = testwm_cmd()
|
||||||
|
windmill_runner.handle()
|
||||||
|
|
||||||
# Restore the old settings.
|
# Restore the old settings.
|
||||||
settings.INSTALLED_APPS = old_installed_apps
|
settings.INSTALLED_APPS = old_installed_apps
|
||||||
|
0
tests/windmill_dev/__init__.py
Executable file
0
tests/windmill_dev/__init__.py
Executable file
11
tests/windmill_dev/manage.py
Executable file
11
tests/windmill_dev/manage.py
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
from django.core.management import execute_manager
|
||||||
|
try:
|
||||||
|
import settings # Assumed to be in the same directory.
|
||||||
|
except ImportError:
|
||||||
|
import sys
|
||||||
|
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
execute_manager(settings)
|
83
tests/windmill_dev/settings.py
Executable file
83
tests/windmill_dev/settings.py
Executable file
@ -0,0 +1,83 @@
|
|||||||
|
# Django settings for windmill_dev project.
|
||||||
|
|
||||||
|
DEBUG = True
|
||||||
|
TEMPLATE_DEBUG = DEBUG
|
||||||
|
|
||||||
|
ADMINS = (
|
||||||
|
# ('Your Name', 'your_email@domain.com'),
|
||||||
|
)
|
||||||
|
|
||||||
|
MANAGERS = ADMINS
|
||||||
|
|
||||||
|
DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
|
||||||
|
DATABASE_NAME = 'test.db' # 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.
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
# If running in a Windows environment this must be set to the same as your
|
||||||
|
# system time zone.
|
||||||
|
TIME_ZONE = 'America/Chicago'
|
||||||
|
|
||||||
|
# Language code for this installation. All choices can be found here:
|
||||||
|
# http://www.i18nguy.com/unicode/language-identifiers.html
|
||||||
|
LANGUAGE_CODE = 'en-us'
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# Absolute path to the directory that holds media.
|
||||||
|
# Example: "/home/media/media.lawrence.com/"
|
||||||
|
MEDIA_ROOT = ''
|
||||||
|
|
||||||
|
# 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 = ''
|
||||||
|
|
||||||
|
# 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/'
|
||||||
|
|
||||||
|
# Make this unique, and don't share it with anybody.
|
||||||
|
SECRET_KEY = '+w3^9f0n-e+08t&z@&#^47z(qd@c$a#mr^$!(ab+xdoovu%_9h'
|
||||||
|
|
||||||
|
# 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',
|
||||||
|
# 'django.template.loaders.eggs.load_template_source',
|
||||||
|
)
|
||||||
|
|
||||||
|
MIDDLEWARE_CLASSES = (
|
||||||
|
'django.middleware.common.CommonMiddleware',
|
||||||
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
|
)
|
||||||
|
|
||||||
|
ROOT_URLCONF = 'windmill_dev.urls'
|
||||||
|
|
||||||
|
TEMPLATE_DIRS = (
|
||||||
|
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
|
||||||
|
# Always use forward slashes, even on Windows.
|
||||||
|
# Don't forget to use absolute paths, not relative paths.
|
||||||
|
)
|
||||||
|
|
||||||
|
INSTALLED_APPS = (
|
||||||
|
'django.contrib.auth',
|
||||||
|
'django.contrib.contenttypes',
|
||||||
|
'django.contrib.sessions',
|
||||||
|
'django.contrib.sites',
|
||||||
|
'django.contrib.admin',
|
||||||
|
'django.contrib.admindocs',
|
||||||
|
'windmill',
|
||||||
|
'testapp',
|
||||||
|
)
|
0
tests/windmill_dev/testapp/__init__.py
Normal file
0
tests/windmill_dev/testapp/__init__.py
Normal file
3
tests/windmill_dev/testapp/models.py
Normal file
3
tests/windmill_dev/testapp/models.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
32
tests/windmill_dev/testapp/tests.py
Normal file
32
tests/windmill_dev/testapp/tests.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
"""
|
||||||
|
This file demonstrates two different styles of tests (one doctest and one
|
||||||
|
unittest). These will both pass when you run "manage.py test".
|
||||||
|
|
||||||
|
Replace these with more appropriate tests for your application.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
class SimpleTest(TestCase):
|
||||||
|
def test_basic_addition(self):
|
||||||
|
"""
|
||||||
|
Tests that 1 + 1 always equals 2.
|
||||||
|
"""
|
||||||
|
self.failUnlessEqual(1 + 1, 2)
|
||||||
|
|
||||||
|
__test__ = {"doctest": """
|
||||||
|
Another way to test that 1 + 1 is equal to 2.
|
||||||
|
|
||||||
|
>>> 1 + 1 == 2
|
||||||
|
True
|
||||||
|
"""}
|
||||||
|
|
||||||
|
import os
|
||||||
|
from windmill.authoring import djangotest
|
||||||
|
|
||||||
|
class TestProjectWindmillTest(djangotest.WindmillDjangoUnitTest):
|
||||||
|
test_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'windmilltests')
|
||||||
|
#test_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
browser = 'firefox'
|
||||||
|
|
||||||
|
|
1
tests/windmill_dev/testapp/views.py
Normal file
1
tests/windmill_dev/testapp/views.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
# Create your views here.
|
12
tests/windmill_dev/testapp/windmilltests/__init__.py
Normal file
12
tests/windmill_dev/testapp/windmilltests/__init__.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# Generated by the windmill services transformer
|
||||||
|
from windmill.authoring import WindmillTestClient
|
||||||
|
|
||||||
|
def test_recordingSuite0():
|
||||||
|
client = WindmillTestClient(__name__)
|
||||||
|
client.type(text="Hello", name='q')
|
||||||
|
client.click(xpath=u"//span[@id='body']/center/form/table[2]/tbody/tr[8]/td")
|
||||||
|
client.waits.forPageLoad(timeout=u'20000')
|
||||||
|
client.asserts.assertNode(xpath=u"//div[@id='res']/div/ol/li/h3[1]/a/em")
|
||||||
|
client.asserts.assertNode(link=u'How do you say hello in Japanese ? - Yahoo! Answers')
|
||||||
|
client.asserts.assertNode(link=u'hello')
|
||||||
|
client.asserts.assertNode(link=u'japanese')
|
17
tests/windmill_dev/urls.py
Executable file
17
tests/windmill_dev/urls.py
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
from django.conf.urls.defaults import *
|
||||||
|
|
||||||
|
# Uncomment the next two lines to enable the admin:
|
||||||
|
from django.contrib import admin
|
||||||
|
admin.autodiscover()
|
||||||
|
|
||||||
|
urlpatterns = patterns('',
|
||||||
|
# Example:
|
||||||
|
# (r'^windmill_dev/', include('windmill_dev.foo.urls')),
|
||||||
|
|
||||||
|
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
|
||||||
|
# to INSTALLED_APPS to enable admin documentation:
|
||||||
|
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
|
||||||
|
|
||||||
|
# Uncomment the next line to enable the admin:
|
||||||
|
(r'^admin/(.*)', admin.site.root),
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user