
    Tid                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
mZ ddlmZmZmZmZ ddlmZ er	dd	lmZmZ n G d
 d      Z G d de      Z G d de
      Z G d de
      Z G d de
      Z ee d       G d de             Z ee d       G d de             Z ee d       G d de             Z ee d       G d de             Z ee d       G d de             Z ee d       G d d e             Zy!)"zv
Tests for django_cronjob_utils hooks integration.

Tests cover standard behavior, edge cases, and outlier scenarios.
    )date)skipIf)patch)TestCase)CronTaskExecutionResult)CronjobHookContextget_global_cronjob_hook_managerclear_cronjob_hooksHOOKS_AVAILABLE)CronExecution)HookTypeHookRejectionErrorc                       e Zd ZdZdZy)r   prepostN)__name__
__module____qualname__PREPOST     @/home/cursorai/projects/django-cronjob-utils/tests/test_hooks.pyr   r      s    r   r   c                         e Zd Zd fd	Z xZS )r   c                 V    || _         || _        |xs i | _        t        |   |       y N)
error_codemessagedetailssuper__init__)selfr   r   r    	__class__s       r   r"   zHookRejectionError.__init__   s)    (DO"DL"=bDLGW%r   r   )r   r   r   r"   __classcell__r$   s   @r   r   r      s    	& 	&r   r   c                   (    e Zd ZdZdZdZdedefdZy)TestTaskzTest task for hook tests.	test-taskT001r   returnc                     dddS )NFSuccess)errorr   r   r#   r   s     r   executezTestTask.execute+   s    955r   N	r   r   r   __doc__	task_name	task_coder   dictr0   r   r   r   r(   r(   %   s"    #II6D 6T 6r   r(   c                   (    e Zd ZdZdZdZdedefdZy)FailingTaskzTask that always fails.zfailing-taskT002r   r+   c                     ddddS )NTzTask failedFAIL)r.   r   r   r   r/   s     r   r0   zFailingTask.execute5   s    -vNNr   Nr1   r   r   r   r7   r7   /   s%    !IIOD OT Or   r7   c                   (    e Zd ZdZdZdZdedefdZy)ExceptionTaskzTask that raises exception.zexception-taskT003r   r+   c                     t        d      )NzTest exception
ValueErrorr/   s     r   r0   zExceptionTask.execute?   s    )**r   Nr1   r   r   r   r<   r<   9   s"    % II+D +T +r   r<   z"django-package-hooks not installedc                   @     e Zd ZdZd Z fdZd Zd Zd Zd Z	 xZ
S )HookContextCreationTestsz0Test CronjobHookContext creation and properties.c                 <    t        ddd      | _        t                yzSet up test fixtures.i        N)r   execution_dater   r#   s    r   setUpzHookContextCreationTests.setUpK   s    "4B/r   c                 6    t                t        | 	          yzClean up after test.Nr   r!   tearDownr#   r$   s    r   rM   z!HookContextCreationTests.tearDownP       r   c           
         t        ddd| j                  dddiddi	      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  | j                         | j                  |j
                  d       | j                  |j                  d   d       | j                  |j                  d   d       y
)z&Test creating context with all fields.r0   r)   r*   {   forceTcustomdata)	operationr3   r4   rG   execution_idoptionsmetadataN)r	   rG   assertEqualr3   r4   rV   rW   rX   r#   contexts     r   %test_context_creation_with_all_fieldsz>HookContextCreationTests.test_context_creation_with_all_fieldsU   s    $!..dO'
 	**K8**F3//1D1DE--s3148))(3V<r   c                    t        ddd| j                        }| j                  |j                  d       | j                  |j                  d       | j                  |j                  | j                         | j                  |j                         | j                  |j                  i        | j                  |j                  i        y)z3Test creating context with minimal required fields.r0   r)   r*   rU   r3   r4   rG   N)	r	   rG   rY   r3   r4   assertIsNonerV   rW   rX   rZ   s     r   test_context_creation_minimalz6HookContextCreationTests.test_context_creation_minimalh   s    $!..	
 	**K8**F3//1D1DE'../"-))2.r   c                     t        ddd| j                        }| j                  t              5  d|_        ddd       y# 1 sw Y   yxY w)z2Test that context is immutable (frozen dataclass).r0   r)   r*   r^   modifiedN)r	   rG   assertRaises	Exceptionr3   rZ   s     r   test_context_is_frozenz/HookContextCreationTests.test_context_is_frozenx   sB    $!..	
 y) *G *))s   A  A	c                     t        ddd| j                  i       }d|j                  d<   | j                  |j                  d   d       y)z:Test that metadata dict is mutable for hook communication.r0   r)   r*   )rU   r3   r4   rG   rX   	new_valuenew_keyN)r	   rG   rX   rY   rZ   s     r    test_context_metadata_is_mutablez9HookContextCreationTests.test_context_metadata_is_mutable   sN    $!..
 '2#)))4kBr   )r   r   r   r2   rI   rM   r\   r`   re   ri   r%   r&   s   @r   rB   rB   G   s%    :

