o
    b                     @   s   d 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mZmZmZ ddl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}.
    )verifyClass)	IResolver)ResolverBase)EFORMATENAMEENOTIMPEREFUSEDESERVERQuery)DNSFormatErrorDNSNameErrorDNSNotImplementedErrorDNSQueryRefusedErrorDNSServerErrorDNSUnknownError)Failure)SynchronousTestCasec                   @   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      |  | tt dS )zd
        L{ResolverBase.exceptionForCode} converts L{EFORMAT} to
        L{DNSFormatError}.
        N)assertIsr   r   r   r   r   r   r   test_eformat"      z"ExceptionForCodeTests.test_eformatc                 C   r   )zd
        L{ResolverBase.exceptionForCode} converts L{ESERVER} to
        L{DNSServerError}.
        N)r   r   r	   r   r   r   r   r   test_eserver)   r   z"ExceptionForCodeTests.test_eserverc                 C   r   )zX
        L{ResolverBase.exceptionForCode} converts L{ENAME} to L{DNSNameError}.
        N)r   r   r   r   r   r   r   r   
test_ename0   s   z ExceptionForCodeTests.test_enamec                 C   r   )zl
        L{ResolverBase.exceptionForCode} converts L{ENOTIMP} to
        L{DNSNotImplementedError}.
        N)r   r   r   r   r   r   r   r   test_enotimp6   r   z"ExceptionForCodeTests.test_enotimpc                 C   r   )zk
        L{ResolverBase.exceptionForCode} converts L{EREFUSED} to
        L{DNSQueryRefusedError}.
        N)r   r   r   r   r   r   r   r   test_erefused=   r   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_otherD   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_resolverBaseProvidesIResolverQ   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querytimeoutresultsr   r   <lambda>_   s    z6QueryTests.test_typeToMethodDispatch.<locals>.<lambda>   example.comnametype{   )r3   r7   N)r   typeToMethodr
   r.   assertEqual)r   resolverr.   r   r0   r   test_typeToMethodDispatchW   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-   expectedr   r   r2   m   s    z4QueryTests.test_typeToMethodResult.<locals>.<lambda>r3   r4   r7   r   N)r#   r   r8   r
   r.   addBothr,   r9   r   r:   r.   queryDeferredresultr   r<   r   test_typeToMethodResulte   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.
        r3   r+   r4   r7   r   N)
r   r8   r
   r.   r>   r,   assertIsInstancer   trapNotImplementedErrorr?   r   r   r   test_unknownQueryTypet   s   z QueryTests.test_unknownQueryTypeN)r%   r&   r'   r(   r*   r;   rB   rF   r   r   r   r   r)   L   s    r)   N)r(   zope.interface.verifyr   twisted.internet.interfacesr   twisted.names.commonr   twisted.names.dnsr   r   r   r   r	   r
   twisted.names.errorr   r   r   r   r   r   twisted.python.failurer   twisted.trial.unittestr   r   r)   r   r   r   r   <module>   s     2