Ë
    BkJiÉD  ã                   ó¬   — d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 ddl
mZ ddlmZmZ  G d„ de«      Z G d	„ d
e«      Z G d„ de«      Z G d„ de«      Zy)z-Tests for the hook system core functionality.é    )ÚDecimal)ÚTestCase)ÚHookManagerÚHookRegistryÚHookTypeÚPostHookError)ÚHookContext)ÚHookRejectionErrorÚHookExecutionErrorc                   óL   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zy)ÚTestHookRegistryzTests for HookRegistry class.c                 ó0  — t        «       }dt        dt        fd„}|j                  dt        j
                  |dd¬«       |j                  dt        j
                  «      }t        |«      dk(  sJ ‚|d	   j                  dk(  sJ ‚|d	   j                  dk(  sJ ‚y
)zTest registering a basic hook.ÚcontextÚreturnc                  ó   — y©NT© ©r   s    ú?/home/cursorai/projects/django-wallet-utils/tests/test_hooks.pyÚmy_hookz:TestHookRegistry.test_register_hook_basic.<locals>.my_hook   ó   € Øó    Ú	test_hookÚaddéd   ©ÚnameÚ	hook_typeÚcallbackÚ	operationÚpriorityé   r   N)
r   r	   ÚboolÚregisterr   ÚPREÚ	get_hooksÚlenr   r!   )ÚselfÚregistryr   Úhookss       r   Útest_register_hook_basicz)TestHookRegistry.test_register_hook_basic   sš   € ä“>ˆð	œ[ð 	¬Tó 	ð 	×ÑØÜ—l‘lØØØð 	ô 	
ð ×"Ñ" 5¬(¯,©,Ó7ˆÜ�5‹z˜QŠÐˆØ�Q‰x�}‰} Ò+Ð+Ð+Ø�Q‰x× Ñ  CÒ'Ð'Ñ'r   c                 ó(  — t        «       }dt        dt        fd„}dt        dt        fd„}dt        dt        fd„}|j                  dt        j
                  |dd¬	«       |j                  d
t        j
                  |dd¬	«       |j                  dt        j
                  |dd¬	«       |j                  dt        j
                  «      }t        |«      dk(  sJ ‚|d   j                  d
k(  sJ ‚|d   j                  dk(  sJ ‚|d   j                  dk(  sJ ‚y)z'Test that hooks are sorted by priority.r   r   c                  ó   — yr   r   r   s    r   Úhook1z@TestHookRegistry.test_register_hook_with_priority.<locals>.hook1+   r   r   c                  ó   — yr   r   r   s    r   Úhook2z@TestHookRegistry.test_register_hook_with_priority.<locals>.hook2.   r   r   c                  ó   — yr   r   r   s    r   Úhook3z@TestHookRegistry.test_register_hook_with_priority.<locals>.hook31   r   r   Úhook_lowr   iô  ©r!   Ú	hook_highé
   Úhook_mediumr   é   r   r"   é   N©	r   r	   r#   r$   r   r%   r&   r'   r   )r(   r)   r.   r0   r2   r*   s         r   Ú test_register_hook_with_priorityz1TestHookRegistry.test_register_hook_with_priority'   s  € ä“>ˆð	œ;ð 	¬4ó 	ð	œ;ð 	¬4ó 	ð	œ;ð 	¬4ó 	ð 	×Ñ˜*¤h§l¡l°E¸5È3ÐÔOØ×Ñ˜+¤x§|¡|°U¸EÈBÐÔOØ×Ñ˜-¬¯©°u¸eÈcÐÔRà×"Ñ" 5¬(¯,©,Ó7ˆÜ�5‹z˜QŠÐˆØ�Q‰x�}‰} Ò+Ð+Ð+Ø�Q‰x�}‰} Ò-Ð-Ð-Ø�Q‰x�}‰} 
Ò*Ð*Ñ*r   c                 ó  — t        «       }dt        dt        fd„}|j                  dt        j
                  |dd¬«       dD ]F  }|j                  |t        j
                  «      }t        |«      d	k(  sJ ‚|d
   j                  dk(  rŒFJ ‚ y)z>Test registering a global hook that applies to all operations.r   r   c                  ó   — yr   r   r   s    r   Úglobal_hookz?TestHookRegistry.test_register_global_hook.<locals>.global_hookC   r   r   r>   Ú*r   r   )r   ÚdeductÚtransferr"   r   Nr:   )r(   r)   r>   r    r*   s        r   Útest_register_global_hookz*TestHookRegistry.test_register_global_hook?   sŒ   € ä“>ˆð	¤ð 	´ó 	ð 	×ÑØÜ—l‘lØ ØØð 	ô 	