=&/ 
+Cr   rB   c                   F     e Zd ZdZd Z fdZd Zd Zd Zd Z	d Z
 xZS )	PreHookStandardTestsz Test standard PRE hook behavior.c                     t        ddd      | _        t                t        j                  j                         j                          yrD   r   rG   r   r   objectsalldeleterH   s    r   rI   zPreHookStandardTests.setUp   4    "4B/!!#**,r   c                 6    t                t        | 	          yrK   rL   rN   s    r   rM   zPreHookStandardTests.tearDown   rO   r   c                 b    g  fd}t               }|j                  j                  dt        j                  |d       t         j                        }|j                         } j                          j                  |j                          j                  |j                  d       y)z$Test PRE hook that allows execution.c                 ^    j                  d       j                  | j                         y NT)appendr_   rV   )r[   hook_calledr#   s    r   
allow_hookzGPreHookStandardTests.test_pre_hook_allows_execution.<locals>.allow_hook   s%    t$g223r   rx   r0   rU   rG   r-   N)r
   registryregisterr   r   r(   rG   run
assertTruesuccessrY   r   )r#   rx   managertaskresultrw   s   `    @r   test_pre_hook_allows_executionz3PreHookStandardTests.test_pre_hook_allows_execution   s    	4
 23!!,jT]!^t':':;$'3r   c                    d }t               }|j                  j                  dt        j                  |d       t        | j                        }|j                         }| j                  |j                         | j                  |j                  d       | j                  |j                  d       | j                  t        j                  j                         d       y	)
