
    Yaj1                        d dl mZ d dlZd dlmc mZ d dlm	Z	 d dl
Z
d dl
mZ d dlmZ d dlmZ d dlmZ d dlmZ ddZddZddZddZddZddZddZddZddZddZddZddZddZ dS )    )annotationsN)Iterator)
Connection)
TestClient)get_db)
create_app)apply_migrationsreturnr   c                 ~    t          j        dd          } t           j        | _        |                     d           | S )Nz:memory:F)check_same_threadzPRAGMA foreign_keys = ON)sqlite3connectRowrow_factoryexecuteconns    e/home/agent/.hermes/worktrees/FinanceManager-test-baseline/tests/unit/test_fastapi_vue_cockpit_v11.py_connectr      s8    ?:???D{DLL+,,,K    r   r   c                h     t                      }d fd}||j        t          <   t          |          S )Nr
   Iterator[Connection]c               3     K    V  d S )N r   s   r   override_dbz_client.<locals>.override_db   s      




r   )r
   r   )r   dependency_overridesr   r   )r   appr   s   `  r   _clientr      sE    
,,C      (3CV$c??r   Nonec                .   d}|                      d|f           |                      d|f           |                      d|f           |                      d|f           |                      d|f           |                      d|f           |                      d|f           |                      d	|f           |                      d
|f           |                      d|f           |                      d||f           |                                  d S )N2026-05-16T12:00:00ZzINSERT INTO platforms(platform_id, name, platform_type, country, default_currency, created_at) VALUES ('p1', 'Raiffeisen', 'bank', 'CH', 'CHF', ?)zINSERT INTO platforms(platform_id, name, platform_type, country, default_currency, created_at) VALUES ('p2', 'True Wealth', 'broker', 'CH', 'CHF', ?)zINSERT INTO accounts(account_id, platform_id, account_name, account_type, currency, created_at) VALUES ('cash1', 'p1', 'Privatkonto', 'cash', 'CHF', ?)zINSERT INTO accounts(account_id, platform_id, account_name, account_type, currency, created_at) VALUES ('broker1', 'p2', 'Depot', 'brokerage', 'CHF', ?)zINSERT INTO instruments(instrument_id, asset_class, name, ticker, isin, currency, created_at) VALUES ('inst1', 'stock', 'Demo Equity', 'DEMO', 'CH0000000000', 'CHF', ?)zINSERT INTO market_prices(market_price_id, instrument_id, price_date, close, currency, provider, quality_status, created_at) VALUES ('mp1', 'inst1', '2026-05-15', '10.50', 'CHF', 'local', 'ok', ?)zINSERT INTO cash_balances(cash_balance_id, account_id, balance_date, currency, amount_original, fx_rate_to_chf, amount_chf, source_type, quality_status, created_at) VALUES ('cb1', 'cash1', '2026-05-16', 'CHF', '1000', '1', '1000', 'fixture', 'ok', ?)zwINSERT INTO crypto_wallets(wallet_id, wallet_name, wallet_type, created_at) VALUES ('w1', 'Cold Wallet', 'hardware', ?)zINSERT INTO crypto_assets(asset_id, symbol, coin_name, coingecko_id, created_at) VALUES ('btc', 'BTC', 'Bitcoin', 'bitcoin', ?)zINSERT INTO crypto_holdings(crypto_holding_id, wallet_id, asset_id, quantity, verification_status, created_at) VALUES ('h1', 'w1', 'btc', '0.25', 'ok', ?)zINSERT INTO crypto_prices(crypto_price_id, asset_id, coingecko_id, price_currency, price, provider, provider_timestamp, fetched_at, quality_status) VALUES ('cp1', 'btc', 'bitcoin', 'CHF', '80000', 'local', ?, ?, 'fresh'))r   commit)r   nows     r   _seedr$      s   
 CLL  f  il  hn  o  o  oLL  i  lo  kq  r  r  rLL  k  nq  ms  t  t  tLL  l  or  nt  u  u  uLL  |  B  ~D  E  E  ELL  X  [^  Z`  a  a  aLL  N  QT  PV  W  W  WLL  K  NQ  MS  T  T  TLL  S  VY  U[  \  \  \LL  n  qt  pv  w  w  wLL  p  sv  x{  r|  }  }  }KKMMMMMr   c            	     8	   t                      } t          |            t          |            t          |                               dd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         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}||k    }|slt          j        d	|fd
