.. _howto-windmill-tests:

Writing a Functional Tests with Windmill
========================================

.. currentmodule:: django.test

If you need to test overall behaviors of your site, ajax widgets or rendered 
html, then functional tests are the solution. Django includes support for the 
popular `Windmill`_ framework. Writing a windmill test 
is simple, following these steps:

.. _Windmill: http://getwindmill.com

#. Your windmill tests must be their own module, named ``wmtests`` or ``windmilltests``.

#. Django must be able to run any function in the module without arguments.::

    from windmill.conf import global_settings
    ADMIN_URL =  "%s/test_admin/admin" % global_settings.TEST_URL
    from windmill.authoring import WindmillTestClient
    from django.test.utils import calling_func_name

    def test_loginAndSetup():
       '''Mostly just a proof of concept to test working order of tests.'''
       client = WindmillTestClient(calling_func_name())

       client.open(url='http://localhost:8000/admin')
       client.waits.forPageLoad(timeout=u'20000')
       ...

#. Your windmill testing module must load any files other than the module loader in ``__init__.py``.::

    from primary import * 
    ...

Setup and Teardown are done differently for windmill tests, and consist of the following
functions. :

    * :meth:`setup_module`
    * :meth:`teardown_module`
   
A sample implementation, in ``__init__.py``.::

    from primary import *
    
    def setup_module(module):
        module.property = fetch_property()
    
    def teardown_module(module):
        module.property = None
    


These methods can be included in any file with windmill tests. See `functest`_
for more information. 

.. _functest : http://functest.pythonesque.org/