.. _topics-testing:

===================
Testing in Merengue
===================

There are two kinds of tests in Merengue:

* Unit tests, see `testing in Django`_ for more information.

* Selenium tests, using the `Selenium web application testing system`_.

.. _`testing in Django`: http://docs.djangoproject.com/en/1.1/topics/testing/
.. _`Selenium web application testing system`: http://seleniumhq.org/


Unit tests
==========

Unit tests are executed using the ``manage.py`` Django utility located inside
every Merengue project, like this:

.. code-block:: bash

    $ python manage.py test

This will try to execute all tests in every application installed in the
Merengue project.

You can also launch test for only one application appending the application in
command line, as follows:

.. code-block:: bash

    $ python manage.py test perms


Selenium tests
==============

Selenium tests are very useful because they tests all application layers (from
database to user interface). It came with a IDE to launch and records functional
tests:

.. image:: _images/selenium_tests.png

These are the steps for installing and executing the Merengue
`Selenium tests suites`_:

1. Installing the selenium IDE Firefox plugin, in the `download page`_.
2. Make sure that *English* is the first language preference in Firefox.
3. Launch Selenium IDE in Options menu.
4. Load a needed Selenium Core extension for loading global variables, located in ``merengueproj/tests/selenium/extensions/user-extensions.js``. This is done in ``Options`` menu in Selenium IDE.
5. Change the ``merengueproj/tests/selenium/generic/variables.html`` file, setting the ``TEST_DATA_DIR`` variable, which have to point to the absolute path to ``merengueproj/tests/selenium/test-data`` directory.
6. Open any test suite (``suite.html`` file) located in the subdirectories of ``merengueproj/tests/selenium/generic`` directory.
7. Execute it.

.. _`download page`: http://seleniumhq.org/download/
.. _`Selenium tests suites`: http://dev.merengueproject.org/browser/trunk/merengueproj/tests/selenium/generic

How to run all selenium test at once?
-------------------------------------

There is a script to execute all suites of selenium test that are located at
``merengueproj/tests/selenium/generic`` subdirectories. This script is
*run_suites.py* and is used as follow:

.. code-block:: bash

    $ python run_suites.py basic_url

``basic_url`` is the basic url of the domain to test (i.e.
http://localhost:8000/). All relatives url depends of this one.

Also, it's necessary to run the script with ``selenium-server.jar`` files on the same directory.

.. note::

    ``selenium-server.jar`` is a file included in Selenium application.

.. admonition:: Note for not english browsers

    If your browser are configured in non english language and your web allow
    the language, Merengue will set by default that language and the test will
    fail. A quick workaround is disabling ``'django.middleware.locale.LocaleMiddleware'``
    from your project middlewares (by default is in ``PRE_MERENGUE_MIDDLEWARE_CLASSES``
    setting, in `merengue/settings.py`_ file).

.. _`merengue/settings.py`: http://dev.merengueproject.org/browser/trunk/merengueproj/merengue/settings.py