U
    ¹~HjI  ã                   @   st   d Z ddlmZmZmZ ddlmZ ddlmZ ddl	m
Z
 G dd„ de
jƒZG dd	„ d	ƒZG d
d„ dee
jƒZdS )z2
Test cases for twisted.protocols.postfix module.
é    )ÚDictÚListÚTuple)ÚStringTransport)Úpostfix)Úunittestc                   @   s&   e Zd ZdddddddgZdd	„ Zd
S )ÚPostfixTCPMapQuoteTests)ó   foor	   )s   foo bars	   foo%20bar)s   foo	bars	   foo%09bar)s   foo
bars	   foo%0Abars	   foo%0abar)s   foo
bars   foo%0D%0Abars   foo%0D%0abars   foo%0d%0Abars   foo%0d%0abar)s   foo s   foo%20)s    foos   %20fooc                 C   sV   | j D ]J}|d }|dd … }|  t |¡|d ¡ |D ]}|  t |¡|¡ q8qd S )Nr   é   )ÚdataÚassertEqualr   ÚquoteÚunquote)ÚselfÚentryÚrawÚquotedÚq© r   ú=/tmp/pip-unpacked-wheel-ewod1tgb/twisted/test/test_postfix.pyÚtestData!   s    
z PostfixTCPMapQuoteTests.testDataN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r      s   òr   c                   @   sR   e Zd ZU i Zeeef ed< g Zee	eef  ed< dd„ Z
dd„ Zdd„ Zd	S )
ÚPostfixTCPMapServerTestCaser   Úchatc              
   C   s€   t  | j¡}tƒ }t  ¡ }||_||_| |¡ | jD ]:\}}| 	|¡ |  
| ¡ |d||| ¡ f ¡ | ¡  q6| d¡ dS )zÑ
        Test that I{get} and I{put} commands are responded to correctly by
        L{postfix.PostfixTCPMapServer} when its factory is an instance of
        L{postifx.PostfixTCPMapDictServerFactory}.
        zFor %r, expected %r but got %rN)r   ZPostfixTCPMapDictServerFactoryr   r   ÚPostfixTCPMapServerÚserviceÚfactoryÚmakeConnectionr   ÚlineReceivedr   ÚvalueÚclearÚ
setTimeout©r   r   Ú	transportÚprotocolÚinputZexpected_outputr   r   r   Ú	test_chat4   s"    

ÿý
z%PostfixTCPMapServerTestCase.test_chatc                 C   s€   t  | j¡}tƒ }t  ¡ }||_||_| |¡ | jD ]:\}}| 	|¡ |  
| ¡ |d ||| ¡ ¡¡ | ¡  q6| d¡ dS )zÚ
        Test that I{get} and I{put} commands are responded to correctly by
        L{postfix.PostfixTCPMapServer} when its factory is an instance of
        L{postifx.PostfixTCPMapDeferringDictServerFactory}.
        z$For {!r}, expected {!r} but got {!r}N)r   Z'PostfixTCPMapDeferringDictServerFactoryr   r   r   r   r   r   r   r    r   r!   Úformatr"   r#   r$   r   r   r   Útest_deferredChatM   s&    

  ÿý
z-PostfixTCPMapServerTestCase.test_deferredChatc                 C   sF   G dd„ dƒ}t  ¡ }|ƒ |_tƒ |_| d¡ |  |j ¡ d¡ dS )z^
        If the factory throws an exception,
        error code 400 must be returned.
        c                   @   s   e Zd ZdZdd„ ZdS )zCPostfixTCPMapServerTestCase.test_getException.<locals>.ErrorFactoryzE
            Factory that raises an error on key lookup.
            c                 S   s   t dƒ‚d S )NzThis is a test error)Ú	Exception)r   Úkeyr   r   r   Úgetr   s    zGPostfixTCPMapServerTestCase.test_getException.<locals>.ErrorFactory.getN)r   r   r   Ú__doc__r-   r   r   r   r   ÚErrorFactorym   s   r/   s   get examples   400 This is a test error
N)r   r   r   r   r%   r    r   r!   )r   r/   Úserverr   r   r   Útest_getExceptiong   s    
z-PostfixTCPMapServerTestCase.test_getExceptionN)r   r   r   r   r   ÚbytesÚ__annotations__r   r   r   r(   r*   r1   r   r   r   r   r   +   s
   
r   c                
   @   s.   e Zd ZdddœZdddddd	d
dddg
ZdS )Ú
ValidTestss
   ThisIs Foos    bar really is found
)r	   s   bar)s   gets&   400 Command 'get' takes 1 parameters.
)s   get foo baró   500 
)s   putó&   400 Command 'put' takes 2 parameters.
)s   put foor6   )s   put foo bar bazó    500 put is not implemented yet.
)s   put foo barr7   )s   get foos   200 ThisIs%20Foo
)s   get bars'   200 %20bar%20really%20is%20found%0D%0A
)s   get bazr5   )r	   s   400 unknown command
N)r   r   r   r   r   r   r   r   r   r4   |   s   þör4   N)r.   Útypingr   r   r   Ztwisted.internet.testingr   Ztwisted.protocolsr   Ztwisted.trialr   ZTestCaser   r   r4   r   r   r   r   Ú<module>   s   Q