U
    
W[“  ã                   @   sb   d 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e	ƒZ
G d	d
„ d
e
ejƒZdS )z2
Test cases for twisted.protocols.postfix module.
é    )Úunittest)Úpostfix)ÚStringTransportc                   @   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   ZquoteZunquote)ÚselfÚentryÚrawZquotedÚq© r   ú;/usr/lib/python3/dist-packages/twisted/test/test_postfix.pyÚtestData   s    
z PostfixTCPMapQuoteTests.testDataN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r      s   ør   c                   @   s,   e Zd Zi Zg Zdd„ Zdd„ Zdd„ ZdS )ÚPostfixTCPMapServerTestCasec              
   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ÚmakeConnectionÚchatÚlineReceivedr	   ÚvalueÚclearÚ
setTimeout©r
   r   Ú	transportZprotocolÚinputZexpected_outputr   r   r   Ú	test_chat/   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_deferredChatG   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   Úgeth   s    zGPostfixTCPMapServerTestCase.test_getException.<locals>.ErrorFactory.getN)r   r   r   Ú__doc__r&   r   r   r   r   ÚErrorFactoryd   s   r(   s   get examples   400 This is a test error
N)r   r   r   r   r   r   r	   r   )r
   r(   Zserverr   r   r   Útest_getException_   s    
ÿz-PostfixTCPMapServerTestCase.test_getExceptionN)r   r   r   r   r   r!   r#   r)   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 foor,   )s   put foo bar bazó    500 put is not implemented yet.
)s   put foo barr-   )s   get foos   200 ThisIs%20Foo
)s   get bars'   200 %20bar%20really%20is%20found%0D%0A
)s   get bazr+   )r   s   400 unknown command
N)r   r   r   r   r   r   r   r   r   r*   t   s   þör*   N)r'   Ztwisted.trialr   Ztwisted.protocolsr   Ztwisted.test.proto_helpersr   ZTestCaser   Úobjectr   r*   r   r   r   r   Ú<module>   s   O