z%Test PRE hook that rejects execution.c                     t        dd      )NDEPENDENCY_NOT_METRequired task not completedr   r   r   r[   s    r   reject_hookzIPreHookStandardTests.test_pre_hook_rejects_execution.<locals>.reject_hook   s    $/5 r   r   r0   ry   rz   r   r   r   N)r
   r{   r|   r   r   r(   rG   r}   assertFalser   rY   r   r   r   rn   countr#   r   r   r   r   s        r   test_pre_hook_rejects_executionz4PreHookStandardTests.test_pre_hook_rejects_execution   s    	 23!!-{V_!`t':':;(**,@A)FG 	..446:r   c                    g fd}t               }|j                  j                  dt        j                  |d       t        | j                  dd      }|j                          | j                  t              d       d   }| j                  |j                  j                  d	             | j                  |j                  j                  d
             y)z$Test PRE hook receives task options.c                 (    j                  |        y r   rv   r[   captured_contexts    r   capture_hookzIPreHookStandardTests.test_pre_hook_receives_options.<locals>.capture_hook       ##G,r   r   r0   ry   T)rG   rR   rerunrE   r   rR   r   N)r
   r{   r|   r   r   r(   rG   r}   rY   lenr~   rW   get)r#   r   r   r   r[   r   s        @r   test_pre_hook_receives_optionsz3PreHookStandardTests.test_pre_hook_receives_options   s    	- 23!!.(,,Xa!bt':':$dS
-.2"1%++G45++G45r   c                    g fd}fd}fd}t               }|j                  j                  dt        j                  |dd       |j                  j                  dt        j                  |dd	       |j                  j                  d
t        j                  |dd       t        | j                        }|j                          | j                  g d       y)z2Test multiple PRE hooks execute in priority order.c                 (    j                  d       y )Nhook_10r   r[   execution_orders    r   hook_priority_10zUPreHookStandardTests.test_multiple_pre_hooks_priority_order.<locals>.hook_priority_10   s    ""9-r   c                 (    j                  d       y )Nhook_5r   r   s    r   hook_priority_5zTPreHookStandardTests.test_multiple_pre_hooks_priority_order.<locals>.hook_priority_5       ""8,r   c                 (    j                  d       y )Nhook_1r   r   s    r   hook_priority_1zTPreHookStandardTests.test_multiple_pre_hooks_priority_order.<locals>.hook_priority_1   r   r   r   r0   
   rU   priorityr      r   rE   rz   )r   r   r   N)	r
   r{   r|   r   r   r(   rG   r}   rY   )r#   r   r   r   r   r   r   s         @r   &test_multiple_pre_hooks_priority_orderz;PreHookStandardTests.test_multiple_pre_hooks_priority_order   s    	.	-	- 23!!"4hllDT`itv!w!!"3X\\?^grs!t!!"3X\\?^grs!tt':':;
 	*IJr   c                    g fd}fd}t               }|j                  j                  dt        j                  |dd       |j                  j                  dt        j                  |dd       t        | j                  	      }|j                         }| j                  |j                         | j                  d
g       y)z5Test that first PRE hook rejection stops other hooks.c                 @    j                  d       t        dd      )NrejectREJECTEDRejectedr   )rv   r   r   s    r   hook_rejectzWPreHookStandardTests.test_first_pre_hook_rejection_stops_execution.<locals>.hook_reject   s    ""8,$
JOOr   c                 (    j                  d       y )Nafterr   r   s    r   
hook_afterzVPreHookStandardTests.test_first_pre_hook_rejection_stops_execution.<locals>.hook_after   s    ""7+r   r   r0   rE   r   r      rz   r   N)r
   r{   r|   r   r   r(   rG   r}   r   r   rY   )r#   r   r   r   r   r   r   s         @r   -test_first_pre_hook_rejection_stops_executionzBPreHookStandardTests.test_first_pre_hook_rejection_stops_execution   s    	P	, 23!!-{V_jk!l!!,jT]hi!jt':':;(8*5r   )r   r   r   r2   rI   rM   r   r   r   r   r   r%   r&   s   @r   rk   rk      s*    *-
