
    ¹;j                         d dl Zd dlmc mZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ dedefdZded	ed
edefdZded	ed
edededefdZd Zd Zd Zd ZdS )    N)
TestClient)init_db)app)admin_headersclientreturnc                     |                      d                                          d         d         d         d         S )Nz/api/dashboard?date=2026-06-23childrenr   childid)getjson)r   s    P/home/agent/projects/FamilyDashboard/backend/tests/test_admin_coin_management.py	_child_idr      s6    ::677<<>>zJ1MgVW[\\    headerschild_idc                    |                      d| d|          }|j        }d}||k    }|st          j        d|fd||f          dt	          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          dz  }t          j        |j	                  d	z   d
|iz  }t          t          j        |                    d x}x}}|                                S )N/api/admin/coins/z/ledger)r      ==z3%(py2)s
{%(py2)s = %(py0)s.status_code
} == %(py5)sresponsepy0py2py5
>assert %(py7)spy7)r   status_code
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_saferepr_format_assertmsgtextAssertionError_format_explanationr   )	r   r   r   r   @py_assert1@py_assert4@py_assert3@py_format6@py_format8s	            r   _ledgerr1      s%   zz?h???zQQH5353&555555555355555555555585555585555555555355555555555555555555555555555555==??r   amountkeyc           	      8   |                      d|||d| |d          }|j        }d}||k    }|st          j        d|fd||f          dt	          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          d	z  }	t          j        |j	                  d
z   d|	iz  }
t          t          j        |
                    d x}x}}|                                d         d         S )Nz/api/admin/coins/manualzTestbuchung )r   r2   commentidempotency_keyr   r   r   r   r   r   r   r   r    transactionr   )postr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r   )r   r   r   r2   r3   r   r,   r-   r.   r/   r0   s              r   _manualr:      sL   {{! +c++"	
 
  	 	H 5353&555555555355555555555585555585555555555355555555555555555555555555555555==??=)$//r   c                     t                       t          t                    5 } t          |           }t	          |           }t          | ||          d         }t          | ||dd          t          | ||          }d d d            n# 1 swxY w Y   d}|k    }|st          j        d|fd|f          dt          j
                    v st          j                  rt          j                  ndt          j        |          dz  }d	d
|iz  }t          t          j        |                    d x}}|d         d         }	|d         }
d}|
|z   }|	|k    }|st          j        d|fd|	|f          t          j        |	          t          j        |
          t          j        |          dz  }dd|iz  }t          t          j        |                    d x}	x}x}
x}}|d         d         }	|d         }
|	|
k    }|slt          j        d|fd|	|
f          t          j        |	          t          j        |
          dz  }dd|iz  }t          t          j        |                    d x}	x}}
|d         d         }	|d         }
d}|
|z   }|	|k    }|st          j        d|fd|	|f          t          j        |	          t          j        |
          t          j        |          dz  }dd|iz  }t          t          j        |                    d x}	x}x}
x}}fd|d         D             }t          |          }
|
sddt          j
                    v st          j        t                    rt          j        t                    ndt          j        |          t          j        |
          dz  }t          t          j        |                    d x}}
