Utils
This package contains tests for the integreat_cms.cms.utils
package.
Test Cancel Translation
Test Content Utils
Test Disable Hix Post Save Signal
Test External Calendar Utils
Test Internal Link Checker
- tests.cms.utils.test_internal_link_checker.prepage_url(link: str, trailing_slash: bool) Url [source]
Make sure a link either has or doesn’t have a trailing slash
- tests.cms.utils.test_internal_link_checker.test_check_internal_invalid(load_test_data: None, link: str, trailing_slash: bool) None [source]
Check whether the given internal URL is correctly identified as invalid link
- Parameters:
load_test_data (None) – The fixture providing the test data (see
load_test_data()
)link (str) – The URL to check
trailing_slash (bool) – Whether to ensure the trailing slash
- Return type:
None
- tests.cms.utils.test_internal_link_checker.test_check_internal_skipped(load_test_data: None, link: str, trailing_slash: bool) None [source]
Check whether the given internal URL is correctly skipped
- Parameters:
load_test_data (None) – The fixture providing the test data (see
load_test_data()
)link (str) – The URL to check
trailing_slash (bool) – Whether to ensure the trailing slash
- Return type:
None
- tests.cms.utils.test_internal_link_checker.test_check_internal_valid(load_test_data: None, link: str, trailing_slash: bool) None [source]
Check whether the given internal URL is correctly identified as valid link
- Parameters:
load_test_data (None) – The fixture providing the test data (see
load_test_data()
)link (str) – The URL to check
trailing_slash (bool) – Whether to ensure the trailing slash
- Return type:
None
Test Repair Tree
Test repair tree util
Test execution order:
Since there seem to be some weird side effects happening
for unrelated tests when testing database consistency, we first run those,
then the tests that make sure the repair_tree()
is effective,
and last the effectiveness of tree_mutex()
itself.
This ordering is facilitated using pytest_order
to specify the tests to run "last"
(eqivalent to -1
, absolute ordering)
and after certain other tests (relative ordering).
See https://pytest-order.readthedocs.io/en/stable/usage.html#order-relative-to-other-tests
- tests.cms.utils.test_repair_tree.test_repair_tree(load_test_data_transactional: None) None [source]
Create a broken tree of 3 nodes and assert that
repair_tree()
correctly fixes it.- Parameters:
load_test_data_transactional (None)
- Return type:
None
- tests.cms.utils.test_repair_tree.test_repair_tree_complex(load_test_data_transactional: None) None [source]
Recreate a real-world example of a broken tree and assert that
repair_tree()
correctly fixes it.- Parameters:
load_test_data_transactional (None)
- Return type:
None
Test Rounded Hix Value
Test Slug Utils
- tests.cms.utils.test_slug_utils.test_generate_unique_slug_fallback(settings: SettingsWrapper, load_test_data: None) None [source]
Test whether the
generate_unique_slug_helper()
function correctly uses the fallback property when no slug is provided- Parameters:
settings (SettingsWrapper)
load_test_data (None)
- Return type:
None
- tests.cms.utils.test_slug_utils.test_generate_unique_slug_no_fallback() None [source]
Test whether the
generate_unique_slug_helper()
throws adjango.core.exceptions.ValidationError
, while the fallback property does not exist- Return type:
None
- tests.cms.utils.test_slug_utils.test_generate_unique_slug_reserved_page_slug(settings: SettingsWrapper, load_test_data: None) None [source]
Test whether the
generate_unique_slug_helper()
function function returns the correct unique slug when the new page slug is a reserved slug- Parameters:
settings (SettingsWrapper)
load_test_data (None)
- Return type:
None
- tests.cms.utils.test_slug_utils.test_generate_unique_slug_reserved_region_slug(settings: SettingsWrapper, load_test_data: None) None [source]
Test whether the
generate_unique_slug_helper()
function returns the correct unique slug when the new region slug is a reserved slug- Parameters:
settings (SettingsWrapper)
load_test_data (None)
- Return type:
None
Test Translation Utils
- tests.cms.utils.test_translation_utils.test_translate_link() None [source]
Test whether the
translate_link()
function correctly escapes message text while preserving the link tags- Return type:
None
Test Tree Mutex
Test tree mutex for page tree
Test execution order:
Since there seem to be some weird side effects happening
for unrelated tests when testing database consistency, we first run those,
then the tests that make sure the repair_tree()
is effective,
and last the effectiveness of tree_mutex()
itself.
This ordering is facilitated using pytest_order
to specify the tests to run "last"
(eqivalent to -1
, absolute ordering)
and after certain other tests (relative ordering).
See https://pytest-order.readthedocs.io/en/stable/usage.html#order-relative-to-other-tests
- tests.cms.utils.test_tree_mutex.back(contestant_id: int) None [source]
Gets the page with id
contestant_id
and the target page with id20
and moves the contestant out as the right sibling of the target.- Parameters:
contestant_id (int)
- Return type:
None
- tests.cms.utils.test_tree_mutex.five_ten_five(contestant_id: int, use_mutex: bool, handle_exception: Callable | None = None) None [source]
Move a “contestant” page back and forth repeatedly. Exceptions are caught and handed to
handle_exception
, this is necessary to get them back out to the main thread.use_mutex
dictates whether to usemforth()
/mback()
orforth()
/back()
.
- tests.cms.utils.test_tree_mutex.forth(contestant_id: int) None [source]
Gets the page with id
contestant_id
and the target page with id20
and moves the contestant in as the last child of the target.- Parameters:
contestant_id (int)
- Return type:
None
- tests.cms.utils.test_tree_mutex.mback(contestant_id: int) None [source]
Only calls
back()
, but decorated withtree_mutex()
.- Parameters:
contestant_id (int)
- Return type:
None
- tests.cms.utils.test_tree_mutex.mforth(contestant_id: int) None [source]
Only calls
forth()
, but decorated withtree_mutex()
.- Parameters:
contestant_id (int)
- Return type:
None
- tests.cms.utils.test_tree_mutex.run_mutex_test(use_mutex: bool) None [source]
Start two
five_ten_five()
tests in parallel, in separate threads. These each constantly move their “contestant” page back and forth. TreeBeard seems to quickly run into inconsistencies, as their code bypasses Djangos Object-Relationional Mapper (ORM), directly running raw SQL commands, without database transactions.- Parameters:
use_mutex (bool)
- Return type:
None
- tests.cms.utils.test_tree_mutex.test_rule_out_false_positive(load_test_data_transactional: None) None [source]
Rule out that
tree_mutex()
is just doing nothing andtest_tree_mutex()
only succeeded because the system magically worked without it. Provoke and expect a variety of possible exceptions usingrun_mutex_test()
.If this test fails with an exception not expected and you can prove that it is indicative of treebeard shooting itself in the foot, please add the exception as expected!
- Parameters:
load_test_data_transactional (None)
- Return type:
None
- tests.cms.utils.test_tree_mutex.test_tree_mutex(load_test_data_transactional: None) None [source]
Check whether
tree_mutex()
is actually preventing collisions. Seerun_mutex_test()
for details.- Parameters:
load_test_data_transactional (None)
- Return type:
None