4&;*6$K06r   rk   c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	PostHookStandardTestsz!Test standard POST hook behavior.c                     t        ddd      | _        t                t        j                  j                         j                          yrD   rm   rH   s    r   rI   zPostHookStandardTests.setUp  rq   r   c                    g fd}t               }|j                  j                  dt        j                  |d       t        | j                        }|j                         }| j                  |j                         | j                  t              d       d   }| j                  |j                         | j                  |j                  d       y	)
z4Test POST hook receives successful execution result.c                 (    j                  |        y r   r   r   s    r   	post_hookzOPostHookStandardTests.test_post_hook_receives_success_result.<locals>.post_hook  r   r   r   r0   ry   rz   rE   r   r)   N)r
   r{   r|   r   r   r(   rG   r}   r~   r   rY   r   assertIsNotNonerV   r3   r#   r   r   r   r   r[   r   s         @r   &test_post_hook_receives_success_resultz<PostHookStandardTests.test_post_hook_receives_success_result  s    	- 23!!+x}}iS\!]t':':;'-.2"1%W112**K8r   c                 z   g fd}t               }|j                  j                  dt        j                  |d       t        | j                        }|j                         }| j                  |j                         | j                  t              d       d   }| j                  |j                         y)	z0Test POST hook receives failed execution result.c                 (    j                  |        y r   r   r   s    r   r   zOPostHookStandardTests.test_post_hook_receives_failure_result.<locals>.post_hook-  r   r   r   r0   ry   rz   rE   r   N)r
   r{   r|   r   r   r7   rG   r}   r   r   rY   r   r   rV   r   s         @r   &test_post_hook_receives_failure_resultz<PostHookStandardTests.test_post_hook_receives_failure_result)  s    	- 23!!+x}}iS\!]$*=*=>(-.2"1%W112r   c                 2   d }t               }|j                  j                  dt        j                  |d       t        | j                        }|j                         }| j                  |j                         | j                  |j                  d       y)z8Test POST hook rejections don't affect execution result.c                     t        dd      )NPOST_REJECTzShould be ignoredr   r   r   s    r   post_hook_rejectzLPostHookStandardTests.test_post_hook_cannot_reject.<locals>.post_hook_reject>  s     %GZ[[r   r   r0   ry   rz   r-   N)r
   r{   r|   r   r   r(   rG   r}   r~   r   rY   r   )r#   r   r   r   r   s        r   test_post_hook_cannot_rejectz2PostHookStandardTests.test_post_hook_cannot_reject<  sw    	\
 23!!"4hmmEUaj!kt':':; 	'3r   c                 ^   g fd}fd}t               }|j                  j                  dt        j                  |dd       |j                  j                  dt        j                  |dd       t        | j                  	      }|j                          | j                  d
dg       y)z%Test multiple POST hooks all execute.c                 (    j                  d       y )Nar   r   s    r   hook_azJPostHookStandardTests.test_multiple_post_hooks_all_execute.<locals>.hook_aQ      ""3'r   c                 (    j                  d       y )Nbr   r   s    r   hook_bzJPostHookStandardTests.test_multiple_post_hooks_all_execute.<locals>.hook_bT  r   r   r   r0   rE   r   r   r   rz   r   r   N)	r
   r{   r|   r   r   r(   rG   r}   rY   )r#   r   r   r   r   r   s        @r   $test_multiple_post_hooks_all_executez:PostHookStandardTests.test_multiple_post_hooks_all_executeM  s    	(	( 23!!(HMM6Yab!c!!(HMM6Yab!ct':':;
3*5r   c                 n   d }t               }|j                  j                  dt        j                  |d       t        | j                        }t        d      5 }|j                         }| j                  |j                         |j                  j                          ddd       y# 1 sw Y   yxY w)z=Test POST hook exceptions are logged but don't affect result.c                     t        d      )NzPOST hook errorr?   r   s    r   post_hook_exceptionzaPostHookStandardTests.test_post_hook_exception_logged_but_not_raised.<locals>.post_hook_exceptionb  s    .//r   r   r0   ry   rz   z django_cronjob_utils.base.loggerN)r
   r{   r|   r   r   r(   rG   r   r}   r~   r   warningassert_called)r#   r   r   r   mock_loggerr   s         r   .test_post_hook_exception_logged_but_not_raisedzDPostHookStandardTests.test_post_hook_exception_logged_but_not_raised`  s    	0 23!!"7H[gp!qt':':; 56+XXZF OOFNN+ --/ 766s   AB++B4N)