ó 7ˆIØ×&Ñ& y´(·,±,Ó?ˆEÜ�u“: ’?Ð"�?Ø˜‘8—=‘= MÓ1Ð1Ð1ñ 7r   c                 ó^  — t        «       }dt        dt        fd„}|j                  dt        j
                  |d«       | j                  t        «      5 }|j                  dt        j
                  |d«       ddd«       | j                  dt        j                  «      «       y# 1 sw Y   Œ/xY w)	z>Test that registering a hook with duplicate name raises error.r   r   c                  ó   — yr   r   r   s    r   r.   zITestHookRegistry.test_register_duplicate_name_raises_error.<locals>.hook1X   r   r   Ú	duplicater   r@   Nzalready registered)r   r	   r#   r$   r   r%   ÚassertRaisesÚ
ValueErrorÚassertInÚstrÚ	exception©r(   r)   r.   Úcms       r   Ú)test_register_duplicate_name_raises_errorz:TestHookRegistry.test_register_duplicate_name_raises_errorT   s†   € ä“>ˆð	œ;ð 	¬4ó 	ð 	×Ñ˜+¤x§|¡|°U¸EÔBð ×ÑœzÔ*¨bØ×Ñ˜k¬8¯<©<¸ÀÔI÷ +à�‰Ð*¬C°·±Ó,=Õ>÷ +Ð*ús   Á#B#Â#B,c                 ó  — t        «       }dt        dt        fd„}| j                  t        «      5 }|j                  dt        j                  |d«       ddd«       | j                  dt        j                  «      «       y# 1 sw Y   Œ/xY w)z:Test that registering with invalid operation raises error.r   r   c                  ó   — yr   r   r   s    r   r.   zLTestHookRegistry.test_register_invalid_operation_raises_error.<locals>.hook1f   r   r   ÚtestÚ
invalid_opNzInvalid operation)r   r	   r#   rF   rG   r$   r   r%   rH   rI   rJ   rK   s       r   Ú,test_register_invalid_operation_raises_errorz=TestHookRegistry.test_register_invalid_operation_raises_errorb   sl   € ä“>ˆð	œ;ð 	¬4ó 	ð ×ÑœzÔ*¨bØ×Ñ˜f¤h§l¡l°E¸<ÔH÷ +à�‰Ð)¬3¨r¯|©|Ó+<Õ=÷ +Ð*ús   °#BÂB
c                 ób  — t        «       }dt        dt        fd„}|j                  dt        j
                  |d«       t        |j                  dt        j
                  «      «      dk(  sJ ‚|j                  d«      }|du sJ ‚t        |j                  dt        j
                  «      «      dk(  sJ ‚y	)
zTest unregistering a hook.r   r   c                  ó   — yr   r   r   s    r   r   z6TestHookRegistry.test_unregister_hook.<locals>.my_hookq   r   r   r   r   r"   Tr   N)	r   r	   r#   r$   r   r%   r'   r&   Ú
unregister)r(   r)   r   Úresults       r   Útest_unregister_hookz%TestHookRegistry.test_unregister_hookm   sœ   € ä“>ˆð	œ[ð 	¬Tó 	ð 	×Ñ˜+¤x§|¡|°W¸eÔDÜ�8×%Ñ% e¬X¯\©\Ó:Ó;¸qÒ@Ð@Ð@ð ×$Ñ$ [Ó1ˆØ˜‰~Ðˆ~Ü�8×%Ñ% e¬X¯\©\Ó:Ó;¸qÒ@Ð@Ñ@r   c                 óF   — t        «       }|j                  d«      }|du sJ ‚y)z-Test unregistering a hook that doesn't exist.ÚnonexistentFN)r   rU   )r(   r)   rV   s      r   Ú test_unregister_nonexistent_hookz1TestHookRegistry.test_unregister_nonexistent_hook|   s%   € ä“>ˆØ×$Ñ$ ]Ó3ˆØ˜‰Ð‰r   c                 óè  — t        «       }dt        dt        fd„}dt        ddfd„}|j                  dt        j
                  |d«       |j                  dt        j                  |d«       |j                  dt        j
                  «      }|j                  dt        j                  «      }t        |«      d	k(  sJ ‚|d
   j                  dk(  sJ ‚t        |«      d	k(  sJ ‚|d
   j                  dk(  sJ ‚y)z)Test that get_hooks filters by hook type.r   r   c                  ó   — yr   r   r   s    r   Úpre_hookzATestHookRegistry.test_get_hooks_filters_by_type.<locals>.pre_hook†   r   r   Nc                  ó   — y )Nr   r   s    r   Ú	post_hookzBTestHookRegistry.test_get_hooks_filters_by_type.<locals>.post_hook‰   s   € Ør   r]   r   r_   r"   r   )
