@@ -2222,6 +2222,31 @@ def _hook_function_warning_check(self, user, *args, **kwargs):
2222
2222
per-project, if needed.
2223
2223
"""
2224
2224
2225
+ should_raise_warning = self ._hook_function_warning_check_if_statement (user )
2226
+ if should_raise_warning :
2227
+ # No custom hooks have been implemented.
2228
+ # Check if any args or kwargs have been provided.
2229
+ if len (args ) > 0 or len (kwargs ) > 0 :
2230
+ # Either args or kwargs have been provided, which are exclusively meant for hook functions.
2231
+ # But no hook functions have been implemented.
2232
+ # Raise warning, as this is probably not an intended state.
2233
+ warn_msg = (
2234
+ "Supplemental args/kwargs have been provided to an assertResponse statement. "
2235
+ "Any supplemental args/kwargs are exclusively used to provide custom data to "
2236
+ "built-in hook functions, but no hook functions seem to be implemented for your project. "
2237
+ "Either remove the use of args/kwargs in the assertion, or implement one of the hook functions."
2238
+ )
2239
+ # Create console warning message.
2240
+ warnings .warn (warn_msg )
2241
+ # Create logging warning message.
2242
+ logging .warning (warn_msg )
2243
+
2244
+ def _hook_function_warning_check_if_statement (self , user ):
2245
+ """If statement to determine if hook functions should raise warning.
2246
+
2247
+ Separate function for maximum customizability per project.
2248
+ """
2249
+
2225
2250
# Django imports here to avoid situational "Apps aren't loaded yet" error.
2226
2251
from django .contrib .auth .models import AnonymousUser
2227
2252
@@ -2246,23 +2271,8 @@ def _hook_function_warning_check(self, user, *args, **kwargs):
2246
2271
):
2247
2272
should_raise_warning = True
2248
2273
2249
- if should_raise_warning :
2250
- # No custom hooks have been implemented.
2251
- # Check if any args or kwargs have been provided.
2252
- if len (args ) > 0 or len (kwargs ) > 0 :
2253
- # Either args or kwargs have been provided, which are exclusively meant for hook functions.
2254
- # But no hook functions have been implemented.
2255
- # Raise warning, as this is probably not an intended state.
2256
- warn_msg = (
2257
- "Supplemental args/kwargs have been provided to an assertResponse statement. "
2258
- "Any supplemental args/kwargs are exclusively used to provide custom data to "
2259
- "built-in hook functions, but no hook functions seem to be implemented for your project. "
2260
- "Either remove the use of args/kwargs in the assertion, or implement one of the hook functions."
2261
- )
2262
- # Create console warning message.
2263
- warnings .warn (warn_msg )
2264
- # Create logging warning message.
2265
- logging .warning (warn_msg )
2274
+ # Return calculated value.
2275
+ return should_raise_warning
2266
2276
2267
2277
# endregion Hook Functions
2268
2278
0 commit comments