summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Kubasik <kevin@kubasik.net>2009-06-17 01:27:20 +0000
committerKevin Kubasik <kevin@kubasik.net>2009-06-17 01:27:20 +0000
commit9628ae6c921f6c9bc6ef8e784b35203993f7f3cd (patch)
tree54ed7fb65eeb1166258435702e4b9ee0cc930d73
parent86e7e1b82ad03eb8bb315549528da3e7416b4368 (diff)
[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
-rw-r--r--django/core/management/commands/test_windmill.py102
-rwxr-xr-xtests/runtests.py3
-rwxr-xr-xtests/windmill_dev/__init__.py0
-rwxr-xr-xtests/windmill_dev/manage.py11
-rwxr-xr-xtests/windmill_dev/settings.py83
-rw-r--r--tests/windmill_dev/testapp/__init__.py0
-rw-r--r--tests/windmill_dev/testapp/models.py3
-rw-r--r--tests/windmill_dev/testapp/tests.py32
-rw-r--r--tests/windmill_dev/testapp/views.py1
-rw-r--r--tests/windmill_dev/testapp/windmilltests/__init__.py12
-rwxr-xr-xtests/windmill_dev/urls.py17
11 files changed, 264 insertions, 0 deletions
diff --git a/django/core/management/commands/test_windmill.py b/django/core/management/commands/test_windmill.py
new file mode 100644
index 0000000000..d9b72f9c3e
--- /dev/null
+++ b/django/core/management/commands/test_windmill.py
@@ -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)
diff --git a/tests/runtests.py b/tests/runtests.py
index 98aaf41608..19c6588679 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -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)
if 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.
settings.INSTALLED_APPS = old_installed_apps
diff --git a/tests/windmill_dev/__init__.py b/tests/windmill_dev/__init__.py
new file mode 100755
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/windmill_dev/__init__.py
diff --git a/tests/windmill_dev/manage.py b/tests/windmill_dev/manage.py
new file mode 100755
index 0000000000..5e78ea979e
--- /dev/null
+++ b/tests/windmill_dev/manage.py
@@ -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)
diff --git a/tests/windmill_dev/settings.py b/tests/windmill_dev/settings.py
new file mode 100755
index 0000000000..ba75978ae6
--- /dev/null
+++ b/tests/windmill_dev/settings.py
@@ -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',
+)
diff --git a/tests/windmill_dev/testapp/__init__.py b/tests/windmill_dev/testapp/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/windmill_dev/testapp/__init__.py
diff --git a/tests/windmill_dev/testapp/models.py b/tests/windmill_dev/testapp/models.py
new file mode 100644
index 0000000000..71a8362390
--- /dev/null
+++ b/tests/windmill_dev/testapp/models.py
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
diff --git a/tests/windmill_dev/testapp/tests.py b/tests/windmill_dev/testapp/tests.py
new file mode 100644
index 0000000000..63fe9ec782
--- /dev/null
+++ b/tests/windmill_dev/testapp/tests.py
@@ -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'
+
+
diff --git a/tests/windmill_dev/testapp/views.py b/tests/windmill_dev/testapp/views.py
new file mode 100644
index 0000000000..60f00ef0ef
--- /dev/null
+++ b/tests/windmill_dev/testapp/views.py
@@ -0,0 +1 @@
+# Create your views here.
diff --git a/tests/windmill_dev/testapp/windmilltests/__init__.py b/tests/windmill_dev/testapp/windmilltests/__init__.py
new file mode 100644
index 0000000000..b942b75115
--- /dev/null
+++ b/tests/windmill_dev/testapp/windmilltests/__init__.py
@@ -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') \ No newline at end of file
diff --git a/tests/windmill_dev/urls.py b/tests/windmill_dev/urls.py
new file mode 100755
index 0000000000..123cf0cbe0
--- /dev/null
+++ b/tests/windmill_dev/urls.py
@@ -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),
+)