r   r	   r#   r$   r   r%   ÚPOSTr&   r'   r   )r(   r)   r]   r_   Ú	pre_hooksÚ
post_hookss         r   Útest_get_hooks_filters_by_typez/TestHookRegistry.test_get_hooks_filters_by_type‚   sá   € ä“>ˆð	œkð 	¬dó 	ð	œ{ð 	¨tó 	ð 	×Ñ˜*¤h§l¡l°H¸eÔDØ×Ñ˜+¤x§}¡}°iÀÔGà×&Ñ& u¬h¯l©lÓ;ˆ	Ø×'Ñ'¨¬x¯}©}Ó=ˆ
ä�9‹~ Ò"Ð"Ð"Ø˜‰|× Ñ  JÒ.Ð.Ð.ä�:‹ !Ò#Ð#Ð#Ø˜!‰}×!Ñ! [Ò0Ð0Ñ0r   c                 ó˜  — t        «       }dt        dt        fd„}dt        dt        fd„}|j                  dt        j
                  |dd¬«       |j                  d	t        j
                  |d
d¬«       |j                  dt        j
                  «      }t        |«      dk(  sJ ‚|d   j                  d	k(  sJ ‚|d   j                  dk(  sJ ‚y)zATest that get_hooks combines operation-specific and global hooks.r   r   c                  ó   — yr   r   r   s    r   r.   zLTestHookRegistry.test_get_hooks_combines_operation_and_global.<locals>.hook1œ   r   r   c                  ó   — yr   r   r   s    r   r0   zLTestHookRegistry.test_get_hooks_combines_operation_and_global.<locals>.hook2Ÿ   r   r   Úspecific_hookr   r   r4   r>   r?   é2   r9   r   r"   Nr:   )r(   r)   r.   r0   r*   s        r   Ú,test_get_hooks_combines_operation_and_globalz=TestHookRegistry.test_get_hooks_combines_operation_and_global˜   s¾   € ä“>ˆð	œ;ð 	¬4ó 	ð	œ;ð 	¬4ó 	ð 	×Ñ˜/¬8¯<©<¸ÀÐPSÐÔTØ×Ñ˜-¬¯©°u¸cÈBÐÔOà×"Ñ" 5¬(¯,©,Ó7ˆÜ�5‹z˜QŠÐˆà�Q‰x�}‰} Ò-Ð-Ð-Ø�Q‰x�}‰} Ò/Ð/Ñ/r   c                 ó˜  — t        «       }dt        dt        fd„}|j                  dt        j
                  |d«       |j                  dt        j                  |d«       |j                  «        t        |j                  dt        j
                  «      «      dk(  sJ ‚t        |j                  dt        j                  «      «      dk(  sJ ‚y	)
zTest clearing all hooks.r   r   c                  ó   — yr   r   r   s    r   r.   z0TestHookRegistry.test_clear_hooks.<locals>.hook1¯   r   r   r.   r   r0   r@   r   N)
r   r	   r#   r$   r   r%   r`   Úclearr'   r&   )r(   r)   r.   s      r   Útest_clear_hooksz!TestHookRegistry.test_clear_hooks«   s    € ä“>ˆð	œ;ð 	¬4ó 	ð 	×Ñ˜'¤8§<¡<°¸Ô>Ø×Ñ˜'¤8§=¡=°%¸ÔBà�‰Ôä�8×%Ñ% e¬X¯\©\Ó:Ó;¸qÒ@Ð@Ð@Ü�8×%Ñ% h´·±Ó>Ó?À1ÒDÐDÑDr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r+   r;   rB   rM   rR   rW   rZ   rc   ri   rm   r   r   r   r   r      s9   „ Ù'ò(ò(+ò02ò*?ò	>òAòò1ò,0ó&Er   r   c                   óF   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zy)ÚTestHookManagerzTests for HookManager class.c           	      óv  ‡— t        «       }t        |«      }g Šdt        dt        fˆfd„}dt        dt        fˆfd„}|j	                  dt
        j                  |dd¬«       |j	                  d	t
        j                  |dd
¬«       t        dddt        d«      ddd¬«      }|j                  |«       ‰dd	gk(  sJ ‚y)z&Test executing PRE hooks successfully.r   r   c                 ó(   •— ‰j                  d«       y©Nr.   T©Úappend©r   Úexecuteds    €r   r.   z=TestHookManager.test_execute_pre_hooks_success.<locals>.hook1Å   ó   ø€ Ø�O‰O˜GÔ$Ør   c                 ó(   •— ‰j                  d«       y)Nr0   Trw   ry   s    €r   r0   z=TestHookManager.test_execute_pre_hooks_success.<locals>.hook2É   r{   r   r.   r   r6   r4   r0   é   r"   ÚcashÚ100rP   Néœÿÿÿ©r    Úuser_idÚ
point_typeÚamountÚremarksÚ
trans_typeÚiid)	r   r   r	   r#   r$   r   r%   r   Úexecute_pre_hooks)r(   r)   Úmanagerr.   r0   r   rz   s         @r   Útest_execute_pre_hooks_successz.TestHookManager.test_execute_pre_hooks_success¾   sÃ   ø€ ä“>ˆÜ˜hÓ'ˆàˆð	œ;ð 	¬4õ 	ð	œ;ð 	¬4õ 	ð 	×Ñ˜'¤8§<¡<°¸ÈÐÔKØ×Ñ˜'¤8§<¡<°¸ÈÐÔKäØØØÜ˜5“>ØØØô
ˆð 	×!Ñ! 'Ô*ð ˜G WÐ-Ò-Ð-Ñ-r   c           	      óŠ  — t        «       }t        |«      }dt        dt        fd„}|j	                  dt
        j                  |d«       t        dddt        d«      d	d
d¬«      }| j                  t        «      5 }|j                  |«       d
d
d
«       | j                  dj                  j                  «       y
# 1 sw Y   Œ0xY w)z7Test PRE hook rejecting transaction by returning False.r   r   c                  ó   — y)NFr   r   s    r   Úrejecting_hookzNTestHookManager.test_execute_pre_hooks_rejection_false.<locals>.rejecting_hookä   s   € Ør   r�   r   r"   r~   r   rP   Nr€   r�   ÚHOOK_REJECTED_REJECTING_HOOK)r   r   r	   r#   r$   r   r%   r   rF   r
   rˆ   rH   rJ   Ú