||f          t          j        |          t          j        |          dz  }dd|iz  }t          t          j
        |                    d x}x}}d}t          |          }|j        } |            }	||	v}|st          j        d|fd||	f          t          j        |          dt          j                    v st          j        t                    rt          j        t                    nddt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          t          j        |	          dz  }
dd|
iz  }t          t          j
        |                    d x}x}x}x}}	d}t          |          }|j        } |            }	||	v}|st          j        d|fd||	f          t          j        |          dt          j                    v st          j        t                    rt          j        t                    nddt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          t          j        |	          dz  }
dd|
iz  }t          t          j
        |                    d x}x}x}x}}	d S )Nz/api/instruments/searchstockdemo)asset_classqueryjsonr   labelzDemo Equity==z%(py1)s == %(py4)spy1py4assert %(py6)spy6isinCH0000000000providerlocalapi_keynot in)zh%(py1)s not in %(py10)s
{%(py10)s = %(py8)s
{%(py8)s = %(py6)s
{%(py6)s = %(py3)s(%(py4)s)
}.lower
}()
}strpayload)r1   py3r2   r4   py8py10assert %(py12)spy12secret)r   r	   r$   r   postr+   
@pytest_ar_call_reprcompare	_safereprAssertionError_format_explanationr<   lower@py_builtinslocals_should_repr_global_name)r   r=   @py_assert0@py_assert3@py_assert2@py_format5@py_format7@py_assert5@py_assert7@py_assert9@py_format11@py_format13s               r   :test_instrument_search_is_local_sanitized_and_decimal_freerX   /   s!   ::D'---uT{{{dmm  !:QXciAjAj kkpprrG1:g/-/-//////////-/////////-///////////////////////////1:f////////////////////////////////////////////////1:j!,W,!W,,,,,,,,,,!W,,,,,!,,,,W,,,,,,,,,,,,,,,,,,,,,,,,,,,0CLL0L.0..0009000000000009000000900000000000C00000C000000000000000000000000L0000.000000000000000000000000000000000000/3w<</<-/--///8///////////8//////8///////////3/////3/////////////w/////w//////<////-//////////////////////////////////////r   c                 Z
   t                      } t          |            t          |            t          |           }ddddddd}|                    d|	                                          }|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         }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}||k    }|slt          j        d|fd||f          t          j        |          t          j        |          dz  }dd|iz  }t          t          j
        |                    d x}x}}|                    di ||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         }
t          |
t                    }|sddt          j                    v st          j        t                    rt          j        t                    ndt          j        |
          dt          j                    v st          j        t                    rt          j        t                    ndt          j        |          dz  }t          t          j
        |                    d 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}||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 )!Ncash1CHFz250.25cash_deposit
2026-05-17zmanual deposit
account_idcurrencyamounttransaction_typebooking_datenote/api/cash/previewr*   warningsr-   r/   r0   r3   r4   
amount_chfzSELECT COUNT(*) FROM audit_logr   /api/cash/confirm
preview_idTri   confirmstatus	confirmedaudit_idz5assert %(py5)s
{%(py5)s = %(py0)s(%(py2)s, %(py3)s)
}
isinstancer<   )py0py2r>   py5zFSELECT COUNT(*) FROM cash_balances WHERE source_type='vue_manual_cash'   :SELECT COUNT(*) FROM audit_log WHERE action='cash_confirm')r   r	   r$   r   rD   r+   rE   rF   rG   rH   rI   r   fetchonero   r<   rK   rL   rM   )r   clientrequestpreviewrN   rO   rP   rQ   rR   rm   @py_assert1@py_assert4@py_format6s                r   Ftest_cash_preview_confirm_writes_snapshot_and_audit_only_after_confirmr|   :   s   ::D'---uT{{{T]]F$%8ao  BN  Xh  i  iGkk-Gk<<AACCG:$"$"$$$$$$$$$$"$$$$$$$$$"$$$$$$$$$$$$$$$$$$$$$$$$$$$< ,H, H,,,,,,,,,, H,,,,, ,,,,H,,,,,,,,,,,,,,,,,,,,,,,,,,,<<899BBDDQGL1LG1LLLLLLLLLLG1LLLLLGLLLL1LLLLLLLLLLLLLLLLLLLLLLLLLLL/6w6wPWXdPerv6w6w6wxx}}IX-+-+----------+---------+---------------------------
+1:+S111111111111111:11111:111111+11111111111S11111S11111111111111111111111111<<`aajjllmnotsttostttttttttttosttttttottttstttttttttttttttttttttttttttt<<TUU^^``abchghhcghhhhhhhhhhhcghhhhhhchhhhghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhr   c            
        t                      } t          |            t          |            t          |           }dddddddd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         }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i ||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                                          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}||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&   broker1inst13r[   r]   initial_snapshot30zopening snapshot)	r(   r_   instrument_idquantityr`   
