Ë
    BkJiÈW  ã                   óv   — d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ  G d„ d	e«      Zy
)z5Integration tests for hook system with WalletService.é    )ÚDecimal)ÚTestCase)ÚWalletServiceÚWalletRepositoryÚHookTypeÚclear_hooksÚregister_hook)ÚHookContext©ÚHookRejectionError)ÚTestUserc                   ó”   — 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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)ÚTestWalletServiceWithHooksz1Test WalletService operations with hooks enabled.c                 ó>  — t         j                  j                  dd¬«      | _        t         j                  j                  dd¬«      | _        ddddœ| _        t        t         | j
                  ¬	«      | _        t        | j                  d
¬«      | _	        t        «        y)zSet up test data.Úuser1zuser1@test.com)ÚusernameÚemailÚuser2zuser2@test.comé   r   )ÚcashÚcredit_balanceÚreward_points©Ú
user_modelÚpoint_typesT©Úenable_hooksN)r   ÚobjectsÚcreater   r   r   r   Ú
repositoryr   Úservicer   ©Úselfs    úK/home/cursorai/projects/django-wallet-utils/tests/test_hooks_integration.pyÚsetUpz TestWalletServiceWithHooks.setUp   s†   € ä×%Ñ%×,Ñ,°gÐEUÐ,ÓVˆŒ
Ü×%Ñ%×,Ñ,°gÐEUÐ,ÓVˆŒ
àØØñ
ˆÔô
 +ÜØ×(Ñ(ô
ˆŒô % T§_¡_À4ÔHˆŒô 	�ó    c                 ó   — t        «        y)zClean up after tests.N)r   r"   s    r$   ÚtearDownz#TestWalletServiceWithHooks.tearDown'   s   € ä�r&   c                 óª  ‡— g Šdt         dt        fˆfd„}t        dt        j                  |dd¬«       | j
                  j                  | j                  j                  dt        d	«      d
¬«      }| j                  |j                  «       | j                  |j                  «       | j                  |j                  «       | j!                  ‰dg«       y)z5Test add_point with PRE hook that allows transaction.ÚcontextÚreturnc                 óV   •— ‰j                  d«       | j                  t        d«      k  S )NÚpre_hookÚ1000©ÚappendÚamountr   ©r*   Úexecuteds    €r$   Úcheck_amountzUTestWalletServiceWithHooks.test_add_point_with_pre_hook_success.<locals>.check_amount3   s"   ø€ Ø�O‰O˜JÔ'à—>‘>¤G¨F£OÑ3Ð3r&   r4   Úaddéd   )ÚnameÚ	hook_typeÚcallbackÚ	operationÚpriorityr   Ú100úTest add©Úuser_idÚ
point_typer1   Úremarksr-   N)r
   Úboolr	   r   ÚPREr!   Ú	add_pointr   Úidr   Ú
assertTrueÚsuccessÚassertIsNotNoneÚtransaction_idÚassertIsNoneÚ
error_codeÚassertEqual)r#   r4   Úresultr3   s      @r$   Ú$test_add_point_with_pre_hook_successz?TestWalletServiceWithHooks.test_add_point_with_pre_hook_success/   s·   ø€ àˆð	4¤+ð 	4´$õ 	4ô
 	ØÜ—l‘lØ!ØØõ	
ð —‘×'Ñ'Ø—J‘J—M‘MØÜ˜5“>Øð	 (ó 
ˆð 	�‰˜Ÿ™Ô'Ø×Ñ˜V×2Ñ2Ô3Ø×Ñ˜&×+Ñ+Ô,Ø×Ñ˜ J <Õ0r&   c                 ó  — dt         dt        fd„}t        dt        j                  |d¬«       | j
                  j                  | j                  j                  dt        d«      d	¬
«      }| j                  |j                  «       | j                  |j                  «       | j                  d|j                  «       | j                   j#                  | j                  j                  d«      }| j%                  |t        d«      «       y)z=Test add_point with PRE hook that rejects by returning False.r*   r+   c                 ó6   — | j                   t        d«      kD  ryy)NÚ500FT)r1   r   ©r*   s    r$   Úreject_large_amountszeTestWalletServiceWithHooks.test_add_point_with_pre_hook_rejection_false.<locals>.reject_large_amountsN   s   € à�~‰~¤¨£Ò.ØØr&   Úreject_larger5   ©r7   r8   r9   r:   r   Ú600zLarge amountr>   ÚHOOK_REJECTED_REJECT_LARGEÚ0N)r
   rB   r	   r   rC   r!   rD   r   rE   r   ÚassertFalserG   rJ   rI   ÚassertInrK   r    Úget_user_balancerL   )r#   rS   rM   Úbalances       r$   Ú,test_add_point_with_pre_hook_rejection_falsezGTestWalletServiceWithHooks.test_add_point_with_pre_hook_rejection_falseL   sÑ   € ð	¬+ð 	¼$ó 	ô 	ØÜ—l‘lØ)Øõ		
