
    VhI                         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e
j                        Z G d d	      Z G d
 dee
j                        Zy)z2
Test cases for twisted.protocols.postfix module.
    )DictListTuple)StringTransport)postfix)unittestc                       e Zd Zg dZd Zy)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                     | j                   D ]`  }|d   }|dd  }| j                  t        j                  |      |d          |D ]'  }| j                  t        j                  |      |       ) b y )Nr      )dataassertEqualr   quoteunquote)selfentryrawquotedqs        I/home/dcms/DCMS/lib/python3.12/site-packages/twisted/test/test_postfix.pytestDataz PostfixTCPMapQuoteTests.testData!   sn    YY 	:E(C12YFW]]3/; :  !3S9:	:    N)__name__
__module____qualname__r   r    r   r   r
   r
      s    D":r   r
   c                   V    e Zd ZU i Zeeef   ed<   g Zee	eef      ed<   d Z
d Zd Zy)PostfixTCPMapServerTestCaser   chatc                    t        j                  | j                        }t               }t        j                         }||_        ||_        |j                  |       | j                  D ]^  \  }}|j                  |       | j                  |j                         |d|d|d|j                                |j                          ` |j                  d       y)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 z, expected z	 but got N)r   PostfixTCPMapDictServerFactoryr   r   PostfixTCPMapServerservicefactorymakeConnectionr    lineReceivedr   valueclear
setTimeoutr   r%   	transportprotocolinputexpected_outputs         r   	test_chatz%PostfixTCPMapServerTestCase.test_chat4   s     88C#%	..0""	*&*ii 	"E?!!%(!/9??+<> OO	 	D!r   c                    t        j                  | j                        }t               }t        j                         }||_        ||_        |j                  |       | j                  D ]f  \  }}|j                  |       | j                  |j                         |dj                  |||j                                      |j                          h |j                  d       y)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+   s         r   test_deferredChatz-PostfixTCPMapServerTestCase.test_deferredChatM   s     AA$))L#%	..0""	*&*ii 		"E?!!%(!6==?IOO,= OO		 	D!r   c                      G d d      }t        j                         } |       |_        t               |_        |j                  d       | j                  |j                  j                         d       y)z^
        If the factory throws an exception,
        error code 400 must be returned.
        c                       e Zd ZdZd Zy)CPostfixTCPMapServerTestCase.test_getException.<locals>.ErrorFactoryzE
            Factory that raises an error on key lookup.
            c                     t        d      )NzThis is a test error)	Exception)r   keys     r   getzGPostfixTCPMapServerTestCase.test_getException.<locals>.ErrorFactory.getr   s     677r   N)r   r   r   __doc__r;   r   r   r   ErrorFactoryr7   m   s    8r   r=   s   get examples   400 This is a test error
N)r   r#   r%   r   r,   r'   r   r(   )r   r=   servers      r   test_getExceptionz-PostfixTCPMapServerTestCase.test_getExceptiong   s^    	8 	8 ,,.%*,N+))//13PQr   N)r   r   r   r   r   bytes__annotations__r    r   r   r0   r4   r?   r   r   r   r   r   +   sE     D$ue|
 'D$uUE\"
# "2"4Rr   r   c                       e Zd ZdddZg dZy)
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 foorE   )s   put foo bar baz    500 put is not implemented yet.
)s   put foo barrF   )s   get foos   200 ThisIs%20Foo
)s   get bars'   200 %20bar%20really%20is%20found%0D%0A
)s   get bazrD   )r   s   400 unknown command
N)r   r   r   r   r    r   r   r   rC   rC   |   s    +DDr   rC   N)r<   typingr   r   r   twisted.internet.testingr   twisted.protocolsr   twisted.trialr   TestCaser
   r   rC   r   r   r   <module>rL      sQ    % $ 4 % ":h// :8NR NRb,h.?.? r   