Automated tests

Kotti uses pytest, zope.testbrowser and WebTest for automated testing.

Before you can run the tests, you must install Kotti’s ‘testing’ extras. Inside your Kotti checkout directory, do:

bin/python setup.py dev

To then run Kotti’s test suite, do:

bin/py.test

Using Kotti’s test fixtures/funcargs in third party add-ons’ tests

To be able to use all of Kotti’s fixtures and funcargs in your own package’s tests, you only need to “include” them with a line like this in your conftest.py file:

pytest_plugins = "kotti"

Available fixtures

Fixture dependencies

digraph kotti_fixtures { "allwarnings"; "app" -> "webtest"; "config" -> "db_session"; "config" -> "depot_tween"; "config" -> "dummy_request"; "config" -> "events"; "config" -> "workflow"; "connection" -> "content"; "connection" -> "db_session"; "content" -> "db_session"; "custom_settings" -> "connection"; "custom_settings" -> "unresolved_settings"; "db_session" -> "app"; "db_session" -> "browser"; "db_session" -> "filedepot"; "db_session" -> "root"; "depot_tween" -> "webtest"; "dummy_mailer" -> "app"; "dummy_mailer"; "dummy_request" -> "depot_tween"; "events" -> "app"; "depot_tween" -> "filedepot"; "depot_tween" -> "mock_filedepot"; "mock_filedepot"; "depot_tween" -> "no_filedepots"; "settings" -> "config"; "settings" -> "content"; "setup_app" -> "app"; "setup_app" -> "browser"; "unresolved_settings" -> "settings"; "unresolved_settings" -> "setup_app"; "workflow" -> "app"; }

class kotti.tests.TestStorage(**kwargs)[source]
get(file_or_id)[source]

Opens the file given by its unique id.

This operation is guaranteed to return a StoredFile instance or should raise IOError if the file is not found.

kotti.tests.browser(db_session, request, setup_app)[source]

returns an instance of zope.testbrowser. The kotti.testing.user pytest marker (or pytest.mark.user) can be used to pre-authenticate the browser with the given login name: @user(‘admin’).

kotti.tests.config(settings)[source]

returns a Pyramid Configurator object initialized with Kotti’s default (test) settings.

kotti.tests.connection(custom_settings)[source]

sets up a SQLAlchemy engine and returns a connection to the database. The connection string used for testing can be specified via the KOTTI_TEST_DB_STRING environment variable. The custom_settings fixture is needed to allow users to import their models easily instead of having to override the connection.

kotti.tests.content(connection, settings)[source]

sets up some default content using Kotti’s testing populator.

kotti.tests.custom_settings()[source]

This is a dummy fixture meant to be overriden in add on package’s conftest.py. It can be used to inject arbitrary settings for third party test suites. The default settings dictionary will be updated with the dictionary returned by this fixture.

This is also a good place to import your add on’s resources module to have the corresponding tables created during create_all() in kotti.tests.content().

Result:settings
Return type:dict
kotti.tests.db_session(config, content, connection)[source]

returns a db session object and sets up a db transaction savepoint, which will be rolled back after the test.

kotti.tests.depot_tween(config, dummy_request)[source]

Sets up the Depot tween and patches Depot’s set_middleware to suppress exceptions on subsequent calls. Yields the DepotManager.

kotti.tests.dummy_request(config, request, monkeypatch)[source]

returns a dummy request object after registering it as the currently active request. This is needed when pyramid.threadlocal.get_current_request is used.

kotti.tests.events(config)[source]

sets up Kotti’s default event handlers.

kotti.tests.filedepot(db_session, depot_tween)[source]

Configures a dbsession integrated mock depot store for depot.manager.DepotManager

kotti.tests.image_asset()[source]

Return an image file

kotti.tests.image_asset2()[source]

Return another image file

kotti.tests.mock_filedepot(depot_tween)[source]

Configures a mock depot store for depot.manager.DepotManager

This filedepot is not integrated with dbsession. Can be used in simple, standalone unit tests.

kotti.tests.no_filedepots(db_session, depot_tween)[source]

A filedepot fixture to empty and then restore DepotManager configuration

kotti.tests.root(db_session)[source]

returns Kotti’s ‘root’ node.

kotti.tests.workflow(config)[source]

loads and activates Kotti’s default workflow rules.

Continuous Integration

Kotti itself is tested against Python versions 2.6 and 2.7 as well as SQLite, mySQL and PostgreSQL (in every possible combination of those) on every commit (and pull request) via the excellent GitHub / Travis CI hook.

If you want your add-on packages’ to be tested the same way with additional testing against multiple versions of Kotti (including the current master), you can add a .travis.yml file to your repo that looks similar to this: https://raw.github.com/Kotti/kotti_media/master/.travis.yml.

The packages under http://kottipackages.xo7.de/ include all Kotti versions released on PyPI (synced every night at 00:15 CET) and a package built from the current master on GitHub (created every 15 minutes).