ð —‘×'Ñ'Ø—J‘J—M‘MØÜ˜5“>Ø"ð	 (ó 
ˆð 	×Ñ˜Ÿ™Ô(Ø×Ñ˜&×/Ñ/Ô0Ø�‰Ð2°F×4EÑ4EÔFà—/‘/×2Ñ2°4·:±:·=±=À&ÓIˆØ×Ñ˜¤'¨#£,Õ/r&   c                 óø  — dt         dt        fd„}t        dt        j                  |d¬«       | j
                  j                  | j                  j                  dt        d«      d	¬
«      }| j                  |j                  «       | j                  |j                  d«       | j                  |j                  d«       | j                  |j                  d   d«       | j                  |j                  d   d«       y)zHTest add_point with PRE hook that rejects by raising HookRejectionError.r*   r+   c                 ó|   — | j                   t        d«      kD  r$t        dddt        | j                   «      dœ¬«      ‚y)NrQ   ÚDAILY_LIMIT_EXCEEDEDú Daily transaction limit exceededéô  )ÚlimitÚ	requested©rK   ÚmessageÚdetailsT©r1   r   r   ÚfloatrR   s    r$   Úcheck_daily_limitzfTestWalletServiceWithHooks.test_add_point_with_pre_hook_rejection_exception.<locals>.check_daily_limitk   s;   € Ø�~‰~¤¨£Ò.Ü(Ø5Ø>Ø&)¼¸g¿n¹nÓ8MÑNôð ð
 r&   Údaily_limitr5   rU   r   rV   z