r   r   r   r2   rI   r   r   r   r   r   r   r   r   r   r     s#    +-9(3&4"6&0r   r   c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	HookEdgeCaseTestsz!Test edge cases in hook behavior.c                     t        ddd      | _        t                t        j                  j                         j                          yrD   rm   rH   s    r   rI   zHookEdgeCaseTests.setUp}  rq   r   c                    d }g fd}t               }|j                  j                  dt        j                  |d       |j                  j                  dt        j
                  |d       t        | j                        }|j                          | j                  t              d       | j                  d	   d
   d       y)z1Test PRE hook can modify metadata for POST hooks.c                 "    d| j                   d<   y )Nfrom_prepre_hook_data)rX   r   s    r   pre_hookzCHookEdgeCaseTests.test_pre_hook_modifies_metadata.<locals>.pre_hook  s    0:G_-r   c                 X    j                  | j                  j                                y r   )rv   rX   copy)r[   captured_metadatas    r   r   zDHookEdgeCaseTests.test_pre_hook_modifies_metadata.<locals>.post_hook  s     $$W%5%5%:%:%<=r   r   r0   ry   r   rz   rE   r   r   r   N)r
   r{   r|   r   r   r   r(   rG   r}   rY   r   )r#   r   r   r   r   r   s        @r   test_pre_hook_modifies_metadataz1HookEdgeCaseTests.test_pre_hook_modifies_metadata  s    	; 	> 23!!*hllHPY!Z!!+x}}iS\!]t':':;
 	./3*1-o>
Kr   c                 Z    G d dt               }g fd}t               }|j                  j                  dt        j
                  |d        || j                        }|j                         }| j                  |j                         | j                  d   j                  d	       y
)z(Test hook with task that has empty code.c                   $    e Zd ZdZdZdedefdZy)DHookEdgeCaseTests.test_hook_with_empty_task_code.<locals>.NoCodeTaskzno-code-task r   r+   c                 
    ddiS )Nr.   Fr   r/   s     r   r0   zLHookEdgeCaseTests.test_hook_with_empty_task_code.<locals>.NoCodeTask.execute  s    ''r   N)r   r   r   r3   r4   r   r5   r0   r   r   r   
