o
    g                     @   s  d dl Z d dlZd dlmZmZ d dlZd dlmZ d dlm	Z	m
Z
 ejdg dedeje ji dd	d
ededdfddZedeje ji dd	deddfddZejdddgededeje ji dd	dedededdfddZdS )    N)patch	MagicMock)SqliteDB)SystemSettingsmigrations_hash_algorithm)Nmd5sha256chromadb.api.fastapi.FastAPIT)clearapi_mockreturnc                 C   s   |rt jjddd|d}n	t jjdddd}t |}| js J | j\}}|r+|d nd}|p0d}|s5J t|jd	d|ks@J |  dS )
zq
    Ensure that when no hash algorithm or a valid one is provided, the client is set up
    with that value
    r
   T./foo)chroma_api_implis_persistentpersist_directoryr   )r   r   r   r   Nr   r   )	chromadbconfigr   Clientcalled	call_argsgetattrsettingsclear_system_cache)r   r   r   clientargskwargspassed_settings"expected_migrations_hash_algorithm r   Q/var/www/visachat/venv/lib/python3.10/site-packages/chromadb/test/db/test_hash.py"test_settings_valid_hash_algorithm
   s,   



r!   mockc                 C   sT   t t tjjdddd}t| W d   n1 sw   Y  | jr(J dS )zn
    Ensure that providing an invalid hash results in a raised exception and the client
    is not called
    r
   invalid_hash_algr   )r   r   r   N)pytestraises	Exceptionr   r   r   r   r   )r"   r   r   r   r    $test_settings_invalid_hash_algorithm8   s   	r'   r   r	   z0chromadb.db.migrations.verify_migration_sequencezchromadb.db.migrations.hashlibhashlib_mockverify_migration_sequence_mockc                 C   s   t ttdd|d}t |_t |_dg|_|  |jjs!J |p$d}|dkr7| j	js/J | j
jr5J dS |dkrI| j	jrAJ | j
jsGJ dS J )	zE
    Test that only the appropriate hashlib functions are called
    applyT)
migrationsallow_resetr   unapplied_migrationr   r	   FN)r   r   r   r   apply_migrationr   return_valuestartr   r   r	   )r(   r)   r   dbr   r   r   r    test_hashlib_algK   s,   r2   )osr$   unittest.mockr   r   r   chromadb.db.impl.sqliter   chromadb.configr   r   markparametrizedictenvironstrr!   r'   r2   r   r   r   r    <module>   s@    +