Onegov Testing API

Fixtures

onegov_testing.fixtures.treat_sqlalchemy_warnings_as_errors()[source]

All onegov models treat SQLAlchemy warnings as errors, because usually SQLAlchemy warnings are errors waiting to happen.

onegov_testing.fixtures.cache_password_hashing(monkeysession)[source]

Monkey-patch the password hashing/verification functions during tests for a big speed increase (we login with the same password over and over again).

Changes to the auth are delicate, so we make sure this is only done during testing by having it here, instead of support some mechanism like this in onegov.core itself.

So this dangerous code is not only inexistant in the core, it is also not present on the server because onegov_testing is strictly a testing dependency and finally it is only run when invoked through pytest.

onegov_testing.fixtures.postgres(pg_preferred_versions)[source]

Starts a postgres server using testing.postgresql once per test session.

onegov_testing.fixtures.postgres_dsn(postgres)[source]

Returns a dsn to a temporary postgres server. Cleans up the database after running the tests.

onegov_testing.fixtures.session_manager(postgres_dsn)[source]

Provides a onegov.core.orm.session_manager.SessionManager setup with postgres_dsn().

onegov_testing.fixtures.session(session_manager)[source]

Provides an SQLAlchemy session, scoped to a random schema.

This is the fixture you usually want to use for ORM tests.

onegov_testing.fixtures.temporary_directory()[source]

Provides a temporary directory that is removed after the test.

onegov_testing.fixtures.temporary_path(temporary_directory)[source]

Same as temporary_directory(), but providing a Path instead of a string.

onegov_testing.fixtures.es_url(es_process)[source]

Provides an url to an elasticsearch cluster that is guaranteed to be empty at the beginning of each test.

onegov_testing.fixtures.es_client(es_url)[source]

Provides an elasticsearch client.

Utils

onegov_testing.utils.create_image(width=50, height=50, output=None)[source]

Generates a test image and returns it’s file handle.

onegov_testing.utils.random_namespace()[source]

Returns a random namespace.