
     ncj                    Z    d dl mZ d dlmZ d dlmZmZ d dlmZ ddZ	ddZ
dd	Zdd
ZdS )    )annotations)connect_memory)apply_migrationsget_schema_version)REQUIRED_TABLESreturnNonec                     t                      } t          |            d |                     d          D             }t          t                                        |          sJ d S )Nc                    h | ]
}|d          S name .0rows     tests/unit/test_schema.py	<setcomp>z0test_db_schema_can_be_created.<locals>.<setcomp>   s    gggcc&kggg    z1SELECT name FROM sqlite_master WHERE type='table')r   r   executesetr   issubset)conntabless     r   test_db_schema_can_be_createdr      sc    DTggT\\2e%f%fgggF((0000000r   c                 j    t                      } t          |            t          |           dk    sJ d S )N)   )r   r   r   )r   s    r   test_schema_version_recordedr      s:    DTd##r))))))r   c                 X   t                      } t          |            d |                     d                                          D             }d |                     d                                          D             }d |                     d                                          D             }|d                                         dk    sJ |d	                                         dk    sJ |d                                         dk    sJ h d
                    |          sJ d S )Nc                ,    i | ]}|d          |d         S r   typer   r   s     r   
<dictcomp>zDtest_decimal_sensitive_columns_use_text_affinity.<locals>.<dictcomp>   s"    nnnCs6{CKnnnr   PRAGMA table_info(transactions)c                ,    i | ]}|d          |d         S r    r   r   s     r   r"   zDtest_decimal_sensitive_columns_use_text_affinity.<locals>.<dictcomp>   s"    uuu3v;Fuuur   z"PRAGMA table_info(crypto_holdings)c                    h | ]
}|d          S r   r   r   s     r   r   zCtest_decimal_sensitive_columns_use_text_affinity.<locals>.<setcomp>   s    hhhss6{hhhr   zPRAGMA table_info(instruments)quantityTEXTfx_rate_to_chf>   ter	benchmark
index_namefund_domicileposition_categorydistribution_policy)r   r   r   fetchallupperr   )r   tx_colscrypto_colsinstrument_colss       r   0test_decimal_sensitive_columns_use_text_affinityr4      sF   DTnn4<<@a3b3b3k3k3m3mnnnGuut||Dh7i7i7r7r7t7tuuuKhhdll;[.\.\.e.e.g.ghhhO:$$&&&0000#$**,,6666z"((**f4444jjjss  uD  E  E  E  E  E  E  Er   c                    t                      } t          |            d |                     d                                          D             }d |                     d                                          D             }d |                     d                                          D             }h d                    |          sJ h d                    |          sJ h d	                    |          sJ d
 |                     d                                          D             }h d                    |          sJ d |                     d                                          D             }h d                    |          sJ d |                     d                                          D             }h d                    |          sJ d S )Nc                    h | ]
}|d          S r   r   r   s     r   r   zNtest_broker_bank_mapping_tables_exist_with_required_columns.<locals>.<setcomp>$   s    xxxss6{xxxr   z&PRAGMA table_info(instrument_mappings)c                    h | ]
}|d          S r   r   r   s     r   r   zNtest_broker_bank_mapping_tables_exist_with_required_columns.<locals>.<setcomp>%   s    {{{CCK{{{r   z,PRAGMA table_info(platform_account_mappings)c                    h | ]
}|d          S r   r   r   s     r   r   zNtest_broker_bank_mapping_tables_exist_with_required_columns.<locals>.<setcomp>&   s    pppCCKpppr   z)PRAGMA table_info(broker_import_dry_runs)>   isintickercurrencyexchange
confidenceasset_classsource_namesource_labelinstrument_idmapping_statusnormalized_namesource_platformquality_flags_json>	   r;   account_typerB   rD   internal_account_idnormalized_platforminternal_platform_idsource_account_labelnormalized_account_name>   
is_currentsummary_jsonsession_statusrD   mapped_positionssource_file_typeblocked_positionsrE   candidate_cash_rowscandidate_positionssnapshot_date_statussource_filename_hashdetected_snapshot_datec                    h | ]
}|d          S r   r   r   s     r   r   zNtest_broker_bank_mapping_tables_exist_with_required_columns.<locals>.<setcomp>+   s    sss33v;sssr   z-PRAGMA table_info(broker_import_review_items)>   row_hash
dry_run_idr@   review_statusreview_item_idsource_row_refrC   rD   detected_currencyrE   reviewer_confirmeddetected_asset_classaccount_mapping_statusimport_readiness_statussnapshot_date_confirmedticker_exchange_confirmedc                    h | ]
}|d          S r   r   r   s     r   r   zNtest_broker_bank_mapping_tables_exist_with_required_columns.<locals>.<setcomp>-   s    yyycc&kyyyr   z0PRAGMA table_info(broker_import_execution_plans)>   rY   snapshot_datepayload_statusr[   transaction_idrD   source_row_hashexecution_statustransaction_typeexecution_plan_idtarget_account_idtarget_instrument_idpayload_quality_flags_jsonplanned_write_summary_jsonc                    h | ]
}|d          S r   r   r   s     r   r   zNtest_broker_bank_mapping_tables_exist_with_required_columns.<locals>.<setcomp>/   s    jjjFjjjr   r#   >   	is_voided	voided_at	voided_byvoid_reasoncorrection_reasoncorrection_of_transaction_id)r   r   r   r/   r   )r   instrument_mapping_colsaccount_mapping_colsdry_run_colsreview_colsexecution_colstransaction_colss          r   ;test_broker_bank_mapping_tables_exist_with_required_columnsr}   !   s   DTxxdllCk6l6l6u6u6w6wxxx{{4<<@n3o3o3x3x3z3z{{{pp4<<8c+d+d+m+m+o+opppL Q  Q  Q  Z  Z  [r  s  s  s  s  s F  F  F  O  O  Pd  e  e  e  e  e Z  Z  Z  c  c  dp  q  q  q  q  qss$,,7f*g*g*p*p*r*rsssK W  W  W  `  `  al  m  m  m  m  myyT\\:l-m-m-v-v-x-xyyyN m  m  m  v  v  wE  F  F  F  F  Fjjt||<]/^/^/g/g/i/ijjjvvv  AQ  R  R  R  R  R  R  Rr   N)r   r	   )
__future__r   jarvis_finance.storage.databaser   !jarvis_finance.storage.migrationsr   r   jarvis_finance.storage.schemar   r   r   r4   r}   r   r   r   <module>r      s    " " " " " " : : : : : : R R R R R R R R 9 9 9 9 9 91 1 1 1* * * *	E 	E 	E 	ER R R R R Rr   