django_sorcery.testing module

Testing utilities.

exception django_sorcery.testing.CommitException[source]

Bases: BaseException

Raised when a commit happens during testing.

class django_sorcery.testing.Transact[source]

Bases: object

Helper context manager for handling transactions during tests. Perfect for testing a single unit of work.

For testing sqlalchemy apps the common pattern is to usually, start a transaction or savepoint, run the tests and once the test is done rollback. Additionally it also prevents commits to the database so that every test gets the same database state.

end()[source]

Rolls back transaction and removes session.

hook()[source]

Hooks commit events to prevent commits.

start()[source]

Starts transaction management and hooks commit events.

stop()[source]

Stops transaction management, rolls back transactions and unhooks commit events.

unhook()[source]

Unhooks commit events.