o
    ¯bK  ã                   @   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)Úpostfix)ÚStringTransport)Úunittestc                   @   s   e Zd Zg d¢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 ]%}|d }|dd … }|  t |¡|d ¡ |D ]}|  t |¡|¡ qqd S )Nr   é   )ÚdataÚassertEqualr   ÚquoteÚunquote)ÚselfÚentryÚrawÚ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                   @   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 ¡ | ¡  q| 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   ÚPostfixTCPMapDictServerFactoryr   r   ÚPostfixTCPMapServerÚserviceÚfactoryÚmakeConnectionr   ÚlineReceivedr   ÚvalueÚclearÚ
setTimeout©r   r   Ú	transportÚprotocolÚinputÚexpected_outputr   r   r   Ú	test_chat4   s"   

ÿý
z%PostfixTCPMapServerTestCase.test_chatc                 C   s€   t  | j¡}tƒ }t  ¡ }||_||_| |¡ | jD ]\}}| 	|¡ |  
| ¡ |d ||| ¡ ¡¡ | ¡  q| 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   Ú'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ƒ‚)NzThis is a test error)Ú	Exception)r   Úkeyr   r   r   Úgetr   s   zGPostfixTCPMapServerTestCase.test_getException.<locals>.ErrorFactory.getN)r   r   r   Ú__doc__r0   r   r   r   r   ÚErrorFactorym   s    r2   s   get examples   400 This is a test error
N)r   r   r   r   r&   r!   r   r"   )r   r2   Úserverr   r   r   Útest_getExceptiong   s   
z-PostfixTCPMapServerTestCase.test_getExceptionN)r   r   r   r   r   ÚbytesÚ__annotations__r   r   r   r*   r-   r4   r   r   r   r   r   +   s   
 r   c                   @   s   e Zd ZdddœZg d¢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 foor9   )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 bazr8   )r	   s   400 unknown command
N)r   r   r   r   r   r   r   r   r   r7   |   s
    þr7   N)r1   Útypingr   r   r   Útwisted.protocolsr   Útwisted.test.proto_helpersr   Útwisted.trialr   ÚTestCaser   r   r7   r   r   r   r   Ú<module>   s   Q