
    Vh                         d Z ddlmZmZ ddlmZ ddlmZmZ ddl	m
Z
 ddlmZ  G d de      Z G d	 d
      Z G d de      Zy)z 
Tests for L{twisted.mail.tap}.
    )defer	endpoints)	protocols)OptionsmakeService)
UsageError)TestCasec                   R    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zy)OptionsTestszK
    Tests for the command line option parser used for I{twistd mail}.
    c                     | j                         | _        t        | j                  d      5 }|j                  d       d d d        y # 1 sw Y   y xY w)Nwzsomeuser:	differentuser
)mktempaliasFilenameopenwrite)self	aliasFiles     N/home/dcms/DCMS/lib/python3.12/site-packages/twisted/mail/test/test_options.pysetUpzOptionsTests.setUp   sD    ![[]$$$c* 	:iOO89	: 	: 	:s   AAc                 n    | j                  t        t               j                  d| j                  g       y)zi
        Test that adding an aliases(5) file before adding a domain raises a
        UsageError.
        	--aliasesN)assertRaisesr   r   parseOptionsr   r   s    r   testAliasesWithoutDomainz%OptionsTests.testAliasesWithoutDomain   s,    
 		..d>P>P0Q	
    c                 R    t               j                  ddd| j                  g       y)z
        Test that adding an aliases(5) file to an IAliasableDomain at least
        doesn't raise an unhandled exception.
        z--maildirdbmdomainzexample.com=example.comr   N)r   r   r   r   s    r   testAliaseszOptionsTests.testAliases"   s+    
 		$)""		
r   c                     t               }|j                  d|z   dg       | j                  t        ||         d       | j	                  ||   d   t
        j                         y)z
        Use L{Options} to parse a single service configuration parameter and
        verify that an endpoint of the correct type is added to the list for
        that service.
        z--ztcp:1234   r   Nr   r   assertEquallenassertIsInstancer   TCP4ServerEndpoint)r   serviceoptionss      r   _endpointTestzOptionsTests._endpointTest0   s\     )dWnj9:WW-.2gg.q193O3OPr   c                 &    | j                  d       y)z
        When I{--smtp} is given a TCP endpoint description as an argument, a
        TCPServerEndpoint is added to the list of SMTP endpoints.
        smtpNr(   r   s    r   test_endpointSMTPzOptionsTests.test_endpointSMTP;       
 	6"r   c                 &    | j                  d       y)z
        When I{--pop3} is given a TCP endpoint description as an argument, a
        TCPServerEndpoint is added to the list of POP3 endpoints.
        pop3Nr+   r   s    r   test_endpointPOP3zOptionsTests.test_endpointPOP3B   r-   r   c                 J   t               }|j                  g        | j                  t        |d         d       | j	                  |d   d   t
        j                         | j                  t        |d         d       | j	                  |d   d   t
        j                         y)zO
        POP3 and SMTP each listen on a TCP4ServerEndpoint by default.
        r/   r    r   r*   Nr!   r   r'   s     r   test_protoDefaultszOptionsTests.test_protoDefaultsI   s     )R WV_-q1gfoa0)2N2NOWV_-q1gfoa0)2N2NOr   c                    t               }|j                  dg       | j                  |j                  dd      g        | j	                  |j                  dd      g        t               }|j                  dg       | j	                  |j                  dd      g        | j                  |j                  dd      g        y)zg
        The I{--no-pop3} and I{--no-smtp} options disable POP3 and SMTP
        respectively.
        	--no-pop3Nr/   r*   	--no-smtp)r   r   r"   _getEndpointsassertNotEqualr2   s     r   test_protoDisablezOptionsTests.test_protoDisableV   s    
 )k]+..tV<bAG11$?D)k]+G11$?D..tV<bAr   c                 ^    t               }| j                  t        |j                  ddg       y)zI
        If all protocols are disabled, L{UsageError} is raised.
        r5   r6   N)r   r   r   r   r2   s     r   test_allProtosDisabledErrorz(OptionsTests.test_allProtosDisabledErrore   s+     ),,[/I	
r   c                     t               }| j                  t        |j                  dg      }| j	                  dt        |             y)zu
        If I{--esmtp} is given without I{--hostname}, L{Options.parseOptions}
        raises L{UsageError}.
        z--esmtpz--esmtp requires --hostnameN)r   r   r   r   r"   str)r   r'   excs      r   test_esmtpWithoutHostnamez&OptionsTests.test_esmtpWithoutHostnamen   s<    
 )
G,@,@9+N6CAr   c                    t               }|j                  ddg       | j                  t        |d         d       |d   d   }|j                  }|j
                  j                  j                  }|D ]  }| j                  |||           y)zC
        Tests that the --auth option registers a checker.
        z--authzmemory:admin:admin:bob:passwordcredCheckersr    r   N)r   r   r"   r#   credentialInterfacesr&   
smtpPortalcheckers)r   r'   checker
interfacesregistered_checkersifaces         r   	test_authzOptionsTests.test_authw   s     )h(IJKW^45q9.)!,11
%oo88AA 	BEW&9%&@A	Br   N)__name__
__module____qualname____doc__r   r   r   r(   r,   r0   r3   r9   r;   r?   rI    r   r   r   r      sC    :


	Q##PB
BBr   r   c                       e Zd ZdZdZd Zy)SpyEndpointzG
    SpyEndpoint remembers what factory it is told to listen with.
    Nc                 :    || _         t        j                  d       S )N)listeningWithr   succeed)r   factorys     r   listenzSpyEndpoint.listen   s    $}}T""r   )rJ   rK   rL   rM   rR   rU   rN   r   r   rP   rP      s     M#r   rP   c                   "    e Zd ZdZd Zd Zd Zy)MakeServiceTestsz3
    Tests for L{twisted.mail.tap.makeService}
    c                 J   t               }t               }t               }||g||<   t        |      }|j                          |j	                          | j                  |j                         | j                  |j                  |       | j                  |j                  |       y)z
        Configure a service with two endpoints for the protocol associated with
        C{key} and verify that when the service is started a factory of type
        C{factoryClass} is used to listen on each of them.
        N)	rP   r   r   privilegedStartServicestartService
addCleanupstopServicer$   rR   )r   keyfactoryClass	cleartextsecureconfigr&   s          r   _endpointServerTestz$MakeServiceTests._endpointServerTest   s      M	 &)sf%&&(++,i55|Df22LAr   c                 D    | j                  dt        j                         y)z
        If one or more endpoints is included in the configuration passed to
        L{makeService} for the C{"pop3"} key, a service for starting a POP3
        server is constructed for each of them and attached to the returned
        service.
        r/   N)rb   r   POP3Factoryr   s    r   	test_pop3zMakeServiceTests.test_pop3        	  )>)>?r   c                 D    | j                  dt        j                         y)z
        If one or more endpoints is included in the configuration passed to
        L{makeService} for the C{"smtp"} key, a service for starting an SMTP
        server is constructed for each of them and attached to the returned
        service.
        r*   N)rb   r   SMTPFactoryr   s    r   	test_smtpzMakeServiceTests.test_smtp   rf   r   N)rJ   rK   rL   rM   rb   re   ri   rN   r   r   rW   rW      s    B"@@r   rW   N)rM   twisted.internetr   r   twisted.mailr   twisted.mail.tapr   r   twisted.python.usager   twisted.trial.unittestr	   r   rP   rW   rN   r   r   <module>ro      sD    . " 1 + +sB8 sBl	# 	#&@x &@r   