django_expanded_test_cases.mixins package

Submodules

django_expanded_test_cases.mixins.core_mixin module

Core testing logic, universal to all test cases.

class django_expanded_test_cases.mixins.core_mixin.CoreTestCaseMixin

Bases: BaseMixin

Core testing logic, used in all other expanded TestCase classes.

For compatibility, does not inherit from

django.test.TestCase channels.testing.ChannelsLiveServerTestCase

Inheriting from either (seems to) make it incompatible with the other. Therefore we treat this as a separate mixin that inherits from nothing, and is included in all.

add_user_group(user_group, user=None)

Adds Group to given user.

Parameters:
  • user_group – Group to add.

  • user – User to add Group to. If not provided, defaults to test_user model.

Returns:

Updated user object.

add_user_permission(user_permission, user=None)

Adds Permission to given user.

Parameters:
  • user_permission – Permission to add.

  • user – User to add Permission to. If not provided, defaults to test_user model.

Returns:

Updated user object.

assertText(expected_text, actual_text, compare_index=None, strip=True)

Wrapper for assertEqual(), that prints full values to console on mismatch.

Parameters:
  • expected_text – Expected text value to check against.

  • actual_text – Actual text value to compare.

  • strip – Bool indicating if outer whitespace should be stripped. Defaults to True.

assertTextEndsWith(expected_text, actual_text, strip=True)

Modified wrapper for assertEqual(), that prints full values to console on mismatch.

Considered a pass if entire string of “expected_text” is at the beginning of “actual_text” variable.

assertTextStartsWith(expected_text, actual_text, strip=True)

Modiefied wrapper for assertEqual(), that prints full values to console on mismatch.

Considered a pass if entire string of “expected_text” is at the beginning of “actual_text” variable.

generate_get_url(url=None, **kwargs)

Generates a full GET request url, passing in the provided args.

Note: Only kwargs are accepted, as this needs <key: value> pairs. Pairs are then written out to url, as query string values. :param url: Optional url value to use. If not provided, defaults to “self.url”, if set. :param kwargs: The set of <key: value> pairs to append to end of GET url string. :return: Full GET request url string.

get_user(user, password='password', extra_usergen_kwargs=None)

Returns user matching provided value.

Parameters:
  • user – User model, or corresponding user identifier, to use.

  • password – Password str to assign to user.

  • extra_usergen_kwargs – Optional extra kwargs to pass into the get_user_model().objects.create_user() function.

Returns:

User object

classmethod setUpClass(*args, debug_print=None, **kwargs)

Test logic setup run at the start of class creation.

Parameters:

debug_print – Optional bool that indicates if debug output should print to console. Param overrides setting value if both param and setting are set.

classmethod setUpTestData(*args, extra_usergen_kwargs=None, **kwargs)

Test logic setup run at the start of class creation, specifically for data setup.

Parameters:

extra_usergen_kwargs – Optional extra kwargs to pass into the get_user_model().objects.create_user() function.

property site_root_url
standardize_characters(value)

Standardizes various characters in provided str.

Helps make testing easier. As generally tests only care that the character exists, not so much how it’s written.

Ex: Brackets have multiple ways to be written, and this will “standardize” them to a literal bracket. Ex: Django form errors seem to auto-escape apostrophe (’) characters to the html code. Which isn’t intuitive. Ex: Django seems to like converting values the hex version, so we convert them back during testing.

Note: If passing the return into regex, further sanitation is required. $ and ^ characters will break regex.

Parameters:

value – Str value to standardize.

Returns:

Sanitized str.

standardize_letters(value)

Standardizes various letter-based characters in provided str.

Helps make testing easier. As generally tests only care that the character exists, not so much how it’s written. :param value: Str value to standardize. :return: Sanitized str.

standardize_newlines(value)

Standardizes newline instances in provided variable.

Will reduce possible newline character types to the

character.

Also, whitespace between newlines is removed, and outer newlines/whitespace is removed.

Note: Handles similar to standardize_whitespace(), except that newlines are preserved.

param value:

Str value to standardize.

return:

Sanitized str.

standardize_numbers(value)

Standardizes various number-based characters in provided str.

Helps make testing easier. As generally tests only care that the character exists, not so much how it’s written. :param value: Str value to standardize. :return: Sanitized str.

standardize_symbols(value)

Standardizes various symbol-based characters in provided str.

Helps make testing easier. As generally tests only care that the character exists, not so much how it’s written. :param value: Str value to standardize. :return: Sanitized str.

standardize_whitespace(value)

Standardizes whitespace in provided variable.

When possible, all whitespace and whitespace-esque characters (including newlines) are reduced down to a single space.

Note: Handles similar to standardize_newlines(), except that all newlines are removed.

Parameters:

value – Str value to standardize.

Returns:

Sanitized str.

subTest(*args, **kwargs)

Test logic setup run every time we enter a subtest.

django_expanded_test_cases.mixins.live_server_mixin module

django_expanded_test_cases.mixins.response_mixin module

Module contents