NoCodeTaskr     s    &II(D (T (r   r   c                 (    j                  |        y r   r   r   s    r   r   zBHookEdgeCaseTests.test_hook_with_empty_task_code.<locals>.pre_hook  r   r   r   r0   ry   rz   r   r   N)r   r
   r{   r|   r   r   rG   r}   r~   r   rY   r4   )r#   r   r   r   r   r   r   s         @r   test_hook_with_empty_task_codez0HookEdgeCaseTests.test_hook_with_empty_task_code  s    	( 	( 	- 23!!*hllHPY!Z)<)<=')!,66;r   c                 2   d }t               }|j                  j                  dt        j                  |d       t        | j                        }|j                         }| j                  |j                         | j                  |j                  d       y)z0Test PRE hook rejection with minimal error info.c                     t        dd      )NMINIMALr   r   r   r   s    r   r   zPHookEdgeCaseTests.test_pre_hook_rejection_with_minimal_info.<locals>.reject_hook  s    $	2FFr   r   r0   ry   rz   r   N)r
   r{   r|   r   r   r(   rG   r}   r   r   rY   r   r   s        r   )test_pre_hook_rejection_with_minimal_infoz;HookEdgeCaseTests.test_pre_hook_rejection_with_minimal_info  sw    	G 23!!-{V_!`t':':;(**I6r   c                    d }t               }|j                  j                  dt        j                  |d       t        | j                        }|j                         }| j                  |j                         | j                  |j                  d       | j                  |j                         | j                  |j                  d   d       y	)
z+Test PRE hook rejection with extra details.c                 $    t        ddddd      )NWITH_DETAILSzRejected with details
dependencyz
other-task)reasonrequired_task)r   r   r    r   r   s    r   r   zQHookEdgeCaseTests.test_pre_hook_rejection_with_extra_details.<locals>.reject_hook  s    $)/#/,O r   r   r0   ry   rz   r   r   r   N)r
   r{   r|   r   r   r(   rG   r}   r   r   rY   r   r   rT   r   s        r   *test_pre_hook_rejection_with_extra_detailsz<HookEdgeCaseTests.test_pre_hook_rejection_with_extra_details  s    	 23!!-{V_!`t':':;(**N;V[[)X.=r   c                 "   g fd}t               }|j                  j                  dt        j                  |d       t        | j                        }| j                  t              5  |j                          ddd       y# 1 sw Y   yxY w)z4Test POST hooks behavior when task raises exception.c                 (    j                  |        y r   r   r   s    r   r   zTHookEdgeCaseTests.test_task_with_exception_still_calls_post_hooks.<locals>.post_hook  r   r   post_hook_exceptr0   ry   rz   N)
r
   r{   r|   r   r   r<   rG   rc   r@   r}   )r#   r   r   r   r   s       @r   /test_task_with_exception_still_calls_post_hookszAHookEdgeCaseTests.test_task_with_exception_still_calls_post_hooks  sp    	- 23!!"4hmmYZc!dD,?,?@ z*HHJ +**s   +BBN)
r   r   r   r2   rI   r   r   r   r   r   r   r   r   r   r   y  s$    +-L*<.7>(r   r   c                   (    e Zd ZdZd Zd Zd Zd Zy)HookOutlierTestsz!Test outlier scenarios for hooks.c                     t        ddd      | _        t                t        j                  j                         j                          yrD   rm   rH   s    r   rI   zHookOutlierTests.setUp  rq   r   c                     g fd}t        | j                        }|j                          | j                  g        y)z:Test hook registered for different event is not triggered.c                 (    j                  d       y ru   r   )r[   rw   s    r   hookzGHookOutlierTests.test_hook_registered_but_never_triggered.<locals>.hook  s    t$r   rz   N)r(   rG   r}   rY   )r#   r  r   rw   s      @r   (test_hook_registered_but_never_triggeredz9HookOutlierTests.test_hook_registered_but_never_triggered  s:    	% t':':;
 	b)r   c                    g t               }t        d      D ]>  }fd}|j                  j                  d| t        j
                   ||      d|       @ t        | j                        }|j                         }| j                  |j                         | j                  t              d       | j                  t        t        d                   y)z'Test system with many hooks registered.   c                       fd}|S )Nc                 (    j                         y r   r   )r[   r   indexs    r   r  zMHookOutlierTests.test_many_hooks_performance.<locals>.make_hook.<locals>.hook  s    #**51r   r   )r  r  r   s   ` r   	make_hookz?HookOutlierTests.test_many_hooks_performance.<locals>.make_hook  s    2r   hook_r0   r   rz   N)r
   ranger{   r|   r   r   r(   rG   r}   r~   r   rY   r   list)r#   r   ir  r   r   r   s         @r   test_many_hooks_performancez,HookOutlierTests.test_many_hooks_performance  s     23rA
 %%aSk8<<1Ybmn%o  t':':; 	'_-r2$uRy/:r   c                    t         j                  j                         }d }t               }|j                  j                  dt        j                  |d       t        | j                        }|j                         }| j                  |j                         t         j                  j                         }| j                  ||       y)z8Test PRE hook rejection doesn't create orphaned records.c                     t        dd      )Nr   z
