o
    Óó·i˜
  ã                   @   sX   d Z ddlmZmZ ddl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}.
é    )ÚcredentialsÚerror)Úversions)ÚFilePath)ÚOptions)ÚTestCasec                   @   sB   e Zd ZdZdZddd„Zddd„Zd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   thisispasswordÚreturnNc                 C   s2   |   ¡ | _t| jƒ}| d | j¡¡ tƒ | _dS )z/
        Create a file with two users.
        ó   :N)ÚmktempÚfilenamer   Z
setContentÚjoinÚusernamePasswordr   Úoptions)ÚselfÚf© r   úcC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-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   Ú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>=   s   
 z2FTPOptionsTests.test_authFailure.<locals>.<lambda>c                 S   s   |   tj¡S ©N)Ztrapr   ZUnauthorizedLogin)Úerrr   r   r   r#   >   s    N)r   r   r   r   ÚUsernamePasswordr   ÚrequestAvatarIdZaddCallbacks)r   ÚcheckerÚinvalidr   r   r   Útest_authFailure3   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+   ©Úcorrectr   r   r   r#   K   s    z2FTPOptionsTests.test_authSuccess.<locals>.<lambda>N)r   r   r   r   r&   r   r'   ZaddCallback)r   r(   r   r,   r   Útest_authSuccessA   s   
ÿz FTPOptionsTests.test_authSuccess)r	   N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r    r*   r.   r   r   r   r   r      s    

	
	r   N)r2   Ztwisted.credr   r   Ztwisted.pythonr   Ztwisted.python.filepathr   Ztwisted.tap.ftpr   Ztwisted.trial.unittestr   r   r   r   r   r   Ú<module>   s   