error_code©r(   r)   r‰   r�   r   rL   s         r   Ú&test_execute_pre_hooks_rejection_falsez6TestHookManager.test_execute_pre_hooks_rejection_falseß   s®   € ä“>ˆÜ˜hÓ'ˆð	¤Kð 	´Dó 	ð 	×ÑÐ*¬H¯L©L¸.È%ÔPäØØØÜ˜5“>ØØØô
ˆð ×ÑÔ1Ô2°bØ×%Ñ% gÔ.÷ 3ð 	�‰Ð4°b·l±l×6MÑ6MÕN÷ 3Ð2ús   Á8B9Â9Cc           	      ó(  — t        «       }t        |«      }dt        dt        fd„}|j	                  dt
        j                  |d«       t        dddt        d«      d	d
d¬«      }| j                  t        «      5 }|j                  |«       d
d
d
«       | j                  j                  j                  d«       | j                  |j                  j                  d«       | j                  |j                  j                  d   d	«       y
# 1 sw Y   ŒxY w)zBTest PRE hook rejecting transaction by raising HookRejectionError.r   r   c                 ó"   — t        ddddi¬«      ‚)NÚCUSTOM_ERRORúTransaction not allowedÚreasonrP   ©r�   ÚmessageÚdetails©r
   r   s    r   r�   zRTestHookManager.test_execute_pre_hooks_rejection_exception.<locals>.rejecting_hooký   s   € Ü$Ø)Ø1Ø! 6Ð*ôð r   r�   r   r"   r~   r   rP   Nr€   r�   r”   r•   r–   )r   r   r	   r#   r$   r   r%   r   rF   r
   rˆ   ÚassertEqualrJ   r�   r˜   r™   r�   s         r   Ú*test_execute_pre_hooks_rejection_exceptionz:TestHookManager.test_execute_pre_hooks_rejection_exceptionø   sé   € ä“>ˆÜ˜hÓ'ˆð	¤Kð 	´Dó 	ð 	×ÑÐ*¬H¯L©L¸.È%ÔPäØØØÜ˜5“>ØØØô
