
    mj;                    n    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l
mZ ddZddZddZddZdS )    )annotations)Path)import_accounts_csv)$set_performance_scope_classification)connect_memory)apply_migrationstmp_pathr   returnNonec                   | dz  }|                     dd           t                      }t          |           t          ||dd          }|j        dk    sJ |j        dk    sJ |j        dk    sJ |j        dk    sJ |j        d	k    sJ |	                    d
          
                                d         dk    sJ |	                    d          
                                d         dk    sJ d S )Naccounts.csvplatform_name,platform_type,account_name,account_type,currency,performance_included,is_health_reserve,notes
Demo Broker,broker,Demo Depot,brokerage,CHF,1,0,Synthetic only
utf-8encodingFcommitsource_filename   r   
dry_run_ok#SELECT COUNT(*) AS n FROM platformsn)SELECT COUNT(*) AS n FROM import_sessions)
write_textr   r   r   
rows_totalrows_newrows_existingrows_failedstatusexecutefetchoner	   pathconnresults       /tests/unit/test_importers_platforms_accounts.py+test_accounts_import_dry_run_does_not_writer'      s*   n$DOO	K    
 DT tE>ZZZF!!!!?a1$$$$""""=L((((<<=>>GGII#NRSSSSS<<CDDMMOOPSTXYYYYYYY    c                   | dz  }|                     dd           t                      }t          |           t          ||dd          }t          ||dd          }|j        dk    sJ |j        dk    sJ |j        dk    sJ |                    d	                                          d
         dk    sJ |                    d                                          d
         dk    sJ |                    d                                          d         dk    sJ |                    d                                          d         dk    sJ |                    d                                          d
         dk    sJ d S )Nr   r   r   r   Tr   r   r   r   r   "SELECT COUNT(*) AS n FROM accountsz)SELECT performance_included FROM accountsz6SELECT COUNT(*) FROM performance_scope_classificationsr      )r   r   r   r   r   r   r    r!   )r	   r#   r$   firstseconds        r&   )test_accounts_import_commit_is_idempotentr.       s   n$DOO	K    
 DTd4XXXE tD.YYYF>Q?a1$$$$<<=>>GGII#NRSSSSS<<<==FFHHMQRRRRR<<CDDMMOOPQRVWWWWW<<PQQZZ\\]^_cddddd<<CDDMMOOPSTXYYYYYYYr(   c                Z   | dz  }|                     dd           t                      }t          |           t          ||dd          }|j        dk    sJ |j        dk    sJ d	|j        d
         v sJ |                    d                                          d         d
k    sJ d S )Nzbad_accounts.csvz`platform_name,platform_type,account_name,account_type,currency
,broker,Demo Depot,brokerage,CHF
r   r   Tr   r   failedplatform_namer   r*   r   )	r   r   r   r   r   r   errorsr    r!   r"   s       r&   /test_accounts_import_collects_validation_errorsr3   7   s    ((DOO	-    
 DT tDJ\]]]F""""=H$$$$fmA.....<<<==FFHHMQRRRRRRRr(   c           	        | dz  }|                     dd           t                      }t          |           |                    d           |                    d           t	          |ddd	d
dd           t          |                    d                                                    }t          ||d|j                  }|j	        dk    sJ t          |                    d                                                    |k    sJ |                    d                                          }|d         dk    sJ |                    d                                          d         dk    sJ d S )Nzhousehold_accounts.csvzplatform_name,platform_type,account_name,account_type,currency,performance_included,is_health_reserve,notes
Household Bank,bank,Daily Cash,cash,CHF,1,0,Synthetic only
r   r   zqINSERT INTO platforms(platform_id,name,platform_type,created_at) VALUES('pf','PostFinance','broker','2026-01-01')zINSERT INTO accounts(account_id,platform_id,account_name,account_type,currency,
             performance_included,created_at)
           VALUES('pf-depot','pf','PostFinance E-Trading','brokerage','CHF',0,'2026-01-01')zpf-depotTpostfinance_etrading_depottestzapproved synthetic rolez2026-01-01T00:00:00Z)
account_idincludedclassification_rolesourcenoteclassified_atzSELECT a.performance_included,c.included,c.classification_role,c.audit_id
           FROM accounts a JOIN performance_scope_classifications c USING(account_id)
           WHERE a.account_id='pf-depot'r   	committedzTSELECT performance_included FROM accounts
           WHERE account_name='Daily Cash'r   zSELECT COUNT(*) FROM performance_scope_classifications c
           JOIN accounts a USING(account_id) WHERE a.account_name='Daily Cash')
r   r   r   r    r   tupler!   r   namer   )r	   r#   r$   beforer%   	households         r&   Itest_household_account_import_cannot_change_an_existing_performance_scoperB   I   s   ..DOO	G    
 DTLL{   	LL	_  
 )8&,    4<<	,  hjj	 F !tD$)TTTF=K''''	,  hjj	  	   
 	.  hjj  Q<1<<	R  hjj      r(   N)r	   r   r
   r   )
__future__r   pathlibr   (jarvis_finance.imports.accounts_importerr   )jarvis_finance.services.performance_scoper   jarvis_finance.storage.databaser   !jarvis_finance.storage.migrationsr   r'   r.   r3   rB    r(   r&   <module>rJ      s    " " " " " "       H H H H H H Z Z Z Z Z Z : : : : : : > > > > > >Z Z Z Z*Z Z Z Z.S S S S$0 0 0 0 0 0r(   