
    x?i)@                         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
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*  G d de      Z+ G d de      Z, G d	 d
e      Z-y)z<
Tests for transaction type constants and helper functions.
    )TestCase)transaction_types)%WALLET_DEPOSITWALLET_DEPOSIT_CANCELWALLET_TRANSFERWALLET_WITHDRAWWALLET_WITHDRAW_REFUNDWALLET_ADJUSTWALLET_TOPUPWALLET_DEDUCTPACKAGE_ACTIVATIONPACKAGE_ACTIVATION_CANCELPACKAGE_UPGRADEPACKAGE_UPGRADE_CANCELPACKAGE_RENEWALPACKAGE_RENEWAL_CANCELPACKAGE_EXPIRY_REFUNDCOMMISSION_DISTRIBUTIONCOMMISSION_DISTRIBUTION_REVERSEROI_DISTRIBUTIONROI_DISTRIBUTION_REVERSEPRODUCT_ORDERPRODUCT_ORDER_CANCELPRODUCT_ORDER_REFUNDPRODUCT_ORDER_PARTIAL_REFUNDPRODUCT_REDEMPTIONPRODUCT_REDEMPTION_CANCELSYSTEM_ADJUSTMENTSYSTEM_REWARDSYSTEM_PENALTYSYSTEM_REVERSALSYSTEM_MIGRATION!CUSTOM_TRANSACTION_TYPE_RANGE_END#CUSTOM_TRANSACTION_TYPE_RANGE_STARTget_custom_transaction_typesget_transaction_typeget_transaction_type_name register_custom_transaction_type"unregister_custom_transaction_typec                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	TransactionTypeConstantsTestsz%Tests for transaction type constants.c                    | j                  t        d       | j                  t        d       | j                  t        d       | j                  t        d       | j                  t
        d       | j                  t        d       | j                  t        d       | j                  t        d       | j                  t        t               | j                  t        t               y	)
z Test wallet operation constants.  i  i    i  i  i  i  N)assertEqualr   r   r   r   r	   r
   r   r   assertIsInstanceintselfs    K/home/cursorai/projects/django-wallet-utils/tests/test_transaction_types.py test_wallet_operations_constantsz>TransactionTypeConstantsTests.test_wallet_operations_constants9   s    ..5$/$//6-t,- 	nc2os3    c                 8   | j                  t        d       | j                  t        d       | j                  t        d       | j                  t        d       | j                  t
        d       | j                  t        d       | j                  t        d       y)	z!Test package operation constants.  i  i  i  i  i  i  N)r/   r   r   r   r   r   r   r   r2   s    r4   !test_package_operations_constantsz?TransactionTypeConstantsTests.test_package_operations_constantsH   sw    +T22D9$//6$//6.5r6   c                     | j                  t        d       | j                  t        d       | j                  t        d       | j                  t        d       y)z&Test commission and rewards constants.  i    i  N)r/   r   r   r   r   r2   s    r4   !test_commission_rewards_constantsz?TransactionTypeConstantsTests.test_commission_rewards_constantsR   sF    0$78$?)40148r6   c                    | j                  t        d       | j                  t        d       | j                  t        d       | j                  t        d       | j                  t
        d       | j                  t        d       y)z!Test product operation constants.  i  i    i  i  N)r/   r   r   r   r   r   r   r2   s    r4   !test_product_operations_constantsz?TransactionTypeConstantsTests.test_product_operations_constantsY   sg    --t4-t45t<+T22D9r6   c                     | j                  t        d       | j                  t        d       | j                  t        d       | j                  t        d       | j                  t
        d       y)z Test system operation constants.  i  i  i  i  N)r/   r   r   r    r!   r"   r2   s    r4    test_system_operations_constantsz>TransactionTypeConstantsTests.test_system_operations_constantsb   sT    *D1-.$/)40r6   c                    | j                  t        d       | j                  t        d       | j                  t        d       | j                  t
        d       | j                  t        d       | j                  t        d       | j                  t        d       | j                  t        d       | j                  t        d       | j                  t        d       y)z+Test that constants are in expected ranges.r-   r8   r;   r?   rC   ip  N)assertGreaterEqualr   