Over limitr>   r`   ra   rc   rb   rd   g     À‚@N)r
   rB   r	   r   rC   r!   rD   r   rE   r   rY   rG   rL   rK   Úerror_messageÚerror_details)r#   rj   rM   s      r$   Ú0test_add_point_with_pre_hook_rejection_exceptionzKTestWalletServiceWithHooks.test_add_point_with_pre_hook_rejection_exceptioni   sÚ   € ð	¤{ð 	´tó 	ô 	ØÜ—l‘lØ&Øõ		
ð —‘×'Ñ'Ø—J‘J—M‘MØÜ˜5“>Ø ð	 (ó 
ˆð 	×Ñ˜Ÿ™Ô(Ø×Ñ˜×*Ñ*Ð,BÔCØ×Ñ˜×-Ñ-Ð/QÔRØ×Ñ˜×-Ñ-¨gÑ6¸Ô<Ø×Ñ˜×-Ñ-¨kÑ:¸EÕBr&   c                 ó¤  ‡ ‡— g Šdt         ddfˆˆ fd„}t        dt        j                  |d¬«       ‰ j                  j                  ‰ j                  j                  dt        d	«      d
¬«      }‰ j                  |j                  «       ‰ j                  |j                  «       ‰ j                  |j                  «       ‰ j                  ‰dg«       y)z9Test add_point with POST hook that executes successfully.r*   r+   Nc                 ó€   •— ‰j                  d«       | j                  j                  d«      }‰j                  |«       y )NÚ	post_hookrI   )r0   ÚmetadataÚgetrH   )r*   Útx_idr3   r#   s     €€r$   Úlog_transactionzYTestWalletServiceWithHooks.test_add_point_with_post_hook_success.<locals>.log_transactionŒ   s4   ø€ Ø�O‰O˜KÔ(à×$Ñ$×(Ñ(Ð)9Ó:ˆEØ× Ñ  Õ'r&   Úlog_txr5   rU   r   r<   r=   r>   rq   )r
   r	   r   ÚPOSTr!   rD   r   rE   r   rF   rG   rH   rI   rJ   Úpost_hook_errorsrL   )r#   ru   rM   r3   s   `  @r$   Ú%test_add_point_with_post_hook_successz@TestWalletServiceWithHooks.test_add_point_with_post_hook_successˆ   s´   ù€ àˆð	(¤[ð 	(°Tö 	(ô 	ØÜ—m‘mØ$Øõ		
ð —‘×'Ñ'Ø—J‘J—M‘MØÜ˜5“>Øð	 (ó 
ˆð 	�‰˜Ÿ™Ô'Ø×Ñ˜V×2Ñ2Ô3Ø×Ñ˜&×1Ñ1Ô2Ø×Ñ˜ K =Õ1r&   c                 ó^  — dt         ddfd„}t        dt        j                  |d¬«       | j                  j                  | j                  j                  dt        d	«      d
¬«      }| j                  |j                  «       | j                  |j                  «       | j                  |j                  «       | j                  t        |j                  «      d«       | j                  |j                  d   j                   d«       | j                  |j                  d   j"                  d«       y)zFTest add_point with POST hook that fails - transaction still succeeds.r*   r+   Nc                 ó   — t        d«      ‚)NzPOST hook failed©Ú
ValueErrorrR   s    r$   Úfailing_post_hookzYTestWalletServiceWithHooks.test_add_point_with_post_hook_error.<locals>.failing_post_hook§   s   € ÜÐ/Ó0Ð0r&   Úfailing_postr5   rU   r   r<   r=   r>   é   r   ÚHOOK_EXECUTION_ERROR)r
   r	   r   rw   r!   rD   r   rE   r   rF   rG   rH   rI   rx   rL   ÚlenÚ	hook_namerK   ©r#   r~   rM   s      r$   Ú#test_add_point_with_post_hook_errorz>TestWalletServiceWithHooks.test_add_point_with_post_hook_error¥   sü   € ð	1¤{ð 	1°tó 	1ô 	ØÜ—m‘mØ&Øõ		
ð —‘×'Ñ'Ø—J‘J—M‘MØÜ˜5“>Øð	 (ó 
ˆð 	�‰˜Ÿ™Ô'Ø×Ñ˜V×2Ñ2Ô3ð 	×Ñ˜V×4Ñ4Ô5Ø×Ñœ˜V×4Ñ4Ó5°qÔ9Ø×Ñ˜×0Ñ0°Ñ3×=Ñ=¸~ÔNØ×Ñ˜×0Ñ0°Ñ3×>Ñ>Ð@VÕWr&   c                 ó   ‡— g Šdt         dt        fˆfd„}dt         dt        fˆfd„}dt         dt        fˆfd„}t        dt        j                  |dd¬	«       t        d
t        j                  |dd¬	«       t        dt        j                  |dd¬	«       | j
                  j                  | j                  j                  dt        d«      d¬«      }| j                  |j                  «       | j                  ‰g d¢«       y)z>Test add_point with multiple hooks executed in priority order.r*   r+   c                 ó(   •— ‰j                  d«       y)NÚlow_priorityT©r0   r2   s    €r$   Úhook_low_priorityzaTestWalletServiceWithHooks.test_add_point_with_multiple_hooks_priority.<locals>.hook_low_priorityÆ   s   ø€ Ø�O‰O˜NÔ+Ør&   c                 ó(   •— ‰j                  d«       y)NÚhigh_priorityTr‰   r2   s    €r$   Úhook_high_priorityzbTestWalletServiceWithHooks.test_add_point_with_multiple_hooks_priority.<locals>.hook_high_priorityÊ   s   ø€ Ø�O‰O˜OÔ,Ør&   c                 ó(   •— ‰j                  d«       y)NÚmedium_priorityTr‰   r2   s    €r$   Úhook_medium_priorityzdTestWalletServiceWithHooks.test_add_point_with_multiple_hooks_priority.<locals>.hook_medium_priorityÎ   s   ø€ Ø�O‰OÐ-Ô.Ør&   Úlowr5   rb   ©r;   Úhighé
   Úmediumr6   r   r<   zTest priorityr>   )rŒ   r�   rˆ   N©r
   rB   r	   r   rC   r!   rD   r   rE   r   rF   rG   rL   )r#   rŠ   r�   r�   rM   r3   s        @r$   Ú+test_add_point_with_multiple_hooks_priorityzFTestWalletServiceWithHooks.test_add_point_with_multiple_hooks_priorityÂ   sØ   ø€ àˆð	¤{ð 	´tõ 	ð	¬ð 	¼õ 	ð	¬+ð 	¼$õ 	ô
 	�eœXŸ\™\Ð+<¸eÈcÕRÜ�fœhŸl™lÐ,>ÀÐPRÕSÜ�h¤§¡Ð.BÀEÐTWÕXà—‘×'Ñ'Ø—J‘J—M‘MØÜ˜5“>Ø#ð	 (ó 
ˆð 	�‰˜Ÿ™Ô'à×Ñ˜Ò#WÕXr&   c                 ó²  ‡— | j                   j                  | j                  j                  dt	        d«      d«       g Šdt
        dt        fˆfd„}t        dt        j                  |d¬	«       | j                   j                  | j                  j                  dt	        d