No recordsr   r   r   s    r   r   zVHookOutlierTests.test_pre_hook_rejection_preserves_database_state.<locals>.reject_hook!  s    $
LQQr   r   r0   ry   rz   N)r   rn   r   r
   r{   r|   r   r   r(   rG   r}   r   r   rY   )r#   initial_countr   r   r   r   final_counts          r   0test_pre_hook_rejection_preserves_database_statezAHookOutlierTests.test_pre_hook_rejection_preserves_database_state  s     &--335	R 23!!-{V_!`t':':;(#++1134r   N)r   r   r   r2   rI   r  r  r  r   r   r   r   r     s    +-* ;,5r   r   c                   :     e Zd ZdZd Z fdZd Zd Zd Z xZ	S )HookIntegrationTestsz+Test real-world hook integration scenarios.c                     t        ddd      | _        t                t        j                  j                         j                          yrD   rm   rH   s    r   rI   zHookIntegrationTests.setUp8  rq   r   c                 6    t                t        | 	          yrK   rL   rN   s    r   rM   zHookIntegrationTests.tearDown>  rO   r   c                    t        | j                        }d|_        d|_        |j	                         }| j                  |j                         d }t               }|j                  j                  dt        j                  |d       t        | j                        }|j	                         }| j                  |j                         y)	z(Test realistic dependency checking hook.rz   zdependency-taskDEP001c                     | j                   dk(  rKt        j                  j                  d| j                  dd      j                         }|st        dd      y y )Nr*   r  T)r4   rG   	completedr   r   z"Required task DEP001 not completedr   )r4   r   rn   filterrG   existsr   )r[   dependency_existss     r   check_dependencyzLHookIntegrationTests.test_dependency_checking_hook.<locals>.check_dependencyL  sl      F*$1$9$9$@$@&#*#9#9" 	 %A %
 &( " ),#7 D  ) +r   r  r0   ry   N)r(   rG   r3   r4   r}   r~   r   r
   r{   r|   r   r   )r#   dependency_taskdependency_resultr  r   r   r   s          r   test_dependency_checking_hookz2HookIntegrationTests.test_dependency_checking_hookC  s     #$2E2EF$5!$,!+//1)112	  23!!"4hllDT`i!j t':':; 	'r   c                    g fd}t               }|j                  j                  dt        j                  |d       t        | j                        }|j                          t        | j                        }|j                          | j                  t              d       | j                  d   d          | j                  d	   d          y
)z'Test realistic audit logging POST hook.c                     | j                   rit        j                  j                  | j                         }j	                  | j
                  |j                  |j                  |j                  d       y y )N)id)r   r  r   duration)	rV   r   rn   r   rv   r3   r  r   r%  )r[   	execution	audit_logs     r   
audit_hookz@HookIntegrationTests.test_audit_logging_hook.<locals>.audit_hookj  sg    ##)11559M9M5N	  #--!*!4!4(00 ) 2 2	"  $r   r(  r0   ry   rz   r   r   r   rE   N)r
   r{   r|   r   r   r(   rG   r}   r7   rY   r   r~   r   )r#   r(  r   task1task2r'  s        @r   test_audit_logging_hookz,HookIntegrationTests.test_audit_logging_hookf  s    			 23!!,zU^!_ (;(;<		 4+>+>?		 	Y+	!Y/01i01r   c                 0   d }t               }|j                  j                  dt        j                  |d       t        d      D ]p  }t        | j                  d      }|j                         }| j                  |j                         |j                  dk7  sU| j                  |j                  d	       r t        | j                  d      }|j                         }| j                  |j                         | j                  |j                  d       y
)z%Test hook that limits retry attempts.c                     | j                   dk(  rZt        j                  j                  | j                   | j                        j                         }|dk\  rt        dd| d      y y )Nr8   )r4   rG      MAX_RETRIES_EXCEEDEDzTask has already failed z timesr   )r4   r   rn   r  rG   r   r   )r[   retry_counts     r   limit_retrieszDHookIntegrationTests.test_retry_limiting_hook.<locals>.limit_retries  sy      F*+33::%//#*#9#9 ;  %' 
 !#,#9":;-v N  $ +r   r1  r0   ry   r.  T)rG   rR   r/  r:   N)r
   r{   r|   r   r   r
  r7   rG   r}   r   r   r   rY   )r#   r1  r   r  r   r   s         r   test_retry_limiting_hookz-HookIntegrationTests.test_retry_limiting_hook  s    	 23!!/8<<Zc!d qAd.A.ANDXXZFV^^,  $::  !2!2F;  $*=*=TJ(**,BCr   )
r   r   r   r2   rI   rM   r!  r+  r2  r%   r&   s   @r   r  r  4  s!    5-
!(F2> Dr   r  N) r2   datetimer   unittestr   unittest.mockr   django.testr   django_cronjob_utils.baser   r   django_cronjob_utils.hooksr	   r
   r   r   django_cronjob_utils.modelsr   django_package_hooksr   r   rd   r(   r7   r<   rB   rk   r   r   r   r  r   r   r   <module>r;     sx  
      ?  6 AA &Y &6x 6O( O+H + OABHCx HC CHCV OABt68 t6 Ct6n OABf0H f0 Cf0Z OABf f Cfd OAB@5x @5 C@5N OABpD8 pD CpDr   