class documentation

class SimpleTestCase(unittest.TestCase):

Known subclasses: django.test.testcases.TransactionTestCase

View In Hierarchy

Undocumented

Class Method set​Up​Class Undocumented
Class Method ​_add​_databases​_failures Undocumented
Class Method ​_remove​_databases​_failures Undocumented
Class Method ​_validate​_databases Undocumented
Method __call__ Wrapper around default __call__ method to perform common Django test set up. This means that user-defined Test Cases aren't required to include a call to super().setUp().
Method ​_assert​_contains Undocumented
Method ​_assert​_raises​_or​_warns​_cm Undocumented
Method ​_assert​_template​_used Undocumented
Method _assert​Foo​Message Undocumented
Method ​_post​_teardown Perform post-test things.
Method ​_pre​_setup Perform pre-test setup: * Create a test client. * Clear the mail test outbox.
Method ​_setup​_and​_call Perform the following in order: pre-setup, run test, post-teardown, skipping pre/post hooks if test is set to be skipped.
Method assert​Contains No summary
Method assert​Field​Output Assert that a form field behaves correctly with various inputs.
Method assert​Form​Error Assert that a form used to render the response has a specific field error.
Method assert​Formset​Error Assert that a formset used to render the response has a specific error.
Method assert​HTMLEqual Assert that two HTML snippets are semantically the same. Whitespace in most cases is ignored, and attribute ordering is not significant. The arguments must be valid HTML.
Method assert​HTMLNot​Equal Assert that two HTML snippets are not semantically equivalent.
Method assert​In​HTML Undocumented
Method assert​JSONEqual Assert that the JSON fragments raw and expected_data are equal. Usual JSON non-significant whitespace rules apply as the heavyweight is delegated to the json library.
Method assert​JSONNot​Equal Assert that the JSON fragments raw and expected_data are not equal. Usual JSON non-significant whitespace rules apply as the heavyweight is delegated to the json library.
Method assert​No​Logs Assert no messages are logged on the logger, with at least the given level.
Method assert​Not​Contains Assert that a response indicates that some content was retrieved successfully, (i.e., the HTTP status code was as expected) and that text doesn't occur in the content of the response.
Method assert​Raises​Message Assert that expected_message is found in the message of a raised exception.
Method assert​Redirects Assert that a response redirected to a specific URL and that the redirect URL can be loaded.
Method assert​Template​Not​Used Assert that the template with the provided name was NOT used in rendering the response. Also usable as context manager.
Method assert​Template​Used Assert that the template with the provided name was used in rendering the response. Also usable as context manager.
Method assert​URLEqual Assert that two URLs are the same, ignoring the order of query string parameters except for parameters with the same name.
Method assert​Warns​Message Same as assertRaisesMessage but for assertWarns() instead of assertRaises().
Method assert​XMLEqual Assert that two XML snippets are semantically the same. Whitespace in most cases is ignored and attribute ordering is not significant. The arguments must be valid XML.
Method assert​XMLNot​Equal Assert that two XML snippets are not semantically equivalent. Whitespace in most cases is ignored and attribute ordering is not significant. The arguments must be valid XML.
Method debug Perform the same as __call__(), without catching the exception.
Method modify​_settings A context manager that temporarily applies changes a list setting and reverts back to the original value when exiting the context.
Method settings A context manager that temporarily sets a setting and reverts to the original value when exiting the context.
Class Variable ​_disallowed​_connection​_methods Undocumented
Class Variable ​_disallowed​_database​_msg Undocumented
Class Variable ​_modified​_settings Undocumented
Class Variable ​_overridden​_settings Undocumented
Class Variable databases Undocumented
Instance Variable async​_client Undocumented
Instance Variable client Undocumented
@classmethod
def setUpClass(cls):
@classmethod
def _add_databases_failures(cls):

Undocumented

@classmethod
def _remove_databases_failures(cls):

Undocumented

@classmethod
def _validate_databases(cls):

Undocumented

def __call__(self, result=None):
Wrapper around default __call__ method to perform common Django test set up. This means that user-defined Test Cases aren't required to include a call to super().setUp().
def _assert_contains(self, response, text, status_code, msg_prefix, html):

Undocumented

@contextmanager
def _assert_raises_or_warns_cm(self, func, cm_attr, expected_exception, expected_message):

Undocumented

def _assert_template_used(self, response, template_name, msg_prefix):

Undocumented

def _assertFooMessage(self, func, cm_attr, expected_exception, expected_message, *args, **kwargs):

Undocumented

def _post_teardown(self):
Perform post-test things.
def _pre_setup(self):
Perform pre-test setup: * Create a test client. * Clear the mail test outbox.
def _setup_and_call(self, result, debug=False):

Perform the following in order: pre-setup, run test, post-teardown, skipping pre/post hooks if test is set to be skipped.

