Newer
Older
class CheckRelateCustomPageTypesRemovedDeadline(CheckRelateSettingsBase):
msg_id_prefix = "relate_custom_page_types_removed_deadline"
VALID_CONF = datetime(2017, 12, 31, 0, 0)
INVALID_CONF = "2017-12-31 00:00"
@override_settings(RELATE_CUSTOM_PAGE_TYPES_REMOVED_DEADLINE=None)
def test_valid_conf_none(self):
self.assertCheckMessages([])
@override_settings(RELATE_CUSTOM_PAGE_TYPES_REMOVED_DEADLINE=VALID_CONF)
def test_valid_conf(self):
self.assertCheckMessages([])
@override_settings(RELATE_CUSTOM_PAGE_TYPES_REMOVED_DEADLINE=INVALID_CONF)
def test_invalid_conf(self):
self.assertCheckMessages(
["relate_custom_page_types_removed_deadline.E001"])
class CheckRelateDisableCodehiliteMarkdownExtensions(CheckRelateSettingsBase):
msg_id_prefix = "relate_disable_codehilite_markdown_extension"
VALID_CONF = None
VALID_CONF_NO_WARNING = True
WARNING_CONF_NOT_BOOL1 = "some string"
WARNING_CONF_NOT_BOOL2 = ["markdown.extensions.codehilite"]
WARNING_CONF_FALSE = False
@override_settings(RELATE_DISABLE_CODEHILITE_MARKDOWN_EXTENSION=VALID_CONF)
def test_valid_conf(self):
@override_settings(
RELATE_DISABLE_CODEHILITE_MARKDOWN_EXTENSION=VALID_CONF_NO_WARNING)
def test_valid_conf_no_warning(self):
@override_settings(
RELATE_DISABLE_CODEHILITE_MARKDOWN_EXTENSION=WARNING_CONF_NOT_BOOL1)
def test_warning_conf_not_bool1(self):
self.assertCheckMessages(
["relate_disable_codehilite_markdown_extension.W001"])
@override_settings(
RELATE_DISABLE_CODEHILITE_MARKDOWN_EXTENSION=WARNING_CONF_NOT_BOOL2)
def test_warning_conf_not_bool2(self):
self.assertCheckMessages(
["relate_disable_codehilite_markdown_extension.W001"])
@override_settings(
RELATE_DISABLE_CODEHILITE_MARKDOWN_EXTENSION=WARNING_CONF_FALSE)
def test_warning_conf_false(self):
self.assertCheckMessages(
["relate_disable_codehilite_markdown_extension.W002"])
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
class RelateStartupChecksExtraCheckTest(CheckRelateSettingsBase):
msg_id_prefix = "my_custom_check_msg"
INSTANCE_WRONG1 = "tests.resouce.my_check_func"
INSTANCE_WRONG2 = {"path": "tests.resouce.my_check_func"}
@override_settings()
def test_not_configured(self):
del settings.RELATE_STARTUP_CHECKS_EXTRA
register_startup_checks_extra()
@override_settings(RELATE_STARTUP_CHECKS_EXTRA=None)
def test_none(self):
register_startup_checks_extra()
@override_settings(RELATE_STARTUP_CHECKS_EXTRA=INSTANCE_WRONG1)
def test_instance_error1(self):
with self.assertRaises(ImproperlyConfigured) as cm:
register_startup_checks_extra()
expected_error_msg = (
"RELATE_STARTUP_CHECKS_EXTRA must be an instance of list or tuple")
self.assertIn(expected_error_msg, str(cm.exception))
@override_settings(RELATE_STARTUP_CHECKS_EXTRA=INSTANCE_WRONG2)
def test_instance_error2(self):
with self.assertRaises(ImproperlyConfigured) as cm:
register_startup_checks_extra()
expected_error_msg = (
"RELATE_STARTUP_CHECKS_EXTRA must be an instance of list or tuple")
self.assertIn(expected_error_msg, str(cm.exception))
@override_settings(RELATE_STARTUP_CHECKS_EXTRA=[])
def test_empty_list(self):
register_startup_checks_extra()
@override_settings(RELATE_STARTUP_CHECKS_EXTRA=[
"unknown_package.unknown_module.func"])
def test_not_importable_check_func(self):
with self.assertRaises(ImproperlyConfigured) as cm:
register_startup_checks_extra()
expected_error_msg = ("No module named 'unknown_package'")
self.assertIn(expected_error_msg, str(cm.exception))
@override_settings(RELATE_STARTUP_CHECKS_EXTRA=[
"tests.resource.my_custom_check_func1",
"tests.resource.my_custom_check_func2"])
def test_do_check(self):
from tests.utils import mock
with mock.patch("relate.checks.register") as mock_register:
register_startup_checks_extra()
self.assertEqual(mock_register.call_count, 2)
stringified_call_args = ". ".join(
[repr(call) for call in mock_register.call_args_list])
self.assertIn(
"function my_custom_check_func1", stringified_call_args)
self.assertIn(
"function my_custom_check_func2", stringified_call_args)