Horizon TestCase Classes

Horizon provides several useful base classes for testing both views and API functions.

class horizon.test.TestCase(methodName='runTest')[source]

Specialized base test case class for Horizon which gives access to numerous additional features:

  • A full suite of test data through various attached objects and managers (e.g. self.servers, self.user, etc.). See the docs for TestData for more information.
  • The mox mocking framework via self.mox.
  • A set of request context data via self.context.
  • A RequestFactory class which supports Django’s contrib.messages framework via self.factory.
  • A ready-to-go request object via self.request.
  • The ability to override specific time data controls for easier testing.
  • Several handy additional assertion methods.
assertFormErrors(response, count=0, message=None, context_name='form')[source]

Asserts that the response does contain a form in it’s context, and that form has errors, if count were given, it must match the exact numbers of errors

assertMessageCount(response=None, **kwargs)[source]

Asserts that the specified number of messages have been attached for various message types. Usage would look like self.assertMessageCount(success=1).

assertNoFormErrors(response, context_name='form')[source]

Asserts that the response either does not contain a form in it’s context, or that if it does, that form has no errors.

assertNoMessages(response=None)[source]

Asserts that no messages have been attached by the contrib.messages framework.

assertRedirectsNoFollow(response, expected_url)[source]

Asserts that the given response issued a 302 redirect without processing the view which is redirected to.

override_times()[source]

Overrides the “current” time with immutable values.

reset_times()[source]

Undoes the changes made by override_times.

class horizon.test.APITestCase(methodName='runTest')[source]

The APITestCase class is for use with tests which deal with the underlying clients rather than stubbing out the horizon.api.* methods.

class horizon.test.BaseAdminViewTests(methodName='runTest')[source]

A TestCase subclass which sets an active user with the “admin” role for testing admin-only views and functionality.

Previous topic

Horizon Exceptions

Next topic

Source Code Index

This Page