
    S>i'                     t    d 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  G d de      Z G d	 d
e      Zy)z 
Tests for wallet_utils models.
    )Decimal)TestCase)ValidationError)AbstractWalletTransactionWalletTransaction)TestUserc                   X    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y)WalletTransactionModelTestsz"Tests for WalletTransaction model.c           
         t         j                  j                  ddddt        d      t        d      dd      }| j	                  |j
                         | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  t        d             | j                  |j                  t        d             | j                  |j                  d       | j                  |j                  d       y	)
z#Test creating a transaction record.credit_balance{   c100.00  zTest transaction)wtypeiiduidtypeamountbalance
trans_typedescrN)r   objectscreater   assertIsNotNoneidassertEqualr   r   r   r   r   r   r   r   selftransactions     G/home/cursorai/projects/django-wallet-utils/tests/test_wallet_models.pytest_create_transactionz3WalletTransactionModelTests.test_create_transaction   s   '//66"8$H%$ 7 	
 	[^^,**,<=$/#.))3/++WX->?,,gh.?@//6**,>?    c           
      P   t         j                  j                  ddddt        d      t        d            }| j	                  |j
                  d       t         j                  j                  ddddt        d      t        d            }| j	                  |j
                  d       y	)
z$Test transaction type field choices.r   r   r   r   r   r   r   r   r   r   r   dz50.00N)r   r   r   r   r   r   )r    
credit_txn	debit_txns      r"   test_transaction_type_choicesz9WalletTransactionModelTests.test_transaction_type_choices&   s     '..55"8$H% 6 

 	#. &--44"7#G$ 5 
	 	-r$   c                     t         j                  j                  ddddt        d      t        d      ddd	      }| j	                  |j
                  d
   d       | j	                  |j
                  d   d       y)zTest extra_data JSONField.r   r   r   r   r   i90  bank)
payment_idsource)r   r   r   r   r   r   
extra_datar-   r.   Nr   r   r   r   r   r/   r   s     r"   test_transaction_extra_dataz7WalletTransactionModelTests.test_transaction_extra_data>   sy    '//66"8$H%&+v> 7 
 	//=uE//96Br$   c           
          t         j                  j                  ddddt        d      t        d            }| j	                  |j
                  i        y)zTest extra_data default value.r   r   r   r   r   r&   Nr0   r   s     r"   #test_transaction_extra_data_defaultz?WalletTransactionModelTests.test_transaction_extra_data_defaultM   sQ    '//66"8$H% 7 
 	//4r$   c           
          t         j                  j                  ddddt        d      t        d            }| j	                  |j
                  d       y)	zTest descr default value.r   r   r   r   r   r&    N)r   r   r   r   r   r   r   s     r"   test_transaction_descr_defaultz:WalletTransactionModelTests.test_transaction_descr_defaultZ   sQ    '//66"8$H% 7 
 	**B/r$   c           
          t         j                  j                  ddddt        d      t        d      d      }| j	                  |j
                         y)zTest trans_type can be None.r   r   r   r   r   N)r   r   r   r   r   r   r   )r   r   r   r   assertIsNoner   r   s     r"   $test_transaction_trans_type_nullablez@WalletTransactionModelTests.test_transaction_trans_type_nullableg   sR    '//66"8$H% 7 
 	+001r$   c           
         ddl }t        j                  j                  ddddt	        d      t	        d            }|j                  d	       t        j                  j                  ddddt	        d
      t	        d
            }t        t        j                  j                               }| j                  |d   j                  |j                         | j                  |d   j                  |j                         y)z%Test default ordering (newest first).r   Nr   r   r   r   r   r&   g{Gz?z200.00   )
timer   r   r   r   sleeplistallr   r   )r    r<   txn1txn2transactionss        r"   test_transaction_orderingz5WalletTransactionModelTests.test_transaction_orderingu   s     	 ((//"8$H% 0 
 	

4 ((//"8$H% 0 
 -5599;<a++TWW5a++TWW5r$   c           
         t         j                  j                  ddddt        d      t        d            }t	        |      }| j                  d|       | j                  d|       | j                  d|       | j                  d|       y	)
