Welcome to Destral documentation!

Release v0.20.1

Contents:

Destral testing library

A library to do tests with our OpenERP Server (v5)

https://travis-ci.org/gisce/destral.svg?branch=master

Note

The API is not stable, and can be changed.

Code as if the next guy to maintain your code is a homicidal maniac who knows where you live.

—Kathy Sierra and Bert Bates

Running tests

To run your tests call destral from the command line. Options to the destral command are:

Usage: destral [OPTIONS]

  Options:
    --enable-coverage
    --report-coverage
    --dropdb/no-dropdb
    --requirements/no-requirements
    -m, --modules TEXT
    -t, --tests TEXT
    --help              Show this message and exit.

where -m are the modules to be tested and -t the tests to run. For the -t parameter is needed to pass full test class and method. Eg: SomeTestClass.test_method

If no specific tests are defined into the module, destral will test:

  • Correct installation of the module.
  • All the views defined in the module are ok.
  • Definition of access rules for all the models of the module

If you have run with the –enable-coverage option a .coverage file will be generated with the results and you can see the report executing:

$ coverage report

If your want to reuse the database you can use –no-dropdb and this will keep the database after running all the tests. Then you can make destral use this database exporting the environment variable OPENERP_DB_NAME=database_name

If you are running the destral in local environment with all the requirements installed and you want to speed up the tests you can use the option –no-requirements to skip the requirements installation.

Configuring destral

All the configuration can be made with environment variables with prefix DESTRAL_

Variables definition

DESTRAL_MODULE:
Module to test
DESTRAL_USE_TEMPLATE:
If we want to use a template when creating a database for test, if this variable is set to True a database with name base must exists and will be used to create a temporally database for this test.

Configuring OpenERP

All configuration for OpenERP server can be made with environment variables with prefix OPENERP_ and will overwrite the defaults in tools.config.

Useful variables

OPENERP_DB_NAME:
A database to use, if this is set then the test framework assumes that the module is already installed and this database will not be deleted after the tests.
OPENERP_UPDATE:
If you want to update some modules during the initialization of OpenERP service Eg value: OPENERP_UPDATE={‘base’: 1, ‘crm’: 1}

Note

When developing is useful to have a database initialized and use OPENERP_DB_NAME variable to speed up the test.

API

destral.openerp

destral.openerp.DEFAULT_USER = 1

Default user id

class destral.openerp.OpenERPService(**kwargs)[source]

OpenERP Service.

create_database(template=True)[source]

Creates a new database.

Parameters:template – use a template (name must be base) (default True)
db_name

Database name.

drop_database()[source]

Drop database from self.db_name

install_module(module)[source]

Installs a module

Parameters:module – Module to install
destral.openerp.patched_pool_jobs(*args, **kwargs)[source]

Patch pool jobs

destral.patch

class destral.patch.PatchNewCursors[source]

Util to patch creation of new cursor.

This will always return the cursor created by Transaction

class destral.patch.PatchedConnection(connection, cursor)[source]

Patched connection wapper to return the same cursor.

This is useful when some method inside a testing mehtod creates new cursors.

Parameters:
  • connection – Original connection
  • cursor – Original cursor
cursor(serialized=False)[source]

Wrapped function to return the same cursor

destral.testing

class destral.testing.OOTestCase(methodName='runTest')[source]

Base class to inherit test cases from for OpenERP Testing Framework.

database

Database used in the test.

require_demo_data = False

Require demo data to run the tests.

destral.testing.get_spec_suite(module)[source]

Get spec suite to run Mamba :param module: Module to get the spec suite :return: suite

destral.testing.get_unittest_suite(module, tests=None)[source]

Get the unittest suit for a module

destral.testing.run_spec_suite(suite)[source]

Run Spec suite :param suite: mamba Runner :return:

destral.testing.run_unittest_suite(suite)[source]

Run test suite

destral.transaction

class destral.transaction.Singleton(mcs, name, bases, dict_)[source]

Metaclass for singleton pattern.

Copyright:Tryton Project
class destral.transaction.Transaction[source]

Transaction object

get_context()[source]

Loads the context of the current user

start(database_name, user=1, context=None)[source]

Start a new transaction

Parameters:
  • database_name – Database name
  • user – User id
  • context – Context to be used
stop()[source]

Stop the transaction.

destral.utils

destral.utils.update_config(config, **kwargs)[source]

Updates config dictionary from keyword arguments.

destral.utils.detect_module(path)[source]

Detect if a path is part of a openerp module or not

Parameters:path – to examine
Returns:None if is not a module or the module name
destral.utils.module_exists(module)[source]

Check if a python module exists.

This is used to check if a module have its own tests defined, Eg: addons.module_name.tests

Parameters:module – Module name to check
Returns:True if exists or False if not
destral.utils.get_dependencies(module, addons_path=None, deps=None)[source]

Get all the dependencies of a module without database

Using __terp__.py files and is used to check requirements.txt in the dependencies.

Parameters:
  • module – Module to find the dependencies
  • addons_path – Path to find the modules
Returns:

a listt of dependencies.

destral.utils.find_files(diff)[source]

Return all the files implicated in a diff

destral.utils.install_requirements(module, addons_path)[source]

Install module requirements and its dependecies

destral.cover

Indices and tables