Files
tryton/trytond/doc/ref/tests.rst
T

166 lines
4.5 KiB
ReStructuredText
Raw Normal View History

2017-10-02 11:38:31 +02:00
.. _ref-test:
.. module:: trytond.tests.test_tryton
2022-03-27 16:06:09 +02:00
Tests
=====
2017-10-02 11:38:31 +02:00
.. attribute:: DB_NAME
2022-03-27 16:06:09 +02:00
The name of the database to use for testing.
Its value is taken from the environment variable of the same name.
2017-10-02 11:38:31 +02:00
.. attribute:: USER
2022-03-27 16:06:09 +02:00
The user id used to test the transactions
2017-10-02 11:38:31 +02:00
.. attribute:: CONTEXT
2022-03-27 16:06:09 +02:00
The context used to test the transactions
2017-10-02 11:38:31 +02:00
.. function:: activate_module(name)
2022-03-27 16:06:09 +02:00
Activate the named module for the tested database.
2017-10-02 11:38:31 +02:00
2022-03-27 16:06:09 +02:00
In case database does not exist and the ``DB_CACHE`` environment variable is
set then Tryton restores a backup found in the directory pointed by
``DB_CACHE``.
``DB_CACHE`` can also be set to the value ``postgresql://``, in that case
Tryton create the database using the template found on the server.
2022-03-27 16:06:09 +02:00
Otherwise it procees to the creation of the database and the activation of
the module.
2017-10-02 11:38:31 +02:00
``DB_CACHE_JOBS`` environment variable defines the number of jobs used for
dump and restore operations.
The default value is the number of CPU.
2017-10-02 11:38:31 +02:00
ModuleTestCase
2022-03-27 16:06:09 +02:00
--------------
2017-10-02 11:38:31 +02:00
.. class:: ModuleTestCase()
2022-03-27 16:06:09 +02:00
A subclass of `unittest.TestCase`_ that tests a Tryton module.
Some tests are included to ensure that the module works properly.
2017-10-02 11:38:31 +02:00
2022-03-27 16:06:09 +02:00
It creates a temporary database with the module activated in setUpClass_ and
drops it in the tearDownClass_ method.
2017-10-02 11:38:31 +02:00
.. attribute:: ModuleTestCase.module
2022-03-27 16:06:09 +02:00
Name of the tested module.
2017-10-02 11:38:31 +02:00
2023-09-12 18:52:14 +02:00
.. attribute:: ModuleTestCase.extras
A list of extra modules to activate
.. attribute:: ModuleTestCase.language
The language to activate.
Default value is ``en``.
RouteTestCase
-------------
.. class:: RouteTestCase()
A subclass of `unittest.TestCase`_ to test Tryton routes.
It creates a temporary database with the module activated in setUpClass_ and
drops it in the tearDownClass_ method.
.. attribute:: RouteTestCase.module
Name of the tested module.
.. attribute:: RouteTestCase.extras
A list of extra modules to activate
.. attribute:: RouteTestCase.language
The language to activate.
Default value is ``en``.
.. attribute:: RouteTestCase.db_name
Returns the name of the database
.. classmethod:: RouteTestCase.setUpDatabase()
A method called by setUpClass_ after activating the modules in a
:class:`~trytond.transaction.Transaction`.
It is used to setup data in the database.
.. method:: RouteTestCase.client()
Return a client to simulate requests to the WSGI application.
2017-10-02 11:38:31 +02:00
.. _`unittest.TestCase`: https://docs.python.org/library/unittest.html#test-cases
.. _setUpClass: https://docs.python.org/library/unittest.html#unittest.TestCase.setUpClass
.. _tearDownClass: https://docs.python.org/library/unittest.html#unittest.TestCase.tearDownClass
2023-09-12 18:52:14 +02:00
2017-10-02 11:38:31 +02:00
Helpers
2022-03-27 16:06:09 +02:00
-------
2017-10-02 11:38:31 +02:00
.. function:: with_transaction(user=1, context=None)
2022-03-27 16:06:09 +02:00
Return a decorator to run a test case inside a
:class:`~trytond.transaction.Transaction`.
It is rolled back and the cache cleared at the end of the test.
2017-10-02 11:38:31 +02:00
doctest helpers
---------------
.. function:: doctest_setup
2022-03-27 16:06:09 +02:00
Prepare the run of the `doctest`_ by creating a database and dropping it
beforehand if necessary.
This function should be used as the ``setUp`` parameter.
2017-10-02 11:38:31 +02:00
2022-03-27 16:06:09 +02:00
.. deprecated:: 4.2
2017-10-02 11:38:31 +02:00
2022-03-27 16:06:09 +02:00
The ``doctest_setup`` function should not be used anymore to set up
2022-04-06 18:19:49 +02:00
:py:func:`~doctest.DocFileSuite`.
New modules should use :func:`~trytond.tests.tools.activate_modules`
instead.
2017-10-02 11:38:31 +02:00
.. function:: doctest_teardown()
2022-03-27 16:06:09 +02:00
Clean up after the run of the doctest_ by dropping the database.
It should be used as ``tearDown`` parameter when creating a
``DocFileSuite``.
2017-10-02 11:38:31 +02:00
.. attribute:: doctest_checker
2022-03-27 16:06:09 +02:00
A specialized doctest checker to ensure the Python compatibility.
2017-10-02 11:38:31 +02:00
2022-04-25 18:11:21 +02:00
.. function:: load_doc_tests(name, path, loader, tests, pattern)
An helper that follows the ``load_tests`` protocol to load as
:py:class:`~doctest.DocTest` all ``*.rst`` files in ``directory``,
with the module ``name`` and the ``path`` to the module file from which the
doc tests are registered.
2023-07-29 15:11:05 +02:00
If a file with the same name but the extension ``.json`` exists, the test is
registered for each globals defined in the JSON list.
2022-04-25 18:11:21 +02:00
2017-10-02 11:38:31 +02:00
.. function:: suite()
2022-03-27 16:06:09 +02:00
A function returning a subclass of ``unittest.TestSuite`` that drops the
database if it does not exist prior to the run of the tests.
.. _doctest: https://docs.python.org/library/doctest.html
2017-10-02 11:38:31 +02:00
.. module:: trytond.tests.tools
2022-03-27 16:06:09 +02:00
Tools
-----
2017-10-02 11:38:31 +02:00
.. function:: activate_modules(modules)
2022-03-27 16:06:09 +02:00
Activate a list of ``modules`` for scenario based on proteus doctests.
2017-10-02 11:38:31 +02:00
.. function:: set_user(user, config)
2022-03-27 16:06:09 +02:00
Set the user of the ``config`` proteus connection to ``user``.