If debug=True, reraise any errors in setup and use super().debug() instead of __call__() to run the test.

def assertContains(self, response, text, count=None, status_code=200, msg_prefix='', html=False):
Assert that a response indicates that some content was retrieved successfully, (i.e., the HTTP status code was as expected) and that text occurs count times in the content of the response. If count is None, the count doesn't matter - the assertion is true if the text occurs at least once in the response.
def assertFieldOutput(self, fieldclass, valid, invalid, field_args=None, field_kwargs=None, empty_value=''):

Assert that a form field behaves correctly with various inputs.

Args:

fieldclass: the class of the field to be tested. valid: a dictionary mapping valid inputs to their expected

cleaned values.
invalid: a dictionary mapping invalid inputs to one or more
raised error messages.

field_args: the args passed to instantiate the field field_kwargs: the kwargs passed to instantiate the field empty_value: the expected clean output for inputs in empty_values

def assertFormError(self, response, form, field, errors, msg_prefix=''):
Assert that a form used to render the response has a specific field error.
def assertFormsetError(self, response, formset, form_index, field, errors, msg_prefix=''):

Assert that a formset used to render the response has a specific error.

For field errors, specify the form_index and the field. For non-field errors, specify the form_index and the field as None. For non-form errors, specify form_index as None and the field as None.

def assertHTMLEqual(self, html1, html2, msg=None):
Assert that two HTML snippets are semantically the same. Whitespace in most cases is ignored, and attribute ordering is not significant. The arguments must be valid HTML.
def assertHTMLNotEqual(self, html1, html2, msg=None):
Assert that two HTML snippets are not semantically equivalent.
def assertInHTML(self, needle, haystack, count=None, msg_prefix=''):

Undocumented

def assertJSONEqual(self, raw, expected_data, msg=None):
Assert that the JSON fragments raw and expected_data are equal. Usual JSON non-significant whitespace rules apply as the heavyweight is delegated to the json library.
def assertJSONNotEqual(self, raw, expected_data, msg=None):
Assert that the JSON fragments raw and expected_data are not equal. Usual JSON non-significant whitespace rules apply as the heavyweight is delegated to the json library.
@contextmanager
def assertNoLogs(self, logger, level=None):
Assert no messages are logged on the logger, with at least the given level.
def assertNotContains(self, response, text, status_code=200, msg_prefix='', html=False):
Assert that a response indicates that some content was retrieved successfully, (i.e., the HTTP status code was as expected) and that text doesn't occur in the content of the response.
def assertRaisesMessage(self, expected_exception, expected_message, *args, **kwargs):

Assert that expected_message is found in the message of a raised exception.

Args:
expected_exception: Exception class expected to be raised. expected_message: expected error message string value. args: Function to be called and extra positional args. kwargs: Extra kwargs.
def assertRedirects(self, response, expected_url, status_code=302, target_status_code=200, msg_prefix='', fetch_redirect_response=True):

Assert that a response redirected to a specific URL and that the redirect URL can be loaded.

Won't work for external links since it uses the test client to do a request (use fetch_redirect_response=False to check such links without fetching them).

def assertTemplateNotUsed(self, response=None, template_name=None, msg_prefix=''):
Assert that the template with the provided name was NOT used in rendering the response. Also usable as context manager.
def assertTemplateUsed(self, response=None, template_name=None, msg_prefix='', count=None):
Assert that the template with the provided name was used in rendering the response. Also usable as context manager.
def assertURLEqual(self, url1, url2, msg_prefix=''):

Assert that two URLs are the same, ignoring the order of query string parameters except for parameters with the same name.

For example, /path/?x=1&y=2 is equal to /path/?y=2&x=1, but /path/?a=1&a=2 isn't equal to /path/?a=2&a=1.

def assertWarnsMessage(self, expected_warning, expected_message, *args, **kwargs):
Same as assertRaisesMessage but for assertWarns() instead of assertRaises().
def assertXMLEqual(self, xml1, xml2, msg=None):
Assert that two XML snippets are semantically the same. Whitespace in most cases is ignored and attribute ordering is not significant. The arguments must be valid XML.
def assertXMLNotEqual(self, xml1, xml2, msg=None):
Assert that two XML snippets are not semantically equivalent. Whitespace in most cases is ignored and attribute ordering is not significant. The arguments must be valid XML.
def debug(self):
Perform the same as __call__(), without catching the exception.
def modify_settings(self, **kwargs):
A context manager that temporarily applies changes a list setting and reverts back to the original value when exiting the context.
def settings(self, **kwargs):
A context manager that temporarily sets a setting and reverts to the original value when exiting the context.
_disallowed_connection_methods: list =

Undocumented

_disallowed_database_msg: str =

Undocumented

_modified_settings =

Undocumented

_overridden_settings =

Undocumented

databases: set =

Undocumented

async_client =

Undocumented

client =

Undocumented