assertLessr   r   r   r   r   r   r   r   r"   r2   s    r4   test_constant_rangesz2TransactionTypeConstantsTests.test_constant_rangesj   s     	5t, 	 2D9-t4 	 7>0$7 	t4148 	 148($/r6   N)
__name__
__module____qualname____doc__r5   r9   r=   rA   rD   rH    r6   r4   r+   r+   6   s#    /469:10r6   r+   c                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)#TransactionTypeHelperFunctionsTestsz,Tests for transaction type helper functions.c                    | j                  t        d      d       | j                  t        d      d       | j                  t        d      d       | j                  t        d      d       | j                  t        d	      d
       y)z-Test get_transaction_type() with valid names.wallet-depositr-   wallet-withdrawr.   roi-distributionr<   product-order-partial-refundr@   system-adjustmentrC   N)r/   r&   r2   s    r4   test_get_transaction_type_validzCTransactionTypeHelperFunctionsTests.test_get_transaction_type_valid   su    -.>?F-.?@$G-.@A4H-.LMtT-.ABDIr6   c                     | j                  t              5 }t        d       ddd       | j                  dt	        j
                               y# 1 sw Y   /xY w)z.Test get_transaction_type() with invalid name.zinvalid-typeNzUnknown transaction type)assertRaises
ValueErrorr&   assertInstr	exceptionr3   cms     r4   !test_get_transaction_type_invalidzETransactionTypeHelperFunctionsTests.test_get_transaction_type_invalid   sB    z*b 0 + 	0#bll2CD +*   AAc                    | j                  t        d      d       | j                  t        d      d       | j                  t        d      d       | j                  t        d      d       | j                  t        d	      d
       y)z6Test get_transaction_type_name() with valid constants.r-   rQ   r.   rR   r<   rS   r@   rT   rC   rU   N)r/   r'   r2   s    r4   $test_get_transaction_type_name_validzHTransactionTypeHelperFunctionsTests.test_get_transaction_type_name_valid   su    248:JK248:KL248:LM248:XY248:MNr6   c                     | j                  t        d             | j                  t        d             | j                  t        d             y)z7Test get_transaction_type_name() with invalid constant.韆 r   N)assertIsNoner'   r2   s    r4   &test_get_transaction_type_name_invalidzJTransactionTypeHelperFunctionsTests.test_get_transaction_type_name_invalid   s>    3E:;3A673B78r6   c                     t         j                  }| j                  d|       | j                  |d   d       | j                  d|       | j                  |d   d       y)z"Test TRANSACTION_TYPES dictionary.rQ   r-   rS   r<   N)r   TRANSACTION_TYPESrZ   r/   )r3   ri   s     r4   !test_transaction_types_dictionaryzETransactionTypeHelperFunctionsTests.test_transaction_types_dictionary   s\    -??&(9:*+;<dC(*;<*+=>Er6   c                     t         j                  }| j                  d|       | j                  |d   d       | j                  d|       | j                  |d   d       y)z'Test TRANSACTION_TYPE_NAMES dictionary.r-   rQ   r<   rS   N)r   TRANSACTION_TYPE_NAMESrZ   r/   r3   rl   s     r4   &test_transaction_type_names_dictionaryzJTransactionTypeHelperFunctionsTests.test_transaction_type_names_dictionary   sZ    !2!I!Id23/57GHd23/57IJr6   c                     t         j                  }t         j                  }|j                         D ]  \  }}| j	                  ||   |        |j                         D ]  \  }}| j	                  ||   |        y)zFTest that TRANSACTION_TYPES and TRANSACTION_TYPE_NAMES are consistent.N)r   ri   rl   itemsr/   )r3   ri   rl   name