ˆð ×ÑÔ1Ô2°bØ×%Ñ% gÔ.÷ 3ð 	×Ñ˜Ÿ™×0Ñ0°.ÔAØ×Ñ˜Ÿ™×-Ñ-Ð/HÔIØ×Ñ˜Ÿ™×-Ñ-¨hÑ7¸Õ@÷ 3Ð2ús   Á8DÄDc           	      óÔ  — t        «       }t        |«      }dt        dt        fd„}|j	                  dt
        j                  |d«       t        dddt        d«      d	d
d¬«      }| j                  t        «      5 }|j                  |«       d
d
d
«       | j                  j                  j                  d«       | j                  dt        |j                  «      «       y
# 1 sw Y   ŒUxY w)z+Test PRE hook raising unexpected exception.r   r   c                 ó   — t        d«      ‚)NúSomething went wrong©rG   r   s    r   Úfailing_hookzMTestHookManager.test_execute_pre_hooks_unexpected_error.<locals>.failing_hook  s   € ÜÐ3Ó4Ð4r   r¡   r   r"   r~   r   rP   Nr€   r�   rŸ   )r   r   r	   r#   r$   r   r%   r   rF   r   rˆ   r›   rJ   Ú	hook_namerH   rI   )r(   r)   r‰   r¡   r   rL   s         r   Ú'test_execute_pre_hooks_unexpected_errorz7TestHookManager.test_execute_pre_hooks_unexpected_error  sÆ   € ä“>ˆÜ˜hÓ'ˆð	5¤+ð 	5´$ó 	5ð 	×Ñ˜.¬(¯,©,¸ÀeÔLäØØØÜ˜5“>ØØØô
ˆð ×ÑÔ1Ô2°bØ×%Ñ% gÔ.÷ 3ð 	×Ñ˜Ÿ™×/Ñ/°Ô@Ø�‰Ð,¬c°"·,±,Ó.?Õ@÷	 3Ð2ús   Á8CÃC'c           	      óL  ‡— t        «       }t        |«      }g Šdt        dt        fˆfd„}dt        dt        fˆfd„}dt        dt        fˆfd„}|j	                  dt
        j                  |dd¬	«       |j	                  d
t
        j                  |dd¬	«       |j	                  dt
        j                  |dd¬	«       t        dddt        d«      ddd¬«      }| j                  t        «      5  |j                  |«       ddd«       | j                  ‰dd
g«       y# 1 sw Y   ŒxY w)z7Test that PRE hook execution stops when a hook rejects.r   r   c                 ó(   •— ‰j                  d«       yrv   rw   ry   s    €r   r.   zHTestHookManager.test_execute_pre_hooks_stops_on_rejection.<locals>.hook18  r{   r   c                 ó(   •— ‰j                  d«       y)NÚ	rejectingFrw   ry   s    €r   r�   zQTestHookManager.test_execute_pre_hooks_stops_on_rejection.<locals>.rejecting_hook<  s   ø€ Ø�O‰O˜KÔ(Ør   c                 ó(   •— ‰j                  d«       y)Nr2   Trw   ry   s    €r   r2   zHTestHookManager.test_execute_pre_hooks_stops_on_rejection.<locals>.hook3@  r{   r   r.   r   r6   r4   r§   r}   r2   é   r"   r~   r   rP   Nr€   r�   )r   r   r	   r#   r$   r   r%   r   rF   r
   rˆ   r›   )r(   r)   r‰   r.   r�   r2   r   rz   s          @r   Ú)test_execute_pre_hooks_stops_on_rejectionz9TestHookManager.test_execute_pre_hooks_stops_on_rejection1  s  ø€ ä“>ˆÜ˜hÓ'ˆàˆð	œ;ð 	¬4õ 	ð	¤Kð 	´Dõ 	ð	œ;ð 	¬4õ 	ð 	×Ñ˜'¤8§<¡<°¸ÈÐÔKØ×Ñ˜+¤x§|¡|°^ÀUÐUWÐÔXØ×Ñ˜'¤8§<¡<°¸ÈÐÔKäØØØÜ˜5“>ØØØô