trade_daterb   cost_basis_originalrd   z/api/positions/previewr*   r(   r-   r/   r0   r3   r4   	fx_status
not_neededrf   z/api/positions/confirmri   Trj   rl   rm   zISELECT COUNT(*) FROM transactions WHERE source_type='vue_manual_position'r   rs   z>SELECT COUNT(*) FROM audit_log WHERE action='position_confirm'r   r	   r$   r   rD   r+   rE   rF   rG   rH   rI   r   ru   )
r   rv   rw   rx   rN   rO   rP   rQ   rR   rm   s
             r   Atest_equity_position_preview_confirm_writes_transaction_and_auditr   L   s	   ::D'---uT{{{T]]F%YQXfiw|  MY  oA  Z^  hz  {  {Gkk2kAAFFHHG=!,W,!W,,,,,,,,,,!W,,,,,!,,,,W,,,,,,,,,,,,,,,,,,,,,,,,,,,;/</<//////////</////////<///////////////////////////:$"$"$$$$$$$$$$"$$$$$$$$$"$$$$$$$$$$$$$$$$$$$$$$$$$$$4;|g;|U\]iUjw{;|;|;|}}  C  C  E  EIX-+-+----------+---------+---------------------------<<cddmmoopqrwvwwrvwwwwwwwwwwwrvwwwwwwrwwwwvwwwwwwwwwwwwwwwwwwwwwwwwwwww<<XYYbbddefglkllgklllllllllllgkllllllgllllkllllllllllllllllllllllllllllllr   c                    t                      } t          |            t          |            t          |           }|                    d                                          }|                    d                                          }|                    d                                          }|                    d                                          }|                    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         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}||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}||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}||k    }	|	slt          j        d
|	fd||f          t          j        |          t          j        |          dz  }
dd|
iz  }t          t          j
        |                    d x}x}	}t          |||||g                                          }g }d}	|	|v}|}|rd}||v}|}|rd}||v}|}|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  }|                    |           |rt          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  }|                    |           |rt          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          j        |d          i z  }d&d'|iz  }t          t          j
        |                    d x}x}x}	x}x}x}x}}d S )(Nz&/api/portfolio/positions/broker1:inst1/api/crypto/positions/btcz/api/cash/positions/cash1:CHFz /api/market/prices/inst1/historyz/api/crypto/prices/btc/historyavailable_actionsr   r,   Kaufenr-   r/   r0   r3   r4   
Einzahlungu   Live-Modus spätervaluez10.5080000r9   tokenrC   r:   )z%(py3)s not in %(py5)srendered)r>   rr   z%(py7)spy7)z%(py10)s not in %(py12)s)r@   rB   z%(py14)spy14)z%(py17)s not in %(py19)s)py17py19z%(py21)spy21zassert %(py24)spy24)r   r	   r$   r   getr+   rE   rF   rG   rH   rI   r<   rJ   rK   rL   rM   append_format_boolop)r   rv   equitycryptocashmarket_historycrypto_historyrN   rO   rP   rQ   rR   r   ry   rz   rU   @py_assert11@py_assert16@py_assert18r{   @py_format8rW   @py_format15@py_format20@py_format22@py_format23@py_format25s                              r   6test_details_audit_and_history_endpoints_are_user_safer   ]   s   ::D'---uT{{{T]]FZZ@AAFFHHFZZ34499;;F::566;;==DZZ BCCHHJJNZZ @AAFFHHN%&q)'2>h>2h>>>>>>>>>>2h>>>>>2>>>>h>>>>>>>>>>>>>>>>>>>>>>>>>>>#$Q'0@L@0L@@@@@@@@@@0L@@@@@0@@@@L@@@@@@@@@@@@@@@@@@@@@@@@@@@%&r*73K7KK37KKKKKKKKKKK37KKKKKK3KKKK7K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!W%00%0000000000%00000%0000000000000000000000000000000!W%00%0000000000%00000%0000000000000000000000000000000FFD..IJJPPRRH]]9]9H$]]]]]])@]]]]]X]XU]E]]]]]]]]]]]]9H]]]]]9]]]]]]]]]]]H]]]]]H]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]XU]]]]]]X]]]]]]]]]]]U]]]]]]U]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]r   c            	     
   t                      } t          |            t          |            d}|                     d|f           |                     d           |                     d|f           |                     d           |                                  t          |                               d                                          }d |d         D             }t          |          }d	d