trans_types        r4   test_dictionary_consistencyz?TransactionTypeHelperFunctionsTests.test_dictionary_consistency   sx    -??!2!I!I 1 7 7 9D*3J?F !: !7 < < >J.t4jA !?r6   c                    t         j                  }t         j                  }t        t        t
        t        t        t        g}|D ]@  }| j                  ||       ||   }| j                  ||       | j                  ||   |       B y)z0Test that all constants are in the dictionaries.N)r   ri   rl   r   r   r   r   r   r   rZ   r/   )r3   ri   rl   	constantsconstantrq   s         r4    test_all_constants_in_dictionaryzDTransactionTypeHelperFunctionsTests.test_all_constants_in_dictionary   s{    -??!2!I!IO-=}.J
	
 "HMM($:;)(3DMM$ 12.t4h?	 "r6   N)rI   rJ   rK   rL   rV   r_   rb   rg   rj   rn   rs   rw   rM   r6   r4   rO   rO      s4    6JEO9FKB@r6   rO   c                   j    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y)CustomTransactionTypeTestsz/Tests for custom transaction type registration.c                     t               }t        |j                               D ]  }	 t        |        y# t        $ r Y w xY w)z+Clean up any custom types before each test.Nr%   listkeysr)   rY   r3   custom_typesrq   s      r4   setUpz CustomTransactionTypeTests.setUp   E     45**,-D248 .     6	AAc                     t               }t        |j                               D ]  }	 t        |        y# t        $ r Y w xY w)z*Clean up any custom types after each test.Nr{   r~   s      r4   tearDownz#CustomTransactionTypeTests.tearDown   r   r   c                 \    | j                  t        d       | j                  t        d       y)z-Test custom transaction type range constants.'  iN  N)r/   r$   r#   r2   s    r4   test_custom_range_constantsz6CustomTransactionTypeTests.test_custom_range_constants   s$    <eD:EBr6   c                 d   t        dd       t        j                  }t        j                  }| j	                  d|       | j                  |d   d       | j	                  d|       | j                  |d   d       | j                  t        d      d       | j                  t        d      d       y)z+Test registering a custom transaction type.custom-rewardr   N)r(   r   ri   rl   rZ   r/   r&   r'   r3   ri   rl   s      r4   %test_register_custom_transaction_typez@CustomTransactionTypeTests.test_register_custom_transaction_type   s    (%@ .??!2!I!Io'89*?;UCe34/6H 	-o>F259?Kr6   c                     t        dd       t        dd       t        dd       | j                  t        d      d       | j                  t        d      d       | j                  t        d      d       y)z3Test registering multiple custom transaction types.r   r   custom-penalty'  zaffiliate-bonusi'  N)r(   r/   r&   r2   s    r4   #test_register_multiple_custom_typesz>CustomTransactionTypeTests.test_register_multiple_custom_types   sf    (%@()95A():EB-o>F-.>?G-.?@%Hr6   c                 p   | j                  t              5 }t        dd       ddd       | j                  dt	        j
                               | j                  t              5 }t        dd       ddd       | j                  dt	        |j
                               y# 1 sw Y   ~xY w# 1 sw Y   ;xY w)zHTest that registering a type outside the custom range raises ValueError.invalidrC   Nzmust be in rangei N  )rX   rY   r(   rZ   r[   r\   r]   s     r4   &test_register_custom_type_out_of_rangezACustomTransactionTypeTests.test_register_custom_type_out_of_range  s    z*b,Y= + 	(#bll*;<z*b,Y> + 	(#bll*;< +*
 +*s   B %B, B),B5c                     t        dd       | j                  t              5 }t        dd       ddd       | j                  dt	        j
                               y# 1 sw Y   /xY w)z9Test that registering a duplicate name raises ValueError.r   r   r   Nalready existsr(   rX   rY   rZ   r[   r\   r]   s     r4   (test_register_custom_type_duplicate_namezCCustomTransactionTypeTests.test_register_custom_type_duplicate_name  sN    (%@z*b,_eD + 	&BLL(9: +*   AA&c                     t        dd       | j                  t              5 }t        dd       ddd       | j                  dt	        j
                               y# 1 sw Y   /xY w)z:Test that registering a duplicate value raises ValueError.r   r   r   Nr   r   r]   s     r4   )test_register_custom_type_duplicate_valuezDCustomTransactionTypeTests.test_register_custom_type_duplicate_value  sO    (%@z*b,-=uE + 	&BLL(9: +*r   c                     t        dd       t        ddd       | j                  t        d      d       t        j                  }| j                  d|       y)z(Test overriding an existing custom type.r   r   r   T)overrideN)r(   r/   r&   r   rl   assertNotInrm   s     r4   "test_register_custom_type_overridez=CustomTransactionTypeTests.test_register_custom_type_override  sK    (%@(%$O-o>F!2!I!I 67r6   c                 2   t        dd       t        j                  }| j                  d|       t	        d       t        j                  }t        j
                  }| j                  d|       | j                  d|       | j                  t        d             y)z-Test unregistering a custom transaction type.r   r   N)	r(   r   ri   rZ   r)   rl   r   rf   r'   r   s      r4   'test_unregister_custom_transaction_typezBCustomTransactionTypeTests.test_unregister_custom_transaction_type(  s    (%@ .??o'89 	+?; .??!2!I!I*;< 673E:;r6   c                     | j                  t              5 }t        d       ddd       | j                  dt	        j
                               y# 1 sw Y   /xY w)z:Test that unregistering a built-in type raises ValueError.rQ   NzCannot unregister built-inrX   rY   r)   rZ   r[   r\   r]   s     r4   )test_unregister_builtin_type_raises_errorzDCustomTransactionTypeTests.test_unregister_builtin_type_raises_error:  sC    z*b./?@ + 	2C4EF +*r`   c                     | j                  t              5 }t        d       ddd       | j                  dt	        j
                               y# 1 sw Y   /xY w)z>Test that unregistering a non-existent type raises ValueError.znonexistent-typeNzis not registeredr   r]   s     r4   -test_unregister_nonexistent_type_raises_errorzHCustomTransactionTypeTests.test_unregister_nonexistent_type_raises_errorA  sC    z*b./AB + 	)3r||+<= +*r`   c                    t               }| j                  t        |      d       t        dd       t        dd       t               }| j                  t        |      d       | j	                  d|       | j	                  d|       | j                  |d   d       | j                  |d   d       d|d<   | j                  dt                      y	)
z*Test getting all custom transaction types.r   r   r   r   r      rd   testN)r%   r/   lenr(   rZ   r   )r3   r   s     r4   !test_get_custom_transaction_typesz<CustomTransactionTypeTests.test_get_custom_transaction_typesH  s     45\*A. 	)%@()95A 45\*A.o|4&5o6>&67?  %V!=!?@r6   c                 &   t        dd       | j                  t        d      d       | j                  t        d      d       | j	                  t
              5  t        d       ddd       | j                  t        d             y# 1 sw Y   $xY w)z2Test that custom types work with helper functions.r   r   znonexistent-customNrd   )r(   r/   r&   r'   rX   rY   rf   r2   s    r4   ,test_custom_types_work_with_helper_functionszGCustomTransactionTypeTests.test_custom_types_work_with_helper_functions^  sy    (%@ 	-o>F 	259?K z* !56 + 	3E:;	 +*s   BBc                     t        d      }t        dd       | j                  t        d      |       | j                  t        d      t               y)zDTest that built-in types remain unchanged after custom registration.rQ   r   r   N)r&   r(   r/   r   )r3   original_wallet_deposits     r4   6test_builtin_types_unchanged_after_custom_registrationzQCustomTransactionTypeTests.test_builtin_types_unchanged_after_custom_registrationo  sI    "67G"H(%@ 	-.>?AXY-.>?Pr6   N)rI   rJ   rK   rL   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r6   r4   ry   ry      sV    9C
L I
=;;8<$G>A,<"Qr6   ry   N).rL   django.testr   wallet_utilsr   wallet_utils.transaction_typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r+   rO   ry   rM   r6   r4   <module>r      su    ! *, , , , , , , , , ,^H0H H0VG@( G@TlQ lQr6   