← Back
Editing: test_proxy.cpython-38.pyc
U W[|N � @ s� d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z ddl mZmZ ddl m Z mZmZ dd lmZ G d d� de�ZG dd � d e�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZdS )z Test for L{twisted.web.proxy}. � )�TestCase)� StringTransportWithDisconnection)� MemoryReactor)�Resource)�Site)�ReverseProxyResource�ProxyClientFactory)�ProxyClient�ProxyRequest�ReverseProxyRequest��DummyRequestc @ s8 e Zd ZdZdd� Zdd� Zdd� Zdd � Zd d� ZdS ) �ReverseProxyResourceTestsz, Tests for L{ReverseProxyResource}. c C s� t � }t� }tddd|�}|�d|� t|�}t� }|�d�}|�|� | �|j d� |� d| d � | �t|j �d� | �|j d d d� | �|j d d d� |j d d } | �| t� | �| j|� | �| jd d� dS ) z� Check that a request pointing at C{uri} produce a new proxy connection, with the path of this request pointing at C{expectedURI}. � 127.0.0.1�� � /paths indexNs GET s HTTP/1.1 Accept: text/html � r � � hosts 127.0.0.1:1234)r r r ZputChildr r � buildProtocol�makeConnectionZ addCleanup�connectionLost�dataReceived�assertEqual�len� tcpClients�assertIsInstancer �rest�headers) �self�uri�expectedURI�root�reactor�resourceZsite� transport�channel�factory� r( �=/usr/lib/python3/dist-packages/twisted/web/test/test_proxy.py�_testRender s* ��z%ReverseProxyResourceTests._testRenderc C s | � dd�S )z� Test that L{ReverseProxyResource.render} initiates a connection to the given server with a L{ProxyClientFactory} as parameter. s /indexr �r* �r r( r( r) �test_render9 s z%ReverseProxyResourceTests.test_renderc C s | � dd�S )zr Test that L{ReverseProxyResource.render} passes query parameters to the created factory. s /index?foo=bars /path?foo=barr+ r, r( r( r) �test_renderWithQueryA s z.ReverseProxyResourceTests.test_renderWithQueryc C sj t � }tddd|�}|�dd�}| �|t� | �|jd� | �|jd� | �|jd� | �|j |j � dS )a The L{ReverseProxyResource.getChild} method should return a resource instance with the same class as the originating resource, forward port, host, and reactor values, and update the path value with the value passed. r r r � fooNs /path/foo) r r �getChildr r �path�port�hostZassertIdenticalr# )r r# r$ �childr( r( r) � test_getChildI s z'ReverseProxyResourceTests.test_getChildc C s* t ddd�}|�dd�}| �|jd� dS )zu The L{ReverseProxyResource} return by C{getChild} has a path which has already been quoted. r r r s /%Ns /path/%20%2F%25)r r0 r r1 )r r$ r4 r( r( r) �test_getChildWithSpecial[ s z2ReverseProxyResourceTests.test_getChildWithSpecialN) �__name__� __module__�__qualname__�__doc__r* r- r. r5 r6 r( r( r( r) r s !r c @ s0 e Zd ZdZdd� Zdd� Zdd� Zdd � Zd S )�DummyChannelz� A dummy HTTP channel, that does nothing but holds a transport and saves connection lost. @ivar transport: the transport used by the client. @ivar lostReason: the reason saved at connection lost. c C s || _ d| _dS )z4 Hold a reference to the transport. N)r% � lostReason)r r% r( r( r) �__init__o s zDummyChannel.__init__c C s || _ dS )z; Keep track of the connection lost reason. N)r<