ˆð ×ÑÔ1Õ2Ø×%Ñ% gÔ.÷ 3ð 	×Ñ˜ G¨[Ð#9Õ:÷	 3Ð2ús   Ã+DÄD#c           	      ó†  ‡— t        «       }t        |«      }g Šdt        ddfˆfd„}dt        ddfˆfd„}|j                  dt        j
                  |dd¬	«       |j                  d
t        j
                  |dd¬	«       t        dddt        d«      ddd¬«      }|j                  |«      }t        |«      dk(  sJ ‚‰dd
gk(  sJ ‚y)z'Test executing POST hooks successfully.r   r   Nc                 ó(   •— ‰j                  d«       y ©Nr.   rw   ry   s    €r   r.   z>TestHookManager.test_execute_post_hooks_success.<locals>.hook1_  ó   ø€ Ø�O‰O˜GÕ$r   c                 ó(   •— ‰j                  d«       y )Nr0   rw   ry   s    €r   r0   z>TestHookManager.test_execute_post_hooks_success.<locals>.hook2b  r®   r   r.   r   r6   r4   r0   r}   r"   r~   r   rP   r€   r�   r   )	r   r   r	   r$   r   r`   r   Úexecute_post_hooksr'   )r(   r)   r‰   r.   r0   r   Úerrorsrz   s          @r   Útest_execute_post_hooks_successz/TestHookManager.test_execute_post_hooks_successX  sÕ   ø€ ä“>ˆÜ˜hÓ'ˆàˆð	%œ;ð 	%¨4õ 	%ð	%œ;ð 	%¨4õ 	%ð 	×Ñ˜'¤8§=¡=°%¸ÈÐÔLØ×Ñ˜'¤8§=¡=°%¸ÈÐÔLäØØØÜ˜5“>ØØØô
ˆð ×+Ñ+¨GÓ4ˆä�6‹{˜aÒÐÐØ˜G WÐ-Ò-Ð-Ñ-r   c           	      óx  — t        «       }t        |«      }dt        ddfd„}|j                  dt        j
                  |d«       t        dddt        d	«      d