g}||k    }|st          j
        d|fd||f          dt          j                    v st          j        t                    rt          j        t                    nddt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j        |                    d 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}
|	|
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}
|	|
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             }t#          |          }
|d         }t%          |          }|
|k    }|s"t          j
        d|fd|
|f          dt          j                    v st          j        t"                    rt          j        t"                    ndt          j        |          t          j        |
          dt          j                    v st          j        t$                    rt          j        t$                    ndt          j        |          t          j        |          d z  }d!d"|iz  }t          t          j        |                    d x}x}
x}x}}d S )#Nr!   z{INSERT INTO crypto_wallets(wallet_id, wallet_name, wallet_type, created_at) VALUES ('w2', 'Exchange Wallet', 'exchange', ?)zGUPDATE crypto_holdings SET quantity='0.30' WHERE crypto_holding_id='h1'zINSERT INTO crypto_holdings(crypto_holding_id, wallet_id, asset_id, quantity, verification_status, created_at) VALUES ('h2', 'w2', 'btc', '0.20', 'ok', ?)	  INSERT INTO crypto_prices(crypto_price_id, asset_id, coingecko_id, price_currency, price, provider, provider_timestamp, fetched_at, quality_status) VALUES ('cp_old', 'btc', 'bitcoin', 'CHF', '70000', 'local', '2026-05-15T12:00:00Z', '2026-05-15T12:00:00Z', 'stale')r   c                     i | ]}|d          |S )walletr   .0rows     r   
<dictcomp>z]test_crypto_detail_aggregates_wallet_holdings_before_joining_latest_price.<locals>.<dictcomp>{   s    LLLXLLLr   wallet_allocationszCold WalletzExchange Walletr-   )z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)slist	by_wallet)rp   r1   r>   r4   zassert %(py8)sr?   r   z0.30r/   r0   r3   r4   z0.20market_value_chfz24000.00c              3  @   K   | ]}t          |d                    V  dS )r   N)floatr   s     r   	<genexpr>z\test_crypto_detail_aggregates_wallet_holdings_before_joining_latest_price.<locals>.<genexpr>   s.      NN#uS_%%NNNNNNr   quantity_total)zP%(py4)s
{%(py4)s = %(py0)s(%(py2)s)
} == %(py10)s
{%(py10)s = %(py6)s(%(py8)s)
}sumr   )rp   rq   r2   r4   r?   r@   rA   rB   )r   r	   r$   r   r"   r   r   r+   r   rE   rF   rK   rL   rM   rG   rH   rI   r   r   )r   r#   detailr   rP   rS   rz   rR   @py_format9rN   rO   rQ   ry   rT   rU   rV   rW   s                    r   Itest_crypto_detail_aggregates_wallet_holdings_before_joining_latest_pricer   p   s   ::D'---uT{{{
 CLL  O  RU  QW  X  X  XLLZ[[[LL  n  qt  pv  w  w  wLL  ]  ^  ^  ^KKMMMT]]:;;@@BBFLLv6J/KLLLI	??@}.?@@?@@@@@@@@@@@?@@@@@@@@@@@@@4@@@@@4@@@@@@@@@@@@@	@@@@@	@@@@@@?@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@]#J/969/69999999999/699999/99996999999999999999999999999999&'