d S )Nsummary
   zmanual-plus-tenr   )>)z%(py0)s > %(py3)stx_id)r   py3assert %(py5)sr   postedr   z%(py1)s == (%(py4)s + %(py6)s)py1py4py6assert %(py9)spy9reservedz%(py1)s == %(py4)srE   rF   assert %(py6)srG   	availablec              3   `   K   | ](}|d          k    o|d         dk    o|d         dk    V  )dS )r   r2   r=   transaction_typemanualN .0txr?   s     r   	<genexpr>zVtest_admin_manual_plus_ten_booking_updates_available_balance_by_ten.<locals>.<genexpr>.   sL      cer$x5 ^R\R%7^B?Q<RV^<^r   transactions,assert %(py4)s
{%(py4)s = %(py0)s(%(py2)s)
}anyr   r   rF   )r   r   r   r   r   r1   r:   r"   r#   r$   r%   r&   r'   r*   r+   rY   )r   r   r   beforeafter@py_assert2r,   @py_format4r/   @py_assert0r.   @py_assert5@py_assert7r0   @py_format10@py_format5@py_format7r?   s                    @r   Ctest_admin_manual_plus_ten_booking_updates_available_balance_by_tenre   !   s   III	C 3F''V$$(33I>27HII223 3 3 3 3 3 3 3 3 3 3 3 3 3 3 51951551H%>)9>B>)9B)>>%)>>>>>>>>>>>%)>>>>>>%>>>>)9>>>>B>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>J'=6*+=='+==========='+======'====+============================K(DF;,?D"D,?",DD(,DDDDDDDDDDD(,DDDDDD(DDDD,?DDDD"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDino}i~333s   AB

BBc                  p   t                       t          t                    5 } t          |           }t	          |           }t          | ||          d         }t          | ||dd          |                     d d|dd d	          }|                     d d|dd d	          }t          | ||          }d d d            n# 1 swxY w Y   |j        }d
}||k    }	|	st          j
        d|	fd||f          dt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          dz  }
t          j        |j                  dz   d|
iz  }t#          t          j        |                    d x}x}	}|j        }d
}||k    }	|	st          j
        d|	fd||f          dt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          dz  }
t          j        |j                  dz   d|
iz  }t#          t          j        |                    d x}x}	}|d         }||k    }|st          j
        d|fd||f          t          j        |          dt          j                    v st          j        |          rt          j        |          nddz  }dd|iz  }
t#          t          j        |
                    d x}}fd|d         D             }t'          |          }	d}|	|k    }|st          j
        d|fd|	|f          dt          j                    v st          j        t&                    rt          j        t&                    ndt          j        |          t          j        |	          t          j        |          dz  }dd|iz  }t#          t          j        |                    d x}x}	x}}d S )Nr<      zadmin-void-sourcer   z/voidzStorno Testzvoid:)r5   r6   r7   r   r   r   firstr   r   r    secondz%(py1)s == %(py3)sr[   rE   r@   rA   r   c                 ,    g | ]}|d          k    |S )reference_transaction_idrR   rS   s     r   
<listcomp>zKtest_admin_single_void_does_not_crash_and_is_idempotent.<locals>.<listcomp>@   s*    ___rr:T7UY^7^7^7^7^7^r   rW      )z0%(py4)s
{%(py4)s = %(py0)s(%(py2)s)
} == %(py7)slen)r   r   rF   r    rH   rI   )r   r   r   r   r   r1   r:   r9   r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   rp   )r   r   r   r[   rh   ri   ledgerr,   r-   r.   r/   r0   r_   r]   r^   @py_assert6r`   rb   r?   s                     @r   7test_admin_single_void_does_not_crash_and_is_idempotentrs   1   sA   III	C 4F''V$$(33I>16IJJ<<<<g`m  CR  KP  CR  CR  US  US  T  T====wan  DS  LQ  DS  DS  VT  VT  U  U(334 4 4 4 4 4 4 4 4 4 4 4 4 4 4 //#/////////////////////5/////5//////////////////UZ////////////////////////11$1111111111111111111116111116111111111111111111fk111111111111111111111111)&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&____VN3___e3_``edee`deeeeeeeeeee`deeeeeeeeeeeee3eeeee3eeeeee_eeee`eeeedeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeees   BCCCc            
      
   t                       t          t                    5 } t          |           }t	          |           }t          | ||          d         }t          | ||dd          t          | ||dd          |                     d|gddd	
          }t          | ||          }|                     dd||gdd
          }t          | ||          }d d d            n# 1 swxY w Y   |j	        }d}	||	k    }
|
st          j        d|
fd||	f          dt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |	          dz  }t          j        |j                  dz   d|iz  }t%          t          j        |                    d x}x}
}	|d         }||k    }|st          j        d|fd||f          t          j        |          dt          j                    v st          j        |          rt          j        |          nddz  }dd|iz  }t%          t          j        |                    d x}}|j	        }d}	||	k    }
|
st          j        d|
fd||	f          dt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |	          dz  }t          j        |j                  dz   d|iz  }t%          t          j        |                    d x}x}
}	|                                d         }d}
||
k    }|slt          j        d|fd||
f          t          j        |          t          j        |
          dz  }d d!|iz  }t%          t          j        |                    d x}x}}
|d         }||k    }|st          j        d|fd||f          t          j        |          dt          j                    v st          j        |          rt          j        |          nddz  }dd|iz  }t%          t          j        |                    d x}}fd"|d#         D             }t+          |          }
|
sd$d%t          j                    v st          j        t*                    rt          j        t*                    nd%t          j        |          t          j        |
          d&z  }t%          t          j        |                    d x}}
