U
    
W[}
  ã                   @   sX   d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ G dd„ deƒZd	S )
z
Tests for L{twisted.tap.ftp}.
é    )ÚTestCase)ÚcredentialsÚerror)ÚOptions)Úversions)ÚFilePathc                   @   s<   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dS )ÚFTPOptionsTestszJ
    Tests for the command line option parser used for C{twistd ftp}.
    )s   iamusers   thisispasswordc                 C   s2   |   ¡ | _t| jƒ}| d | j¡¡ tƒ | _dS )z/
        Create a file with two users.
        ó   :N)ZmktempÚfilenamer   Z
setContentÚjoinÚusernamePasswordr   Úoptions)ÚselfÚf© r   ú?/usr/lib/python3/dist-packages/twisted/test/test_ftp_options.pyÚsetUp   s    

zFTPOptionsTests.setUpc                 C   s$   |   t dddd¡| jj| j¡ dS )zs
        The C{--password-file} option will emit a warning stating that
        said option is deprecated.
        ZTwistedé   é   r   N)ZcallDeprecatedr   ZVersionr   Zopt_password_filer
   ©r   r   r   r   Útest_passwordfileDeprecation"   s
     þz,FTPOptionsTests.test_passwordfileDeprecationc                 C   sB   t | jd ƒ}| j dd| j g¡ |  t | jd ƒ|d ¡ dS )zf
        The C{--auth} command-line option will add a checker to the list of
        checkers
        ÚcredCheckersú--authúfile:r   N)Úlenr   ÚparseOptionsr
   ÚassertEqual)r   ZnumCheckersr   r   r   Útest_authAdded,   s    zFTPOptionsTests.test_authAddedc                    sT   ˆ j  ddˆ j g¡ ˆ j d d }t ˆ jd d¡}| |¡ ‡ fdd„d	d„ ¡S )
z×
        The checker created by the C{--auth} command-line option returns a
        L{Deferred} that fails with L{UnauthorizedLogin} when
        presented with credentials that are unknown to that checker.
        r   r   r   éÿÿÿÿr   Zfakec                    s
   ˆ   d¡S )Nz!Wrong password should raise error)Zfail)Úignorer   r   r   Ú<lambda>A   ó    z2FTPOptionsTests.test_authFailure.<locals>.<lambda>c                 S   s   |   tj¡S ©N)Ztrapr   ZUnauthorizedLogin)Úerrr   r   r   r    B   r!   )r   r   r
   r   ÚUsernamePasswordr   ÚrequestAvatarIdZaddCallbacks)r   ÚcheckerZinvalidr   r   r   Útest_authFailure6   s    

ýz FTPOptionsTests.test_authFailurec                    sJ   ˆj  ddˆj g¡ ˆj d d }tjˆjŽ ‰ | ˆ ¡ ‡ ‡fdd„¡S )zË
        The checker created by the C{--auth} command-line option returns a
        L{Deferred} that returns the avatar id when presented with credentials
        that are known to that checker.
        r   r   r   r   c                    s   ˆ  | ˆ j¡S r"   )r   Úusername)r(   ©Zcorrectr   r   r   r    O   r!   z2FTPOptionsTests.test_authSuccess.<locals>.<lambda>)r   r   r
   r   r$   r   r%   ZaddCallback)r   r&   r   r)   r   Útest_authSuccessE   s    
ÿz FTPOptionsTests.test_authSuccessN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r'   r*   r   r   r   r   r      s   


r   N)r.   Ztwisted.trial.unittestr   Ztwisted.credr   r   Ztwisted.tap.ftpr   Ztwisted.pythonr   Ztwisted.python.filepathr   r   r   r   r   r   Ú<module>   s   