3=v=3v==========3v=====3====v===========================]#$67E:E7:EEEEEEEEEE7:EEEEE7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ENN8L1MNNNq3NNNqX^_oXpqRWXpRqRqqNRqqqqqqqqqqqNRqqqqqqqqqqqqq3qqqqq3qqqqqqNqqqqNqqqqqqqqqqqRWqqqqqRWqqqqqqXpqqqqRqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqr   c                    t                      } t          |            t          |            |                     d           |                                  t          |           }|                    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 |d         D             }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         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 S )Nr   z/api/walletsz/api/wallets/w1r   r   z20000.00r-   r/   r0   r3   r4   c                    g | ]
}|d          S )asset_idr   )r   coins     r   
<listcomp>zbtest_wallet_summaries_and_details_use_latest_price_without_duplicate_coin_rows.<locals>.<listcomp>   s    999D999r   coinsbtc)r   r	   r$   r   r"   r   r   r+   rE   rF   rG   rH   rI   )	r   rv   walletsr   rN   rO   rP   rQ   rR   s	            r   Ntest_wallet_summaries_and_details_use_latest_price_without_duplicate_coin_rowsr      s   ::D'---uT{{{LL  ]  ^  ^  ^KKMMMT]]Fjj((--//GZZ)**//11F1:()7Z7)Z7777777777)Z77777)7777Z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99999DeWD9WDDDDDDDDDD9WDDDDD9DDDDW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'?101?Z?1Z??????????1Z?????1????Z?????????????????????????????r   c                    t                      } t          |            t          |            t          |           }ddddddd}|                    d|	                                          }|d
         }|j        }d} ||          }|ssdt          j        |          t          j        |          t          j        |          t          j        |          dz  }t          t          j
        |                    d x}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                                          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i ||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                                          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}	||	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   w1z
0.12500001increaser]   zmanual top-upr   	wallet_idr   rb   effective_daterd   /api/crypto/actions/previewr*   summaryu   Crypto Bestand erhöhenLassert %(py7)s
{%(py7)s = %(py3)s
{%(py3)s = %(py1)s.startswith
}(%(py5)s)
}r1   r>   rr   r   rf   r-   r/   r0   r3   r4   z(SELECT COUNT(*) FROM crypto_transactionsr   /api/crypto/actions/confirmri   Trj   rl   rm   zHSELECT quantity FROM crypto_transactions WHERE source='manual_dashboard'FSELECT COUNT(*) FROM audit_log WHERE action='crypto_manual_adjustment'rs   r   r	   r$   r   rD   r+   
startswithrE   rG   rH   rI   rF   r   ru   )r   rv   rw   rx   rN   rP   rz   @py_assert6r   rO   rQ   rR   rm   s                r   Jtest_crypto_manual_adjustment_preview_confirm_writes_transaction_and_auditr      s   ::D'---uT{{{T]]F tcm  BN  Xg  h  hGkk7gkFFKKMMG9C(C)BC(()BCCCCCCCCCCCC(CCCC)BCCCCCCCCCCCCCCCCCCCCCCCCCCCC:$"$"$$$$$$$$$$"$$$$$$$$$"$$$$$$$$$$$$$$$$$$$$$$$$$$$<<BCCLLNNqQVUVVQUVVVVVVVVVVVQUVVVVVVQVVVVUVVVVVVVVVVVVVVVVVVVVVVVVVVVV9  AB7  ABZabnZo  }A  AB  AB  AB  C  C  H  H  J  JIX-+-+----------+---------+---------------------------<<bccllnnopq  B  vB  Bq  vB  B  B  B  B  B  B  B  B  B  Bq  vB  B  B  B  B  Bq  B  B  B  B  vB  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B<<`aajjllmnotsttostttttttttttosttttttottttsttttttttttttttttttttttttttttttr   c                    t                      } t          |            t          |            t          |           }ddddddd}|                    d|	                                          }|d
         }|j        }d} ||          }|ssdt          j        |          t          j        |          t          j        |          t          j        |          dz  }t          t          j
        |                    d x}x}x}}|                    di ||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                                          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 S )Nr   r   0set_zeror]   zclose manual test holdingr   r   r*   r   zCrypto auf 0 setzenr   r   r   ri   Trj   rl   rm   r-   r/   r0   r3   r4   r   r   rs   r   )r   rv   rw   rx   rN   rP   rz   r   r   rm   rO   rQ   rR   s                r   @test_crypto_set_zero_allows_zero_preview_and_confirms_adjustmentr      s   ::D'---uT{{{T]]F tZd  yE  Oj  k  kGkk7gkFFKKMMG9?(?)>?(()>????????????(????)>????????????????????????????9  AB7  ABZabnZo  }A  AB  AB  AB  C  C  H  H  J  JIX-+-+----------+---------+---------------------------<<`aajjllmnotsttostttttttttttosttttttottttsttttttttttttttttttttttttttttttr   c                 .	   t                      } t          |            t          |            t          |           }ddddddd}dddd	d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i ||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                                          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i ||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                                          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 }||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 )#NrZ   r[   25.00