d S )'Nr<      zbulk-source-1zbulk-source-2z/api/admin/coins/bulk-voidSammelstornoz	bulk-test)transaction_idsr5   r6   r7   DELETEz/api/admin/coins/bulkDELETE_COIN_BUCHUNGEN)r   rx   confirmr   r   r   	bulk_voidr   r   r    rj   r[   rk   rA   r   deletedeleted   rK   rL   rM   rG   c              3   0   K   | ]}|d          hvV  dS )r   NrR   )rT   rU   first_id	second_ids     r   rV   zMtest_admin_bulk_void_and_bulk_delete_selected_transactions.<locals>.<genexpr>W   s1      \\r$x)44\\\\\\r   rW   rX   allrZ   )r   r   r   r   r   r1   r:   r9   requestr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r   r   )r   r   r   r[   r|   
after_voidr}   after_deleter,   r-   r.   r/   r0   r_   r]   r^   rc   rd   r   r   s                     @@r   :test_admin_bulk_void_and_bulk_delete_selected_transactionsr   C   sl   III	C 
:F''V$$(33I>67HaIIFGXr?KK	KK <giqs|h}  KY  ny  Uz  UzK  {  {	VWh77
*A7fn  EM  OX  DY  f}  Z~  Z~    vw99
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
:  7C7 C'777777777 C7777777777779777779777777 7777C77777777777777777777777777777777i * F********** F***** ***********F*****F***************************11$1111111111111111111116111116111111111111111111fk111111111111111111111111;;==#(q(#q((((((((((#q(((((#((((q(((((((((((((((((((((((((((	","f,,,,,,,,,,"f,,,,,",,,,,,,,,,,f,,,,,f,,,,,,,,,,,,,,,,,,,,,,,,,,,\\\\\|N?[\\\\3\\\\\\\\\\\\\\\\3\\\\\3\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\s   B;C,,C03C0c                     t                       t          t                    5 } t          |           }t	          |           }t          | ||          d         }t          | ||dd           t          | ||          }|                     d| d|ddd	          }t          | ||          }d d d            n# 1 swxY w Y   |d         d
         }|d
         }d}	||	z   }
||
k    }|st          j	        d|fd||
f          t          j
        |          t          j
        |          t          j
        |	          dz  }dd|iz  }t          t          j        |                    d x}x}x}x}	}
|j        }d}||k    }|st          j	        d|fd||f          dt          j                    v st          j        |          rt          j
        |          ndt          j
        |          t          j
        |          dz  }t          j        |j                  dz   d|iz  }t          t          j        |                    d x}x}}|                                d         }d}||k    }|slt          j	        d|fd||f          t          j
        |          t          j
        |          dz  }dd|iz  }t          t          j        |                    d x}x}}|d         }dddd}||k    }|slt          j	        d|fd||f          t          j
        |          t          j
        |          dz  }dd|iz  }t          t          j        |                    d x}x}}|d          }g }||k    }|slt          j	        d|fd||f          t          j
        |          t          j
        |          dz  }dd|iz  }t          t          j        |                    d x}x}}d S )!Nr<      zreset-sourcer   z/resetCOINS_AUF_NULLT)r{   delete_redemptionsr7   rN   r   rC   rD   rH   rI   r   r   resetr   r   r    r~   ro   )>=)z%(py1)s >= %(py4)srL   rM   rG   r   )rB   rJ   rN   rK   rW   )r   r   r   r   r   r1   r:   r9   r"   r#   r'   r*   r+   r!   r$   r%   r&   r(   r)   r   )r   r   r   before_manualr[   r   r\   r_   r.   r`   ra   r]   r0   rb   r,   r-   r/   rc   rd   s                      r   Htest_admin_reset_coin_history_sets_child_to_zero_and_removes_redemptionsr   Z   s   III	C 3F''V$$::9E1n===(33@@@@'dt  MQ  YR  YR  S  S223 3 3 3 3 3 3 3 3 3 3 3 3 3 3 )[)K];-GK!K-G!-KK)-KKKKKKKKKKK)-KKKKKK)KKKK-GKKKK!KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK//#/////////////////////5/////5//////////////////UZ////////////////////////::<<	"'a'"a''''''''''"a'''''"''''a'''''''''''''''''''''''''''K!KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK &B& B&&&&&&&&&& B&&&&& &&&&B&&&&&&&&&&&&&&&&&&&&&&&&&&&&&s   B
B99B= B=)builtinsr$   _pytest.assertion.rewrite	assertionrewriter"   fastapi.testclientr   app.db.sessionr   app.mainr   tests.conftestr   intr   dictr1   strr:   re   rs   r   r   rR   r   r   <module>r      sO                 ) ) ) ) ) ) " " " " " "       ( ( ( ( ( (]j ]S ] ] ] ]J       0J 0 0 0c 0PS 0X[ 0 0 0 0@ @ @ f f f$] ] ].' ' ' ' 'r   