dd¬«      }|j                  |«      }t        |«      dk(  sJ ‚|d   j                  dk(  sJ ‚|d   j                  dk(  sJ ‚d|d   j                  v sJ ‚y)z4Test that POST hook errors are captured, not raised.r   r   Nc                 ó   — t        d«      ‚)NúPOST hook failedr    r   s    r   r¡   zMTestHookManager.test_execute_post_hooks_captures_errors.<locals>.failing_hook|  s   € ÜÐ/Ó0Ð0r   r¡   r   r"   r~   r   rP   r€   r�   r   ÚHOOK_EXECUTION_ERRORrµ   )r   r   r	   r$   r   r`   r   r°   r'   r¢   r�   r˜   )r(   r)   r‰   r¡   r   r±   s         r   Ú'test_execute_post_hooks_captures_errorsz7TestHookManager.test_execute_post_hooks_captures_errorsw  sÐ   € ä“>ˆÜ˜hÓ'ˆð	1¤+ð 	1°$ó 	1ð 	×Ñ˜.¬(¯-©-¸ÀuÔMäØØØÜ˜5“>ØØØô
ˆð ×+Ñ+¨GÓ4ˆä�6‹{˜aÒÐÐØ�a‰y×"Ñ" nÒ4Ð4Ð4Ø�a‰y×#Ñ#Ð'=Ò=Ð=Ð=Ø! V¨A¡Y×%6Ñ%6Ñ6Ð6Ñ6r   c           	      óR  — t        «       }t        |«      }dt        ddfd„}|j                  dt        j
                  |d«       t        dddt        d	«      d
dd¬«      }|j                  |«      }t        |«      dk(  sJ ‚|d   j                  dk(  sJ ‚|d   j                  dk(  sJ ‚y)z=Test that POST hooks trying to reject are captured as errors.r   r   Nc                 ó   — t        ddi ¬«      ‚)NÚTRYING_TO_REJECTzPOST hook should not rejectr—   rš   r   s    r   Úrejecting_post_hookzRTestHookManager.test_execute_post_hooks_cannot_reject.<locals>.rejecting_post_hook—  s   € Ü$Ø-Ø5Øôð r   r§   r   r"   r~   r   rP   r€   r�   r   rº   )r   r   r	   r$   r   r`   r   r°   r'   r¢   r�   )r(   r)   r‰   r»   r   r±   s         r   Ú%test_execute_post_hooks_cannot_rejectz5TestHookManager.test_execute_post_hooks_cannot_reject’  s¹   € ä“>ˆÜ˜hÓ'ˆð	¬ð 	¸ó 	ð 	×Ñ˜+¤x§}¡}Ð6IÈ5ÔQäØØØÜ˜5“>ØØØô
ˆð ×+Ñ+¨GÓ4ˆä�6‹{˜aÒÐÐØ�a‰y×"Ñ" kÒ1Ð1Ð1Ø�a‰y×#Ñ#Ð'9Ò9Ð9Ñ9r   c           	      ó  ‡— t        «       }t        |«      }g Šdt        ddfˆfd„}dt        ddfˆfd„}dt        ddfˆfd„}|j                  dt        j
                  |dd	¬
«       |j                  dt        j
                  |dd¬
«       |j                  dt        j
                  |dd¬
«       t        dddt        d«      ddd¬«      }|j                  |«      }‰g d¢k(  sJ ‚t        |«      dk(  sJ ‚|d   j                  dk(  sJ ‚y)z8Test that POST hooks continue executing after one fails.r   r   Nc                 ó(   •— ‰j                  d«       y r­   rw   ry   s    €r   r.   zLTestHookManager.test_execute_post_hooks_continues_after_error.<locals>.hook1·  r®   r   c                 ó<   •— ‰j                  d«       t        d«      ‚)NÚfailingÚFailed)rx   rG   ry   s    €r   r¡   zSTestHookManager.test_execute_post_hooks_continues_after_error.<locals>.failing_hookº  s   ø€ Ø�O‰O˜IÔ&Ü˜XÓ&Ð&r   c                 ó(   •— ‰j                  d«       y )Nr2   rw   ry   s    €r   r2   zLTestHookManager.test_execute_post_hooks_continues_after_error.<locals>.hook3¾  r®   r   r.   r   r6   r4   rÀ   r}   r2   r©   r"   r~   r   rP   r€   r�   )r.   rÀ   r2   r   )
r   r   r	   r$   r   r`   r   r°   r'   r¢   )	r(   r)   r‰   r.   r¡   r2   r   r±   rz   s	           @r   Ú-test_execute_post_hooks_continues_after_errorz=TestHookManager.test_execute_post_hooks_continues_after_error°  s  ø€ ä“>ˆÜ˜hÓ'ˆàˆð	%œ;ð 	%¨4õ 	%ð	'¤+ð 	'°$õ 	'ð	%œ;ð 	%¨4õ 	%ð 	×Ñ˜'¤8§=¡=°%¸ÈÐÔLØ×Ñ˜)¤X§]¡]°LÀ%ÐRTÐÔUØ×Ñ˜'¤8§=¡=°%¸ÈÐÔLäØØØÜ˜5“>ØØØô
ˆð ×+Ñ+¨GÓ4ˆð Ò8Ò8Ð8Ð8ä�6‹{˜aÒÐÐØ�a‰y×"Ñ" iÒ/Ð/Ñ/r   N)rn   ro   rp   rq   rŠ   r‘   rœ   r£   rª   r²   r·   r¼   rÃ   r   r   r   rs   rs   »   s7   „ Ù&ò.òBOò2Aò>Aò4%;òN.ò>7ò6:ó<%0r   rs   c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)ÚTestHookContextz Tests for HookContext dataclass.c           	      ó  — t        dddt        d«      ddd¬«      }| j                  t        «      5  d	|_        ddd«       | j                  t        «      5  t        d
«      |_        ddd«       y# 1 sw Y   Œ8xY w# 1 sw Y   yxY w)z2Test that HookContext fields are frozen/immutable.r   r"   r~   r   rP   Nr€   r�   r@   Ú200)r	   r   rF   Ú	Exceptionr    r„   ©r(   r   s     r   Útest_hook_context_immutablez+TestHookContext.test_hook_context_immutableÛ  sw   € äØØØÜ˜5“>ØØØô
ˆð ×ÑœyÕ)Ø (ˆGÔ÷ *ð ×ÑœyÕ)Ü$ U›^ˆGŒN÷ *Ð)÷ *Ð)ú÷ *Ð)ús   ±A0ÁA<Á0A9Á<Bc           	      ó€   — t        dddt        d«      ddd¬«      }d	|j                  d
<   |j                  d
   d	k(  sJ ‚y)z@Test that metadata dict is mutable for inter-hook communication.r   r"   r~   r   rP   Nr€   r�   Úcustom_valueÚ
custom_key)r	   r   ÚmetadatarÉ   s     r   Ú"test_hook_context_metadata_mutablez2TestHookContext.test_hook_context_metadata_mutableî  sP   € äØØØÜ˜5“>ØØØô
ˆð *8ˆ×Ñ˜Ñ&Ø×Ñ Ñ-°Ò?Ð?Ñ?r   c                 ó‚   — t        dddt        d«      ddddd¬	«	      }|j                  dk(  sJ ‚|j                  dk(  sJ ‚y)
z/Test HookContext with transfer-specific fields.rA   r"   r~   r   Nr€   r9   Úcredit)	r    r‚   rƒ   r„   r…   r†   r‡   Ú
to_user_idÚto_point_type)r	   r   rÒ   rÓ   rÉ   s     r   Ú!test_hook_context_transfer_fieldsz1TestHookContext.test_hook_context_transfer_fieldsþ  sU   € äØ ØØÜ˜5“>ØØØØØ"ô

ˆð ×!Ñ! QÒ&Ð&Ð&Ø×$Ñ$¨Ò0Ð0Ñ0r   N)rn   ro   rp   rq   rÊ   rÏ   rÔ   r   r   r   rÅ   rÅ   Ø  s   „ Ù*ò,ò&@ó 1r   rÅ   c                   ó   — e Zd ZdZd„ Zy)ÚTestPostHookErrorz"Tests for PostHookError dataclass.c                 óì   — t        d«      }t        dddddi|¬«      }|j                  dk(  sJ ‚|j                  dk(  sJ ‚|j                  dk(  sJ ‚|j
                  d   dk(  sJ ‚|j                  |u sJ ‚y)	zTest creating a PostHookError.z
Test errorr   Ú
TEST_ERRORzTest error messageÚkeyÚvalue)r¢   r�   r˜   r™   rJ   N)rG   r   r¢   r�   r˜   r™   rJ   )r(   rJ   Úerrors      r   Útest_post_hook_error_creationz/TestPostHookError.test_post_hook_error_creation  sŽ   € ä˜|Ó,ˆ	ÜØ!Ø#Ø(Ø˜GÐ$Øô
ˆð �‰ +Ò-Ð-Ð-Ø×Ñ <Ò/Ð/Ð/Ø�}‰}Ð 4Ò4Ð4Ð4Ø�}‰}˜UÑ# wÒ.Ð.Ð.Ø�‰ )Ñ+Ð+Ñ+r   N)rn   ro   rp   rq   rÜ   r   r   r   rÖ   rÖ     s
   „ Ù,ó,r   rÖ   N)rq   Údecimalr   Údjango.testr   Úwallet_utilsr   r   r   r   Úwallet_utils.hooksr	   Úwallet_utils.exceptionsr
   r   r   rs   rÅ   rÖ   r   r   r   Ú<module>râ      sY   ðÙ 3å Ý  ÷ó õ +ß JôhE�xô hEôVZ0�hô Z0ôz51�hô 51ôp,˜õ ,r   