Auszahlungr]   zcash outr^   z5.00	Korrekturzmanual correctionre   r*   r   zAuszahlung CHF 25.00r-   r/   r0   r3   r4   rh   ri   Trj   rl   rm   zWSELECT transaction_type, gross_amount_original FROM transactions WHERE notes='cash out')cash_withdrawalr   zISELECT transaction_type FROM transactions WHERE notes='manual correction'r   manual_cash_correctionrt      )>=)z%(py1)s >= %(py4)sr   )r   rv   
withdrawal
correction	w_previewrN   rO   rP   rQ   rR   	w_confirm	c_preview	c_confirms                r   Qtest_cash_withdrawal_and_correction_preview_confirm_use_positive_amount_and_auditr      s   ::D'---uT{{{T]]F 'Ugco  BN  Xb  c  cJ 'Ufbm  @L  Vi  j  jJ/jAAFFHHIY9#99#99999999999#9999999999#9999999999999999999999999999/6|6|S\]iSjw{6|6|6|}}  C  C  E  EIX-+-+----------+---------+---------------------------<<qrr{{}}~~~  A  a  Ea  a  A  Ea  a  a  a  a  a  a  a  a  a  a  A  Ea  a  a  a  a  a  A  a  a  a  a  Ea  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a/jAAFFHHI/6|6|S\]iSjw{6|6|6|}}  C  C  E  EIX-+-+----------+---------+---------------------------<<cddmmoopqr  O  wO  Or  wO  O  O  O  O  O  O  O  O  O  Or  wO  O  O  O  O  Or  O  O  O  O  wO  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O<<TUU^^``abchghhcghhhhhhhhhhhcghhhhhhchhhhghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhr   c            
        ddl m}  dd l} | t                                                    j        d         }dD ]}||z  }|j        } |            }|sddt          j                    v st          j
        |          rt          j        |          ndt          j        |          t          j        |          dz  }t          t          j        |                    d x}}|j        } |            }|j        }|j        }	||	z  }
|
sddt          j                    v st          j
        |          rt          j        |          ndt          j        |          t          j        |          t          j        |          d	t          j                    v st          j
        |          rt          j        |          nd	t          j        |	          d
z  }t          t          j        |                    d x}x}x}x}	}
|                                }d}||v}|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}}d}||v}|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}}d}||v}|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}}d S )Nr   )Pathr   )zscripts/start_vue_dashboard.shzscripts/stop_vue_dashboard.shzAassert %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.exists
}()
}script)rp   rq   r2   zassert (%(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.stat
}()
}.st_mode
} & %(py9)s
{%(py9)s = %(py7)s.S_IXUSR
})stat)rp   rq   r2   r4   r   py9API_KEYr:   )z%(py1)s not in %(py3)stext)r1   r>   zassert %(py5)srr   TOKENSECRET)pathlibr   r   __file__resolveparentsexistsrK   rL   rE   rM   rG   rH   rI   st_modeS_IXUSR	read_textrF   )r   r   reporelr   ry   rO   rQ   rS   @py_assert8@py_assert10rV   r   rN   rP   @py_format4r{   s                    r   Mtest_vue_dashboard_scripts_exist_are_executable_and_do_not_print_secret_namesr     s   KKK4>>!!##+A.DR $ $}}}vv}{3{{}}3}$3t|3$|33333333333333v33333v333333{3333}3333$33333333333t33333t333333|3333333333333333333333333!!$y$$$$$$$$$$y$$$$$y$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"wd""""""""""wd"""""w"""""""""""d"""""d"""""""""""""""""""""""""""#xt##########xt#####x###########t#####t############################$ $r   )r
   r   )r   r   r
   r   )r   r   r
   r   )r
   r   )!
__future__r   builtinsrK   _pytest.assertion.rewrite	assertionrewriterE   collections.abcr   r   r   fastapi.testclientr   jarvis_finance.api.dependenciesr   jarvis_finance.api.mainr   !jarvis_finance.storage.migrationsr	   r   r   r$   rX   r|   r   r   r   r   r   r   r   r  r   r   r   <module>r     s   " " " " " "               $ $ $ $ $ $        ) ) ) ) ) ) 2 2 2 2 2 2 . . . . . . > > > > > >          0 0 0 0i i i i$m m m m"^ ^ ^ ^&r r r r&@ @ @ @u u u u"
u 
u 
u 
ui i i i&$ $ $ $ $ $r   