«      d¬«      }| j                  |j                  «       | j                  ‰dg«       y)z8Test deduct_point with PRE hook that allows transaction.r   rQ   úInitial balancer*   r+   c                 óX   •— ‰j                  d«       | j                  | j                  k\  S )Nr-   )r0   Úcurrent_balancer1   r2   s    €r$   Úcheck_balancezYTestWalletServiceWithHooks.test_deduct_point_with_pre_hook_success.<locals>.check_balanceï   s$   ø€ Ø�O‰O˜JÔ'à×*Ñ*¨g¯n©nÑ<Ð<r&   rœ   ÚdeductrU   r<   úTest deductr>   r-   N)r!   rD   r   rE   r   r
   rB   r	   r   rC   Údeduct_pointrF   rG   rL   )r#   rœ   rM   r3   s      @r$   Ú'test_deduct_point_with_pre_hook_successzBTestWalletServiceWithHooks.test_deduct_point_with_pre_hook_successæ   s¸   ø€ ð 	�‰×ÑØ�J‰J�M‰M˜6¤7¨5£>Ð3Dô	
ð ˆð	=¤;ð 	=´4õ 	=ô
 	Ø Ü—l‘lØ"Øõ		
ð —‘×*Ñ*Ø—J‘J—M‘MØÜ˜5“>Ø!ð	 +ó 
ˆð 	�‰˜Ÿ™Ô'Ø×Ñ˜ J <Õ0r&   c                 óP  — | j                   j                  | j                  j                  dt	        d«      d«       dt
        dt        fd„}t        dt        j                  |d¬	«       | j                   j                  | j                  j                  dt	        d
«      d¬«      }| j                  |j                  «       | j                  |j                  d«       | j                  j!                  | j                  j                  d«      }| j                  |t	        d«      «       y)z9Test deduct_point with PRE hook that rejects transaction.r   rQ   r™   r*   r+   c                 ó|   — | j                   t        d«      kD  r$t        dddt        | j                   «      dœ¬«      ‚y)NÚ200ÚAMOUNT_TOO_LARGEzDeduction amount too largeéÈ   )Úmaxrd   re   Trh   rR   s    r$   Úreject_large_deductionszeTestWalletServiceWithHooks.test_deduct_point_with_pre_hook_rejection.<locals>.reject_large_deductions  s;   € Ø�~‰~¤¨£Ò.Ü(Ø1Ø8Ø$'´e¸G¿N¹NÓ6KÑLôð ð
 r&   Úlimit_deductionr�   rU   Ú300zLarge deductionr>   r¤   N)r!   rD   r   rE   r   r
   rB   r	   r   rC   rŸ   rY   rG   rL   rK   r    r[   )r#   r§   rM   r\   s       r$   Ú)test_deduct_point_with_pre_hook_rejectionzDTestWalletServiceWithHooks.test_deduct_point_with_pre_hook_rejection  sé   € ð 	�‰×ÑØ�J‰J�M‰M˜6¤7¨5£>Ð3Dô	
ð	¬[ð 	¼Tó 	ô 	Ø"Ü—l‘lØ,Øõ		
ð —‘×*Ñ*Ø—J‘J—M‘MØÜ˜5“>Ø%ð	 +ó 
ˆð 	×Ñ˜Ÿ™Ô(Ø×Ñ˜×*Ñ*Ð,>Ô?à—/‘/×2Ñ2°4·:±:·=±=À&ÓIˆØ×Ñ˜¤'¨%£.Õ1r&   c                 ó   — | j                   j                  | j                  j                  dt	        d«      d¬«      }| j                  |j                  «       | j                  |j                  d«       | j                  |j                  «       y)zFTest deduct_point with insufficient balance returns TransactionResult.r   r<   ÚInsufficientr>   ÚINSUFFICIENT_BALANCEN)r!   rŸ   r   rE   r   rY   rG   rL   rK   rH   rl   )r#   rM   s     r$   Ú5test_deduct_point_insufficient_balance_returns_resultzPTestWalletServiceWithHooks.test_deduct_point_insufficient_balance_returns_result)  st   € ð —‘×*Ñ*Ø—J‘J—M‘MØÜ˜5“>Ø"ð	 +ó 
ˆð 	×Ñ˜Ÿ™Ô(Ø×Ñ˜×*Ñ*Ð,BÔCØ×Ñ˜V×1Ñ1Õ2r&   c                 óª  ‡— | j                   j                  | j                  j                  dt	        d«      d«       g Šdt
        ddfˆfd„}t        dt        j                  |d	¬
«       | j                   j                  | j                  j                  dt	        d«      d¬«      }| j                  |j                  «       | j                  ‰dg«       y)z!Test deduct_point with POST hook.r   rQ   r™   r*   r+   Nc                 ó(   •— ‰j                  d«       y )NÚnotification_sentr‰   r2   s    €r$   Úsend_notificationzVTestWalletServiceWithHooks.test_deduct_point_with_post_hook.<locals>.send_notificationA  s   ø€ Ø�O‰OÐ/Õ0r&   Únotifyr�   rU   r<   rž   r>   r±   )r!   rD   r   rE   r   r
   r	   r   rw   rŸ   rF   rG   rL   )r#   r²   rM   r3   s      @r$   Ú test_deduct_point_with_post_hookz;TestWalletServiceWithHooks.test_deduct_point_with_post_hook8  sº   ø€ ð 	�‰×ÑØ�J‰J�M‰M˜6¤7¨5£>Ð3Dô	