zTest __str__ method.r   r   r   r   r   r&   C123N)r   r   r   r   strassertIn)r    r!   str_reprs      r"   &test_transaction_string_representationzBWalletTransactionModelTests.test_transaction_string_representation   s~    '//66"8$H% 7 
 {#c8$h)&1eX&r$   c           
         t         j                  j                  ddddt        d      t        d            }| j	                  |j
                  t        d             | j	                  |j                  t        d             y)z2Test decimal precision (default 2 decimal places).r   r   r   r   z100.99r&   N)r   r   r   r   r   r   r   r   s     r"   "test_transaction_decimal_precisionz>WalletTransactionModelTests.test_transaction_decimal_precision   sq    '//66"8$H% 7 
 	++WX->?,,gh.?@r$   c           
          t         j                  j                  ddddt        d      t        d            }| j	                  |j
                  d       | j                  |j                         y)z)Test using system user ID (-100) for uid.r   r   r   r   r&   N)r   r   r   r   r   r   r   r   r   s     r"   test_transaction_system_user_idz;WalletTransactionModelTests.test_transaction_system_user_id   sa    '//66"8$H% 7 
 	$/[^^,r$   c                    t        d      D ]9  }t        j                  j                  dd|dt	        d      t	        d             ; t        j                  j                  d      }| j                  |j                         d	       t        j                  j                  d
      }| j                  |j                         d       t        j                  j                  d      }| j                  |j                         d       y)zITest that indexes are created (indirectly by checking query performance).
   r   r   r   r   r&      )r   r;   )r   r   )r   r   N)ranger   r   r   r   filterr   count)r    irB   s      r"   test_transaction_indexesz4WalletTransactionModelTests.test_transaction_indexes   s     rA%%,,&x() -   )0077A7>++-q1 )0077>N7O++-r2 )007747H++-q1r$   c                    dD ]@  }dD ]9  }t         j                  j                  |d|dt        d      t        d             ; B t         j                  j	                  dd	      }| j                  |j                         d       y
)zTest composite indexes.)r;         )r   reward_pointsr   r   r   r&   r;   r   )r   r   N)r   r   r   r   rS   r   rT   )r    r   r   rB   s       r"   "test_transaction_composite_indexesz>WalletTransactionModelTests.test_transaction_composite_indexes   s     C<!))00"8,#H- 1  =  )0077AEU7V++-q1r$   N)__name__
__module____qualname____doc__r#   r*   r1   r3   r6   r9   rC   rJ   rL   rN   rV   r[    r$   r"   r
   r
      sD    ,@..0C5026<'"A-222r$   r
   c                   "    e Zd ZdZd Zd Zd Zy)AbstractWalletTransactionTestsz*Tests for AbstractWalletTransaction model.c                 V    | j                  t        j                  j                         y)zKTest that AbstractWalletTransaction is abstract and doesn't create a table.N)
assertTruer   _metaabstract)r    s    r"   %test_abstract_model_not_creates_tablezDAbstractWalletTransactionTests.test_abstract_model_not_creates_table   s    177@@Ar$   c                    ddl m}  G d dt              }| j                  |j                  j
                         | j                  t        |d             | j                  t        |d             | j                  t        |d             | j                  t        |d             | j                  t        |d	             | j                  t        |d
             y)zATest creating a custom model extending AbstractWalletTransaction.r   modelsc                   :    e Zd ZdZ G d dej
                        Zy)\AbstractWalletTransactionTests.test_custom_model_extends_abstract.<locals>.CustomTransactionzCustom transaction model.c                       e Zd ZdZy)aAbstractWalletTransactionTests.test_custom_model_extends_abstract.<locals>.CustomTransaction.Metacustom_transactionsNr\   r]   r^   db_tabler`   r$   r"   Metarn      s    0r$   rr   N)r\   r]   r^   r_   r   rr   r`   r$   r"   CustomTransactionrl      s    +1055 1r$   rs   r   r   r   r   r   r   N)	django.dbrj   r   assertFalsere   rf   rd   hasattr)r    rj   rs   s      r"   "test_custom_model_extends_abstractzAAbstractWalletTransactionTests.test_custom_model_extends_abstract   s    $	1 9 	1 	*0099: 	 17;< 159: 159: 16:; 18<= 19=>r$   c                    ddl m  G fddt              }|j                  j	                  d      }| j                  |j                  d       |j                  j	                  d      }| j                  |j                  d       y)	z0Test custom model with different decimal places.r   ri   c                       e Zd ZdZW  j	                  dd      ZW  j	                  dd      Z G d dej                        Zy)aAbstractWalletTransactionTests.test_custom_model_custom_decimal_places.<locals>.CustomTransactionz/Custom transaction model with 8 decimal places.      )
max_digitsdecimal_placesc                       e Zd ZdZy)fAbstractWalletTransactionTests.test_custom_model_custom_decimal_places.<locals>.CustomTransaction.Metacustom_transactions_8dpNrp   r`   r$   r"   rr   r     s    4r$   rr   N)	r\   r]   r^   r_   DecimalFieldr   r   r   rr   ri   s   r"   rs   rz     sC    A((Bq(IF))R)JG5055 5r$   rs   r   r|   r   N)rt   rj   r   re   	get_fieldr   r~   )r    rs   amount_fieldbalance_fieldrj   s       @r"   'test_custom_model_custom_decimal_placeszFAbstractWalletTransactionTests.test_custom_model_custom_decimal_places  sm    $	5 9 	5 )..88B44a8)//99)D55q9r$   N)r\   r]   r^   r_   rg   rw   r   r`   r$   r"   rb   rb      s    4B?(:r$   rb   N)r_   decimalr   django.testr   django.core.exceptionsr   wallet_utils.modelsr   r   tests.modelsr   r
   rb   r`   r$   r"   <module>r      s6       2 L !^2( ^2B,:X ,:r$   