U
    
W[n                     @   s   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 ddlmZ ddlmZmZmZmZmZmZ dd	lmZmZmZ dd
lmZmZ ddlmZ G dd de	ZG dd de	ZdS )z$
Tests for L{twisted.names.common}.
    )divisionabsolute_import)verifyClass)	IResolver)SynchronousTestCase)Failure)ResolverBase)EFORMATESERVERENAMEENOTIMPEREFUSEDQuery)DNSFormatErrorDNSServerErrorDNSNameError)DNSNotImplementedErrorDNSQueryRefusedError)DNSUnknownErrorc                   @   sH   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dS )ExceptionForCodeTestsz5
    Tests for L{ResolverBase.exceptionForCode}.
    c                 C   s   t  j| _d S N)r   exceptionForCodeself r   @/usr/lib/python3/dist-packages/twisted/names/test/test_common.pysetUp   s    zExceptionForCodeTests.setUpc                 C   s   |  | tt dS )zd
        L{ResolverBase.exceptionForCode} converts L{EFORMAT} to
        L{DNSFormatError}.
        N)assertIsr   r	   r   r   r   r   r   test_eformat   s    z"ExceptionForCodeTests.test_eformatc                 C   s   |  | tt dS )zd
        L{ResolverBase.exceptionForCode} converts L{ESERVER} to
        L{DNSServerError}.
        N)r   r   r
   r   r   r   r   r   test_eserver&   s    z"ExceptionForCodeTests.test_eserverc                 C   s   |  | tt dS )zX
        L{ResolverBase.exceptionForCode} converts L{ENAME} to L{DNSNameError}.
        N)r   r   r   r   r   r   r   r   
test_ename.   s    z ExceptionForCodeTests.test_enamec                 C   s   |  | tt dS )zl
        L{ResolverBase.exceptionForCode} converts L{ENOTIMP} to
        L{DNSNotImplementedError}.
        N)r   r   r   r   r   r   r   r   test_enotimp5   s    z"ExceptionForCodeTests.test_enotimpc                 C   s   |  | tt dS )zk
        L{ResolverBase.exceptionForCode} converts L{EREFUSED} to
        L{DNSQueryRefusedError}.
        N)r   r   r   r   r   r   r   r   test_erefused=   s    z#ExceptionForCodeTests.test_erefusedc                 C   s   |  | t t dS )zr
        L{ResolverBase.exceptionForCode} converts any other response code to
        L{DNSUnknownError}.
        N)r   r   objectr   r   r   r   r   
test_otherE   s    z ExceptionForCodeTests.test_otherN)__name__
__module____qualname____doc__r   r   r   r    r!   r"   r$   r   r   r   r   r      s   r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )
QueryTestsz*
    Tests for L{ResolverBase.query}.
    c                 C   s   t tt dS )zF
        L{ResolverBase} provides the L{IResolver} interface.
        N)r   r   r   r   r   r   r   "test_resolverBaseProvidesIResolverS   s    z-QueryTests.test_resolverBaseProvidesIResolverc                    sF   g  t  }d fddi|_tddd}||d | dg  dS )	z
        L{ResolverBase.query} looks up a method to invoke using the type of the
        query passed to it and the C{typeToMethod} mapping on itself.
        90  c                    s     | |fS r   )appendqueryZtimeoutZresultsr   r   <lambda>b       z6QueryTests.test_typeToMethodDispatch.<locals>.<lambda>   example.comnametype{   )r2   r6   N)r   typeToMethodr   r.   assertEqual)r   resolverr.   r   r/   r   test_typeToMethodDispatchZ   s     
z$QueryTests.test_typeToMethodDispatchc                    sZ   t   t }d fddi|_tddd}||d}g }||j |  |d  dS )	z
        L{ResolverBase.query} returns a L{Deferred} which fires with the result
        of the method found in the C{typeToMethod} mapping for the type of the
        query passed to it.
        i1  c                    s    S r   r   r-   Zexpectedr   r   r0   p   r1   z4QueryTests.test_typeToMethodResult.<locals>.<lambda>r2   r3   r6   r   N)r#   r   r7   r   r.   addBothr,   r8   r   r9   r.   ZqueryDeferredresultr   r;   r   test_typeToMethodResulth   s    z"QueryTests.test_typeToMethodResultc                 C   sV   t  }i |_tddd}||d}g }||j | |d t |d t	 dS )z
        L{ResolverBase.query} returns a L{Deferred} which fails with
        L{NotImplementedError} when called with a query of a type not present in
        its C{typeToMethod} dictionary.
        r2   r+   r3   r6   r   N)
r   r7   r   r.   r<   r,   ZassertIsInstancer   ZtrapNotImplementedErrorr=   r   r   r   test_unknownQueryTypex   s    z QueryTests.test_unknownQueryTypeN)r%   r&   r'   r(   r*   r:   r?   rA   r   r   r   r   r)   N   s
   r)   N)r(   Z
__future__r   r   Zzope.interface.verifyr   Ztwisted.internet.interfacesr   Ztwisted.trial.unittestr   Ztwisted.python.failurer   Ztwisted.names.commonr   Ztwisted.names.dnsr	   r
   r   r   r   r   Ztwisted.names.errorr   r   r   r   r   r   r   r)   r   r   r   r   <module>   s    8