ð ˆð	1¤{ð 	1°tõ 	1ô 	ØÜ—m‘mØ&Øõ		
ð —‘×*Ñ*Ø—J‘J—M‘MØÜ˜5“>Ø!ð	 +ó 
ˆð 	�‰˜Ÿ™Ô'Ø×Ñ˜Ð$7Ð#8Õ9r&   c           	      ó  ‡— | j                   j                  | j                  j                  dt	        d«      d«       g Šdt
        dt        fˆfd„}t        dt        j                  |d¬	«       | j                   j                  | j                  j                  d| j                  j                  dt	        d
«      d¬«      }| j                  |d   «       | j                  |j                  d«      «       | j                  ‰dg«       y)z;Test transfer_points with PRE hook that allows transaction.r   rQ   r™   r*   r+   c                 óV   •— ‰j                  d«       | j                  t        d«      k  S )Nr-   r©   r/   r2   s    €r$   Úcheck_transfer_limitz\TestWalletServiceWithHooks.test_transfer_with_pre_hook_success.<locals>.check_transfer_limitc  s"   ø€ Ø�O‰O˜JÔ'à—>‘>¤G¨E£NÑ2Ð2r&   Útransfer_limitÚtransferrU   r£   úTest transfer©Úfrom_user_idÚfrom_point_typeÚ
to_user_idÚto_point_typer1   rA   rG   Úerrorr-   N)r!   rD   r   rE   r   r
   rB   r	   r   rC   Útransfer_pointsr   rF   rJ   rs   rL   )r#   r·   rM   r3   s      @r$   Ú#test_transfer_with_pre_hook_successz>TestWalletServiceWithHooks.test_transfer_with_pre_hook_successZ  sÞ   ø€ ð 	�‰×ÑØ�J‰J�M‰M˜6¤7¨5£>Ð3Dô	
ð ˆð	3¬+ð 	3¼$õ 	3ô
 	Ø!Ü—l‘lØ)Ø õ		
ð —‘×-Ñ-ØŸ™Ÿ™Ø"Ø—z‘z—}‘}Ø Ü˜5“>Ø#ð .ó 
ˆð 	�‰˜˜yÑ)Ô*Ø×Ñ˜&Ÿ*™* WÓ-Ô.Ø×Ñ˜ J <Õ0r&   c           	      óü  — | j                   j                  | j                  j                  dt	        d«      d«       dt
        dt        fd„}t        dt        j                  |d¬	«       | j                   j                  | j                  j                  d| j                  j                  dt	        d
«      d¬«      }| j                  |d   «       | j                  |d   d   d«       | j                  j                  | j                  j                  d«      }| j                  j                  | j                  j                  d«      }| j                  |t	        d«      «       | j                  |t	        d«      «       y)z<Test transfer_points with PRE hook that rejects transaction.r   rQ   r™   r*   r+   c                 óT   — | j                   t        d«      kD  rt        ddddi¬«      ‚y)NÚ400ÚSUSPICIOUS_TRANSFERz%Transfer amount flagged as suspiciousÚmax_safei�  re   T)r1   r   r   rR   s    r$   Úblock_suspicious_transferzcTestWalletServiceWithHooks.test_transfer_with_pre_hook_rejection.<locals>.block_suspicious_transferƒ  s2   € à�~‰~¤¨£Ò.Ü(Ø4ØCØ'¨Ð-ôð ð
 r&   Úfraud_checkr¹   rU   Ú450zSuspicious transferr»   rG   rÀ   ÚcoderÆ   rX   N)r!   rD   r   rE   r   r
   rB   r	   r   rC   rÁ   r   rY   rL   r    r[   )r#   rÈ   rM   Úbalance1Úbalance2s        r$   Ú%test_transfer_with_pre_hook_rejectionz@TestWalletServiceWithHooks.test_transfer_with_pre_hook_rejection|  s-  € ð 	�‰×ÑØ�J‰J�M‰M˜6¤7¨5£>Ð3Dô	
ð	¬{ð 	¼tó 	ô 	ØÜ—l‘lØ.Ø õ		
ð —‘×-Ñ-ØŸ™Ÿ™Ø"Ø—z‘z—}‘}Ø Ü˜5“>Ø)ð .ó 
ˆð 	×Ñ˜ 	Ñ*Ô+Ø×Ñ˜ ™¨Ñ0Ð2GÔHà—?‘?×3Ñ3°D·J±J·M±MÀ6ÓJˆØ—?‘?×3Ñ3°D·J±J·M±MÀ6ÓJˆØ×Ñ˜¤7¨5£>Ô2Ø×Ñ˜¤7¨3£<Õ0r&   c           	      óÌ  ‡ ‡— ‰ j                   j                  ‰ j                  j                  dt	        d«      d«       g Šdt
        ddfˆˆ fd„}t        dt        j                  |d	¬
