1.22. testing

This module provides supporting functionality for the included application unit tests.

1.22.1. Data

TEST_MESSAGE_TEMPLATE[source]

A string representing a message template that can be used for testing.

TEST_MESSAGE_TEMPLATE_INLINE_IMAGE[source]

A string with the path to a file used as an inline image in the TEST_MESSAGE_TEMPLATE.

1.22.2. Classes

class KingPhisherTestCase(*args, **kwargs)[source]

Bases: smoke_zephyr.utilities.TestCase

This class provides additional functionality over the built in unittest.TestCase object, including better compatibility for methods across Python 2.x and Python 3.x.

assertHasAttribute(obj, attribute, msg=None)[source]

Test that obj has the named attribute.

assertIsEmpty(obj, msg=None)[source]

Test that obj is empty as determined by len().

assertIsNotEmpty(obj, msg=None)[source]

Test that obj is not empty as determined by len().

assertIsSubclass(obj, cls, msg=None)[source]

Test that obj is a subclass of cls (which can be a class or a tuple of classes as supported by issubclass()).

class KingPhisherServerTestCase(*args, **kwargs)[source]

Bases: king_phisher.testing.KingPhisherTestCase

This class can be inherited to automatically set up a King Phisher server instance configured in a way to be suitable for testing purposes.

assertHTTPStatus(http_response, status)[source]

Check an HTTP response to ensure that the correct HTTP status code is specified.

Parameters:
  • http_response (httplib.HTTPResponse) – The response object to check.
  • status (int) – The status to check for.
assertRPCPermissionDenied(method, *args, **kwargs)[source]

Assert that the specified RPC method fails with a KingPhisherPermissionError exception.

Parameters:method – The RPC method that is to be tested
http_request(resource, method='GET', include_id=True, body=None, headers=None)[source]

Make an HTTP request to the specified resource on the test server.

Parameters:
  • resource (str) – The resource to send the request to.
  • method (str) – The HTTP method to use for the request.
  • include_id (bool) – Whether to include the the id parameter.
  • body (dict, str) – The data to include in the body of the request.
  • headers (dict) – The headers to include in the request.
Returns:

The servers HTTP response.

Return type:

httplib.HTTPResponse

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

web_root_files(limit=None, include_templates=True)[source]

A generator object that yields valid files which are contained in the web root of the test server instance. This can be used to find resources which the server should process as files. The function will fail if no files can be found in the web root.

Parameters:
  • limit (int) – A limit to the number of files to return.
  • include_templates (bool) – Whether or not to include files that might be templates.