
    j
                    X    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y	)    )annotations)Path)import_accounts_csv)connect_memory)apply_migrationsc                   | dz  }|j                  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 |j                  d
      j                         d   dk(  sJ |j                  d      j                         d   dk(  sJ y )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tmp_path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>ZF!!!??a1$$$"""==L(((<<=>GGI#NRSSSS<<CDMMOPSTXYYYY    c                   | dz  }|j                  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 |j                  d	      j                         d
   dk(  sJ |j                  d      j                         d
   dk(  sJ |j                  d      j                         d
   dk(  sJ y )Nr	   r
   r   r   Tr   r   r   r   r   "SELECT COUNT(*) AS n FROM accountsr      )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XE tD.YF>>Q??a1$$$<<=>GGI#NRSSSS<<<=FFHMQRRRR<<CDMMOPSTXYYYYr%   c                4   | dz  }|j                  dd       t               }t        |       t        ||dd      }|j                  dk(  sJ |j
                  dk(  sJ d	|j                  d
   v sJ |j                  d      j                         d   d
k(  sJ y )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_errorsr0   4   s    ((DOO	-  
 DT tDJ\]F"""==H$$$fmmA....<<<=FFHMQRRRRr%   N)r   r   returnNone)
__future__r   pathlibr   (jarvis_finance.imports.accounts_importerr   jarvis_finance.storage.databaser   !jarvis_finance.storage.migrationsr   r$   r+   r0    r%   r#   <module>r9      s&    "  H : >Z*Z*Sr%   