«       ‰ j                   j                  ‰ j                  j                  d‰ j                  j                  dt	        d«      d¬«      }‰ j                  |d   «       ‰ j                  ‰dg«       y)z$Test transfer_points with POST hook.r   rQ   r™   r*   r+   Nc                 óÀ   •— ‰j                  d«       ‰j                  | j                  d«       ‰j                  | j                  ‰j                  j
                  «       y )NÚloggedr¹   )r0   rL   r:   r¾   r   rE   )r*   r3   r#   s    €€r$   Úlog_transferzMTestWalletServiceWithHooks.test_transfer_with_post_hook.<locals>.log_transfer®  sC   ø€ Ø�O‰O˜HÔ%à×Ñ˜W×.Ñ.°
Ô;Ø×Ñ˜W×/Ñ/°·±·±Õ?r&   rÒ   r¹   rU   r£   rº   r»   rG   rÑ   )r!   rD   r   rE   r   r
   r	   r   rw   rÁ   r   rF   rL   )r#   rÒ   rM   r3   s   `  @r$   Útest_transfer_with_post_hookz7TestWalletServiceWithHooks.test_transfer_with_post_hook¥  sÊ   ù€ ð 	�‰×ÑØ�J‰J�M‰M˜6¤7¨5£>Ð3Dô	
ð ˆð	@¤+ð 	@°$ö 	@ô 	ØÜ—m‘mØ!Ø õ		
ð —‘×-Ñ-ØŸ™Ÿ™Ø"Ø—z‘z—}‘}Ø Ü˜5“>Ø#ð .ó 
ˆð 	�‰˜˜yÑ)Ô*Ø×Ñ˜ H :Õ.r&   c           	      ó.  — | j                   j                  | j                  j                  dt	        d«      d«       dt
        ddfd„}t        dt        j                  |d	¬
«       | j                   j                  | j                  j                  d| j                  j                  dt	        d«      d¬«      }| j                  |d   «       | j                  d|«       | j                  t        |d   «      d«       | j                  |d   d   d   d«       y)zGTest transfer_points with POST hook error - transaction still succeeds.r   rQ   r™   r*   r+   Nc                 ó   — t        d«      ‚)NzFailed to send notificationr|   rR   s    r$   r~   zXTestWalletServiceWithHooks.test_transfer_with_post_hook_error.<locals>.failing_post_hookÎ  s   € ÜÐ:Ó;Ð;r&   Únotify_failedr¹   rU   r£   rº   r»   rG   Úwarningsr€   r   Úhook)r!   rD   r   rE   r   r
   r	   r   rw   rÁ   r   rF   rZ   rL   r‚   r„   s      r$   Ú"test_transfer_with_post_hook_errorz=TestWalletServiceWithHooks.test_transfer_with_post_hook_errorÇ  sö   € ð 	�‰×ÑØ�J‰J�M‰M˜6¤7¨5£>Ð3Dô	
ð	<¤{ð 	<°tó 	<ô 	Ø Ü—m‘mØ&Ø õ		
ð —‘×-Ñ-ØŸ™Ÿ™Ø"Ø—z‘z—}‘}Ø Ü˜5“>Ø#ð .ó 
ˆð 	�‰˜˜yÑ)Ô*ð 	�‰�j &Ô)Ø×Ñœ˜V JÑ/Ó0°!Ô4Ø×Ñ˜ 
Ñ+¨AÑ.¨vÑ6¸ÕHr&   c                 ó¢  ‡ ‡— g Šdt         dt        fˆfd„}dt         dt        fˆˆ fd„}t        dt        j                  |dd¬«       t        d	t        j                  |dd
¬«       ‰ j
                  j                  ‰ j                  j                  dt        d«      d«      }‰ j                  |j                  «       ‰ j                  ‰dd	g«       y)z,Test that hooks can share data via metadata.r*   r+   c                 óF   •— d| j                   d<   ‰j                  d«       y)NÚprocessed_by_hook1Ú
