o
    Ïd`%  ã                   @   sP   d Z dZddlmZ ddlmZ ddlmZ G dd„ deƒZG dd	„ d	e	ƒZ
d
S )z"A fake HTTP connection for testingzMark Roach (mrroach@google.com)é    )Úurllib)Ú
connection)Úformatsc                   @   s   e Zd ZdZdS )ÚErrorz)The base exception class for this module.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r
   r
   úw/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/pyactiveresource/fake_connection.pyr      s    r   c                   @   sl   e Zd ZdZejfdd„Zdd„ Zddd„Z		dd
d„Z	dd„ Z
ddd„Zddd„Zddd„Zddd„Zd	S )ÚFakeConnectiona=  A fake HTTP connection for testing.
    
    Inspired by ActiveResource's HttpMock class. This class is designed to
    take a list of inputs and their corresponding outputs.
    
    Inputs will be matched on the method, path, query and data arguments
    
    Example:
    >>> connection = FakeConnection()
    >>> body = '<?json ... />'
    >>> connection.respond_to('get', '/foos/1.json', None, None, body)
    >>> class Foo(resource.Resource):
    ...     _site = 'http://localhost/'
    ...
    >>> Foo._connection_obj = connection
    >>> Foo.find(1)
    foo(1)
    c                 C   s   || _ i | _d| _dS )z&Constructor for FakeConnection object.FN)ÚformatÚ_request_mapÚ_debug_only)Úselfr   r
   r
   r   Ú__init__"   s   
zFakeConnection.__init__c                 C   s@   t j |¡\}}|rtdd„ | d¡D ƒƒ}||fS i }||fS )z5Return the path and the query string as a dictionary.c                 S   s   g | ]}|  d ¡‘qS )ú=)Úsplit)Ú.0Úir
   r
   r   Ú
<listcomp>,   s    z.FakeConnection._split_path.<locals>.<listcomp>ú&)r   ÚparseÚ
splitqueryÚdictr   )r   ÚpathÚ	path_onlyÚquery_stringÚ
query_dictr
   r
   r   Ú_split_path(   s   ÿzFakeConnection._split_pathTc                 C   s
   || _ d S ©N)r   )r   Údebugr
   r
   r   Ú
debug_only1   s   
zFakeConnection.debug_onlyNc           	      C   sB   |   |¡\}}|du ri }| j |g ¡ ||||f||ff¡ dS )a  Set the response for a given request.
        
        Args:
            method: The http method (e.g. 'get', 'put' etc.).
            path: The path being requested (e.g. '/collection/id.json')
            headers: Dictionary of headers passed along with the request.
            data: The data being passed in as the request body.
            body: The string that should be returned for a matching request.
            response_headers: The headers returned for a matching request
        Returns:
            None
        N)r   r   Ú
setdefaultÚappend)	r   Úmethodr   ÚheadersÚdataÚbodyÚresponse_headersr   Úqueryr
   r
   r   Ú
respond_to4   s   ÿzFakeConnection.respond_toc                 C   sb   |   |¡\}}| j |i ¡D ]\}}|||||fkr'|\}	}
t d|	|
¡  S qtd|||f ƒ‚)NéÈ   z$Invalid or unknown request: %s %s
%s)r   r   Úgetr   ÚResponser   )r   r%   r   r&   r'   r   r*   ÚkeyÚvalueÚresponse_bodyr)   r
   r
   r   Ú_lookup_responseH   s   þÿzFakeConnection._lookup_responsec                 C   s   | j  |  d||d¡j¡S )zPerform an HTTP get request.r-   N)r   Údecoder2   r(   ©r   r   r&   r
   r
   r   r-   Q   s   ÿzFakeConnection.getc                 C   ó   |   d|||¡S )úPerform an HTTP post request.Úpost©r2   ©r   r   r&   r'   r
   r
   r   r7   V   ó   zFakeConnection.postc                 C   r5   )r6   Úputr8   r9   r
   r
   r   r;   Z   r:   zFakeConnection.putc                 C   s   |   d||d¡S )zPerform an HTTP delete request.ÚdeleteNr8   r4   r
   r
   r   r<   ^   r:   zFakeConnection.delete)Tr    )NN)r   r   r   r	   r   Ú
JSONFormatr   r   r"   r+   r2   r-   r7   r;   r<   r
   r
   r
   r   r      s    
	
ÿ
	

r   N)r	   Ú
__author__Ú	six.movesr   Úpyactiveresourcer   r   Ú	Exceptionr   Úobjectr   r
   r
   r
   r   Ú<module>   s   