o
    tBh                     @   s,   d dl Z d dlZd dlZG dd deZdS )    Nc                   @   sD   e Zd ZdZi Ze	dddZe			dddZedd	 Z	d
S )
TestHelpera  A Helper Class for various functions associated with API testing.
    
    This class contains static and class methods for operations that need to be
    performed during API testing. All of the methods inside this class are
    static or class methods, there is no need to ever initialise an instance of this
    class.    

    Attributes:
        cache (Set): Class variable which stores hashes of file URLs so we don't 
            download the same file twice in a test session.

    Tc                 C   s|   t |t | k s|dkrt | t |krdS dd | D }| D ]}||vr* dS | | dkr;| | || kr; dS q!dS )a  Static method to compare the received headers with the expected headers.
        
        Args:
            expected_headers (dict): A dictionary of expected headers (keys in lower case).
            received_headers (dict): A dictionary of headers received.
            allow_extra (Boolean, optional): A flag which determines if we
                allow extra headers.
        Returns:
            Boolean: True if headers match, False otherwise.
 
        Fc                 S   s   i | ]	\}}|  |qS  )lower).0kvr   r   h/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/tests/test_helper.py
<dictcomp>)   s    z,TestHelper.match_headers.<locals>.<dictcomp>NT)lenitems)expected_headersreceived_headersallow_extrae_keyr   r   r   match_headers   s   zTestHelper.match_headersFc                    s0  t | tkr8t |tkrdS | D ]%}||vr dS s#t | | tkr5t| | ||  dkr5 dS qdS t | tkrt |tkrFdS  dkrTt| t|krTdS g t| D ]3\} fddt|D }t|dkru dS dkr|dkrtfdd|D r dS |qZdS | |krdS dS )a  Static method to compare the received body with the expected body.
        
        Args:
            expected_body (dynamic): The expected body.
            received_body (dynamic): The received body.
            check_values (Boolean, optional): A flag which determines if we
                check values in dictionaries.
            check_order (Boolean, optional): A flag which determines if we
                check the order of array elements.
            check_count (Boolean, optional): A flag which determines if we
                check the count of array elements.
        Returns:
            Boolean: True if bodies match, False otherwise.
 
        FTc              	      s&   g | ]\}}t | r|qS r   )r   
match_body)r   jreceived_element)check_countcheck_ordercheck_valuesexpected_elementr   r   
<listcomp>Z   s
    
z)TestHelper.match_body.<locals>.<listcomp>r   c                    s"   g | ] t  fd dD qS )c                 3   s    | ]}| kV  qd S )Nr   )r   yxr   r   	<genexpr>a   s    z3TestHelper.match_body.<locals>.<listcomp>.<genexpr>)all)r   )previous_matchesr   r   r   a   s   " )typedictr   r   listr
   	enumerater   )expected_bodyreceived_bodyr   r   r   keyimatchesr   )r   r   r   r   r   r   r   3   sH   zTestHelper.match_bodyc                 C   sJ   || j vrt | j |< | j | t|j | j | d | j | S )an  Class method which takes a URL, downloads the file (if not 
        already downloaded for this test session) and returns a file object for 
        the file in read-binary mode.
        
        Args:
            url (string): The URL of the required file.
        Returns:
            FileObject: The file object of the required file (opened with "rb").
 
        r   )cachetempfileNamedTemporaryFilewriterequestsgetcontentseek)clsurlr   r   r   get_fileh   s
   

zTestHelper.get_fileN)T)FFF)
__name__
__module____qualname____doc__r(   staticmethodr   r   classmethodr2   r   r   r   r   r      s    4r   )osr)   r,   objectr   r   r   r   r   <module>   s   