hook1_dataÚhook1T)rr   r0   r2   s    €r$   rÞ   zQTestWalletServiceWithHooks.test_hooks_can_communicate_via_metadata.<locals>.hook1ñ  s"   ø€ Ø-AˆG×Ñ˜\Ñ*Ø�O‰O˜GÔ$Ør&   c                 ó‚   •— | j                   j                  d«      }‰j                  |d«       ‰j                  d«       y)NrÝ   rÜ   Úhook2T)rr   rs   rL   r0   )r*   Údatar3   r#   s     €€r$   rà   zQTestWalletServiceWithHooks.test_hooks_can_communicate_via_metadata.<locals>.hook2ö  s9   ø€ à×#Ñ#×'Ñ'¨Ó5ˆDØ×Ñ˜TÐ#7Ô8Ø�O‰O˜GÔ$Ør&   rÞ   r5   r”   r’   rà   é   r   r<   zTest metadataNr–   )r#   rÞ   rà   rM   r3   s   `   @r$   Ú'test_hooks_can_communicate_via_metadatazBTestWalletServiceWithHooks.test_hooks_can_communicate_via_metadataí  s¨   ù€ àˆð	œ;ð 	¬4õ 	ð
	œ;ð 	¬4ö 	ô 	�gœxŸ|™|¨U°EÀBÕGÜ�gœxŸ|™|¨U°EÀBÕGà—‘×'Ñ'Ø�J‰J�M‰M˜6¤7¨5£>°?ó
ˆð 	�‰˜Ÿ™Ô'Ø×Ñ˜ G¨WÐ#5Õ6r&   c           	      ó   ‡— g Šdt         dt        fˆfd„}t        dt        j                  |d¬«       | j
                  j                  | j                  j                  dt        d«      d	«       | j
                  j                  | j                  j                  dt        d
«      d«       | j
                  j                  | j                  j                  | j                  j                  ddt        d«      d¬«      }| j                  ‰g d¢«       y)z5Test that global hooks ('*') apply to all operations.r*   r+   c                 ó<   •— ‰j                  | j                  «       y)NT)r0   r:   r2   s    €r$   Úglobal_hookzZTestWalletServiceWithHooks.test_global_hook_applies_to_all_operations.<locals>.global_hook  s   ø€ Ø�O‰O˜G×-Ñ-Ô.Ør&   ÚglobalÚ*rU   r   r<   r=   Ú50rž   Ú20rº   )r¼   r¾   r½   r¿   r1   rA   )r5   r�   r¹   N)r
   rB   r	   r   rC   r!   rD   r   rE   r   rŸ   rÁ   r   rL   )r#   ræ   rM   r3   s      @r$   Ú*test_global_hook_applies_to_all_operationszETestWalletServiceWithHooks.test_global_hook_applies_to_all_operations  sÛ   ø€ àˆð	¤ð 	´õ 	ô 	ØÜ—l‘lØ Øõ		
ð 	�‰×ÑØ�J‰J�M‰M˜6¤7¨5£>°:ô	
ð
 	�‰×!Ñ!Ø�J‰J�M‰M˜6¤7¨4£=°-ô	
ð
 —‘×-Ñ-ØŸ™Ÿ™Ø—z‘z—}‘}Ø"Ø Ü˜4“=Ø#ð .ó 
ˆð 	×Ñ˜Ò#@ÕAr&   c                 ó^  — t        t        | j                  ¬«      }t        |d¬«      }dt        dt
        fd„}t        dt        j                  |d«       |j                  | j                  j                  d	t        d
«      d«      }| j                  |t        «       | j                  |d«       y)zJTest that with hooks disabled, service returns int (backwards compatible).r   Fr   r*   r+   c                 ó   — t        d«      ‚)NzThis should not be called)Ú	ExceptionrR   s    r$   Úshould_not_runzjTestWalletServiceWithHooks.test_service_with_hooks_disabled_returns_transaction_id.<locals>.should_not_run>  s   € ÜÐ7Ó8Ð8r&   Úunusedr5   r   r<   ÚTestr   N)r   r   r   r   r
   rB   r	   r   rC   rD   r   rE   r   ÚassertIsInstanceÚintÚassertGreater)r#   Úrepo_no_hooksÚservice_no_hooksrï   rM   s        r$   Ú7test_service_with_hooks_disabled_returns_transaction_idzRTestWalletServiceWithHooks.test_service_with_hooks_disabled_returns_transaction_id4  s—   € ô )ÜØ×(Ñ(ô
ˆô )¨ÀUÔKÐð	9¤Kð 	9´Dó 	9ô 	�h¤§¡¨n¸eÔDà!×+Ñ+Ø�J‰J�M‰M˜6¤7¨5£>°6ó
ˆð
 	×Ñ˜f¤cÔ*Ø×Ñ˜6 1Õ%r&   c                 ó2  — | j                   j                  | j                  j                  dt	        d«      d«      }|j                  «       }| j                  |d   «       | j                  |d   «       | j                  d|«       | j                  d|«       y)	z3Test TransactionResult.to_dict() for API responses.r   r<   rñ   rG   rI   rÀ   r×   N)	r!   rD   r   rE   r   Úto_dictrF   rH   ÚassertNotIn)r#   rM   Úresult_dicts      r$   Ú%test_to_dict_method_for_api_responsesz@TestWalletServiceWithHooks.test_to_dict_method_for_api_responsesK  s~   € à—‘×'Ñ'Ø�J‰J�M‰M˜6¤7¨5£>°6ó
ˆð —n‘nÓ&ˆà�‰˜ IÑ.Ô/Ø×Ñ˜[Ð)9Ñ:Ô;Ø×Ñ˜ +Ô.Ø×Ñ˜ [Õ1r&   c                 óØ  — dt         dt        fd„}t        dt        j                  |d«       | j
                  j                  | j                  j                  dt        d«      d«      }|j                  «       }| j                  |d	   «       | j                  |d
   «       | j                  |d   d   d«       | j                  |d   d   d«       | j                  |d   d   d   d«       y)z6Test TransactionResult.to_dict() with rejection error.r*   r+   c                 ó"   — t        ddddi¬«      ‚)NÚ
TEST_ERRORúTest rejectionÚkeyÚvaluere   r   rR   s    r$   Úreject_hookzQTestWalletServiceWithHooks.test_to_dict_with_rejection_error.<locals>.reject_hookZ  s   € Ü$Ø'Ø(Ø Ð(ôð r&   Úrejectr5   r   r<   rñ   rG   rI   rÀ   rË   rÿ   rf   r   rg   r  r  N)r
   rB   r	   r   rC   r!   rD   r   rE   r   rù   rY   rJ   rL   )r#   r  rM   rû   s       r$   Ú!test_to_dict_with_rejection_errorz<TestWalletServiceWithHooks.test_to_dict_with_rejection_errorX  sÛ   € ð	¤ð 	´ó 	ô 	�h¤§¡¨k¸5ÔAà—‘×'Ñ'Ø�J‰J�M‰M˜6¤7¨5£>°6ó
ˆð —n‘nÓ&ˆà×Ñ˜ YÑ/Ô0Ø×Ñ˜+Ð&6Ñ7Ô8Ø×Ñ˜ WÑ-¨fÑ5°|ÔDØ×Ñ˜ WÑ-¨iÑ8Ð:JÔKØ×Ñ˜ WÑ-¨iÑ8¸Ñ?ÀÕIr&   c                 ó  — dt         ddfd„}t        dt        j                  |d«       | j                  j                  | j                  j                  dt        d«      d	«      }|j                  «       }| j                  |d
   «       | j                  |d   «       | j                  d|«       | j                  t        |d   «      d«       | j                  |d   d   d   d«       | j                  |d   d   d   d«       y)z9Test TransactionResult.to_dict() with POST hook warnings.r*   r+   Nc                 ó   — t        d«      ‚)NzPOST failedr|   rR   s    r$   r   zUTestWalletServiceWithHooks.test_to_dict_with_post_hook_warnings.<locals>.failing_postq  s   € Ü˜]Ó+Ð+r&   Úfailr5   r   r<   rñ   rG   rI   r×   r€   r   rØ   rË   r�   )r
   r	   r   rw   r!   rD   r   rE   r   rù   rF   rH   rZ   rL   r‚   )r#   r   rM   rû   s       r$   Ú$test_to_dict_with_post_hook_warningsz?TestWalletServiceWithHooks.test_to_dict_with_post_hook_warningso  sì   € ð	,¤+ð 	,°$ó 	,ô 	�fœhŸm™m¨\¸5ÔAà—‘×'Ñ'Ø�J‰J�M‰M˜6¤7¨5£>°6ó
ˆð —n‘nÓ&ˆà�‰˜ IÑ.Ô/Ø×Ñ˜[Ð)9Ñ:Ô;Ø�‰�j +Ô.Ø×Ñœ˜[¨Ñ4Ó5°qÔ9Ø×Ñ˜ ZÑ0°Ñ3°FÑ;¸VÔDØ×Ñ˜ ZÑ0°Ñ3°FÑ;Ð=SÕTr&   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r%   r(   rN   r]   rn   ry   r…   r—   r    rª   r®   r´   rÂ   rÎ   rÓ   rÙ   rã   rë   r÷   rü   r  r	  © r&   r$   r   r      s‚   „ Ù;òò$ò1ò:0ò:Cò>2ò:Xò:YòH1ò>"2òH3ò:òD 1òD'1òR /òD IòL7ò<#BòR&ò.2òJó.Ur&   r   N)r  Údecimalr   Údjango.testr   Úwallet_utilsr   r   r   r   r	   Úwallet_utils.hooksr
   Úwallet_utils.exceptionsr   Útests.modelsr   r   r  r&   r$   Ú<module>r     s3   ðÙ ;å Ý  ÷õ õ +Ý 6Ý !ôo	U õ o	Ur&   