o
    Óó·i}A  ã                   @  sþ   d Z ddlmZ ddlZddlZddl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	jƒZG d
d„ de	jƒZG dd„ de	jƒZG dd„ de	jƒZG dd„ de	jƒZG dd„ de	jƒZG dd„ de	jƒZG dd„ de	jƒZG dd„ de	jƒZdS )z
HTTP errors.
é    )ÚannotationsN)ÚnativeString)Úunittest)Úerror)ÚTagc                   @  s.   e Zd ZdZddd„Zddd„Zddd	„Zd
S )ÚCodeToMessageTestsz<
    L{_codeToMessages} inverts L{_responses.RESPONSES}
    ÚreturnÚNonec                 C  s   t  d¡}|  |d¡ d S )Nó   302s   Found©r   Z_codeToMessageÚassertEqual©ÚselfÚm© r   úaC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/web/test/test_error.pyÚtest_validCode   ó   
z!CodeToMessageTests.test_validCodec                 C  ó   t  d¡}|  |d ¡ d S )Ns   987r   r   r   r   r   Útest_invalidCode   r   z#CodeToMessageTests.test_invalidCodec                 C  r   )Ns   InvalidCoder   r   r   r   r   Útest_nonintegerCode!   r   z&CodeToMessageTests.test_nonintegerCodeN©r   r	   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r      s
    

r   c                   @  óB   e Zd ZdZddd„Zddd„Zddd	„Zdd
d„Zddd„ZdS )Ú
ErrorTestsz<
    Tests for how L{Error} attributes are initialized.
    r   r	   c                 C  s,   t  d¡}|  |jd¡ |  t|ƒd¡ dS )zÐ
        If no C{message} argument is passed to the L{Error} constructor and the
        C{code} argument is a valid HTTP status code, C{message} is set to the
        HTTP reason phrase for C{code}.
        ó   200ó   OKú200 OKN©r   ÚErrorr   ÚmessageÚstr©r   Úer   r   r   Útest_noMessageValidStatus+   s   
z$ErrorTests.test_noMessageValidStatusc                 C  s,   t  d¡}|  |jd¡ |  t|ƒd¡ dS )zŸ
        If no C{message} argument is passed to the L{Error} constructor and
        C{code} isn't a known HTTP status code, C{message} stays L{None}.
        ó   999NÚ999r!   r%   r   r   r   Útest_noMessageForStatus5   s   
z"ErrorTests.test_noMessageForStatusc                 C  s:   |   t¡� t d¡ W d  ƒ dS 1 sw   Y  dS )z†
        If C{code} isn't plausibly an HTTP status code (i.e., composed of
        digits) it is rejected with L{ValueError}.
        s   InvalidStatusN)ÚassertRaisesÚ
ValueErrorr   r"   ©r   r   r   r   Útest_invalidStatus>   s   "ÿzErrorTests.test_invalidStatusc                 C  s.   t  dd¡}|  |jd¡ |  t|ƒd¡ dS )z’
        If a C{message} argument is passed to the L{Error} constructor, the
        C{message} isn't affected by the value of C{status}.
        r   ó   My own messagez200 My own messageNr!   r%   r   r   r   Útest_messageExistsF   s   zErrorTests.test_messageExistsc                 C  s<   t  dd¡}|  t|ƒd¡ t  dd¡}|  t|ƒd¡ dS )zh
        C{str()} on an L{Error} returns the code and message it was
        instantiated with.
        r   r   r    éÈ   N)r   r"   r   r$   r%   r   r   r   Útest_strO   s   zErrorTests.test_strNr   )	r   r   r   r   r'   r*   r.   r0   r2   r   r   r   r   r   &   s    



	
	r   c                   @  r   )ÚPageRedirectTestszC
    Tests for how L{PageRedirect} attributes are initialized.
    r   r	   c                 C  ó    t jddd�}|  |jd¡ dS )zé
        If no C{message} argument is passed to the L{PageRedirect} constructor
        and the C{code} argument is a valid HTTP status code, C{code} is mapped
        to a descriptive string to which C{message} is assigned.
        r   ó   /foo©Úlocationó
   OK to /fooN©r   ZPageRedirectr   r#   r%   r   r   r   r'   b   s   z+PageRedirectTests.test_noMessageValidStatusc                 C  ó   t  d¡}|  |jd¡ dS )a;  
        If no C{message} argument is passed to the L{PageRedirect} constructor
        and C{location} is also empty and the C{code} argument is a valid HTTP
        status code, C{code} is mapped to a descriptive string to which
        C{message} is assigned without trying to include an empty location.
        r   r   Nr9   r%   r   r   r   Ú#test_noMessageValidStatusNoLocationk   s   
z5PageRedirectTests.test_noMessageValidStatusNoLocationc                 C  s    t jddd�}|  |jd¡ dS )z¦
        If no C{message} argument is passed to the L{PageRedirect} constructor
        and C{code} isn't a valid HTTP status code, C{message} stays L{None}.
        r(   r5   r6   Nr9   r%   r   r   r   Ú)test_noMessageInvalidStatusLocationExistsu   s   z;PageRedirectTests.test_noMessageInvalidStatusLocationExistsc                 C  ó"   t jdddd�}|  |jd¡ dS )z™
        If a C{message} argument is passed to the L{PageRedirect} constructor,
        the C{message} isn't affected by the value of C{status}.
        r   r/   r5   r6   ó   My own message to /fooNr9   r%   r   r   r   Ú test_messageExistsLocationExists}   ó   z2PageRedirectTests.test_messageExistsLocationExistsc                 C  ó   t  dd¡}|  |jd¡ dS )zº
        If a C{message} argument is passed to the L{PageRedirect} constructor
        and no location is provided, C{message} doesn't try to include the
        empty location.
        r   r/   Nr9   r%   r   r   r   Útest_messageExistsNoLocation…   ó   z.PageRedirectTests.test_messageExistsNoLocationNr   ©	r   r   r   r   r'   r;   r<   r?   rB   r   r   r   r   r3   ]   s    

	


r3   c                   @  r   )ÚInfiniteRedirectionTestszJ
    Tests for how L{InfiniteRedirection} attributes are initialized.
    r   r	   c                 C  r4   )zø
        If no C{message} argument is passed to the L{InfiniteRedirection}
        constructor and the C{code} argument is a valid HTTP status code,
        C{code} is mapped to a descriptive string to which C{message} is
        assigned.
        r   r5   r6   r8   N©r   ÚInfiniteRedirectionr   r#   r%   r   r   r   r'   ”   s   z2InfiniteRedirectionTests.test_noMessageValidStatusc                 C  r:   )aJ  
        If no C{message} argument is passed to the L{InfiniteRedirection}
        constructor and C{location} is also empty and the C{code} argument is a
        valid HTTP status code, C{code} is mapped to a descriptive string to
        which C{message} is assigned without trying to include an empty
        location.
        r   r   NrF   r%   r   r   r   r;   ž   s   
z<InfiniteRedirectionTests.test_noMessageValidStatusNoLocationc                 C  s0   t jddd�}|  |jd¡ |  t|ƒd¡ dS )zµ
        If no C{message} argument is passed to the L{InfiniteRedirection}
        constructor and C{code} isn't a valid HTTP status code, C{message} stays
        L{None}.
        r(   r5   r6   Nr)   )r   rG   r   r#   r$   r%   r   r   r   r<   ©   s   zBInfiniteRedirectionTests.test_noMessageInvalidStatusLocationExistsc                 C  r=   )z 
        If a C{message} argument is passed to the L{InfiniteRedirection}
        constructor, the C{message} isn't affected by the value of C{status}.
        r   r/   r5   r6   r>   NrF   r%   r   r   r   r?   ³   r@   z9InfiniteRedirectionTests.test_messageExistsLocationExistsc                 C  rA   )zÁ
        If a C{message} argument is passed to the L{InfiniteRedirection}
        constructor and no location is provided, C{message} doesn't try to
        include the empty location.
        r   r/   NrF   r%   r   r   r   rB   »   rC   z5InfiniteRedirectionTests.test_messageExistsNoLocationNr   rD   r   r   r   r   rE   �   s    





rE   c                   @  ó   e Zd ZdZddd„ZdS )ÚRedirectWithNoLocationTestszq
    L{RedirectWithNoLocation} is a subclass of L{Error} which sets
    a custom message in the constructor.
    r   r	   c                 C  s.   t  ddd¡}|  |jd¡ |  |jd¡ dS )z»
        When C{code}, C{message}, and C{uri} are passed to the
        L{RedirectWithNoLocation} constructor, the C{message} and C{uri}
        attributes are set, respectively.
        r
   s   REDIRECTs   https://example.coms   REDIRECT to https://example.comN)r   ZRedirectWithNoLocationr   r#   Úurir%   r   r   r   Útest_validMessageË   s   z-RedirectWithNoLocationTests.test_validMessageNr   )r   r   r   r   rK   r   r   r   r   rI   Å   s    rI   c                   @  ó$   e Zd ZdZd	dd„Zd	dd„ZdS )
ÚMissingRenderMethodTestsz\
    Tests for how L{MissingRenderMethod} exceptions are initialized and
    displayed.
    r   r	   c                 C  s2   t ƒ }t |d¡}|  |j|¡ |  |jd¡ dS )zª
        Given C{element} and C{renderName} arguments, the
        L{MissingRenderMethod} constructor assigns the values to the
        corresponding attributes.
        ÚrenderThingN)Úobjectr   ÚMissingRenderMethodÚassertIsÚelementZ
renderName©r   Úeltr&   r   r   r   Útest_constructorÜ   s   z)MissingRenderMethodTests.test_constructorc                 C  s*   t ƒ }t |d¡}|  t|ƒd| ¡ dS )z”
        A L{MissingRenderMethod} is represented using a custom string
        containing the element's representation and the method name.
        rN   zB'MissingRenderMethod': %r had no render method named 'renderThing'N)rO   r   rP   r   ÚreprrS   r   r   r   Ú	test_reprç   s   ÿþz"MissingRenderMethodTests.test_reprNr   ©r   r   r   r   rU   rW   r   r   r   r   rM   Ö   s    
rM   c                   @  rL   )
ÚMissingTemplateLoaderTestsz^
    Tests for how L{MissingTemplateLoader} exceptions are initialized and
    displayed.
    r   r	   c                 C  s"   t ƒ }t |¡}|  |j|¡ dS )z’
        Given an C{element} argument, the L{MissingTemplateLoader} constructor
        assigns the value to the corresponding attribute.
        N)rO   r   ÚMissingTemplateLoaderrQ   rR   rS   r   r   r   rU   û   s   
z+MissingTemplateLoaderTests.test_constructorc                 C  s(   t ƒ }t |¡}|  t|ƒd| ¡ dS )z–
        A L{MissingTemplateLoader} is represented using a custom string
        containing the element's representation and the method name.
        z)'MissingTemplateLoader': %r had no loaderN)rO   r   rZ   r   rV   rS   r   r   r   rW     s   
z$MissingTemplateLoaderTests.test_reprNr   rX   r   r   r   r   rY   õ   s    
	rY   c                   @  sª   e Zd ZdZg fd)dd„Zd*dd„Zd+dd„Zd+dd„Zd+dd„Zd+dd„Z	d+dd„Z
d+dd„Zd+dd„Zd+dd„Zd+dd„Zd+d d!„Zd+d"d#„Zd+d$d%„Zd+d&d'„Zd(S ),ÚFlattenerErrorTestsz&
    Tests for L{FlattenerError}.
    Úrootsúlist[object]r   úerror.FlattenerErrorc              
   C  sN   zt dƒ‚ ty& } zt t ¡ d ¡}t |||¡W  Y d }~S d }~ww )Núoh noesé   )ÚRuntimeErrorÚ	ExceptionÚ	tracebackÚ
extract_tbÚsysÚexc_infor   ÚFlattenerError)r   r\   r&   Útbr   r   r   ÚmakeFlattenerError  s   €þz&FlattenerErrorTests.makeFlattenerErrorÚobjrO   r$   c                 C  s   d| S )NzR(%s)r   )r   rj   r   r   r   ÚfakeFormatRoot  s   z"FlattenerErrorTests.fakeFormatRootr	   c                 C  s&   | j ddgd�}|  |jddg¡ dS )z«
        Given C{exception}, C{roots}, and C{traceback} arguments, the
        L{FlattenerError} constructor assigns the roots to the C{_roots}
        attribute.
        ÚaÚb)r\   N)ri   r   Z_rootsr%   r   r   r   rU     s   z$FlattenerErrorTests.test_constructorc                 C  s    |   ¡ }|  t|ƒt|ƒ¡ dS )zd
        The string form of a L{FlattenerError} is identical to its
        representation.
        N)ri   r   r$   rV   r%   r   r   r   r2   &  s   zFlattenerErrorTests.test_strc                 C  s@   |   ddg¡}| j|_|  t dt|ƒtjtjB ¡t|ƒ¡ dS )z×
        The representation of a L{FlattenerError} initialized with roots and a
        traceback contains a formatted representation of those roots (using
        C{_formatRoot}) and a formatted traceback.
        rl   rm   zœException while flattening:
  R\(a\)
  R\(b\)
  File "[^"]*", line [0-9]*, in makeFlattenerError
    raise RuntimeError\("oh noes"\)
RuntimeError: oh noes
$N)	ri   rk   Ú_formatRootÚ
assertTrueÚreÚmatchrV   ÚMÚSr%   r   r   r   Ú"test_reprWithRootsAndWithTraceback.  s   
ø
õz6FlattenerErrorTests.test_reprWithRootsAndWithTracebackc                 C  s4   |   g ¡}|  t dt|ƒtjtjB ¡t|ƒ¡ dS )úŸ
        The representation of a L{FlattenerError} initialized without roots but
        with a traceback contains a formatted traceback but no roots.
        zŠException while flattening:
  File "[^"]*", line [0-9]*, in makeFlattenerError
    raise RuntimeError\("oh noes"\)
RuntimeError: oh noes
$N)ri   ro   rp   rq   rV   rr   rs   r%   r   r   r   Ú%test_reprWithoutRootsAndWithTracebackD  s   

ú÷z9FlattenerErrorTests.test_reprWithoutRootsAndWithTracebackc                 C  s<   t  tdƒg d¡}|  t dt|ƒtjtjB ¡t|ƒ¡ dS )ru   r_   Nz3Exception while flattening:
RuntimeError: oh noes
$)	r   rg   ra   ro   rp   rq   rV   rr   rs   r%   r   r   r   Ú(test_reprWithoutRootsAndWithoutTracebackV  s   
ýúz<FlattenerErrorTests.test_reprWithoutRootsAndWithoutTracebackc                 C  s&   |   ¡ }|  | tdƒ¡tdƒ¡ dS )zk
        The C{_formatRoot} method formats a short unicode string using the
        built-in repr.
        ZabcdN)ri   r   rn   r   rV   r%   r   r   r   Ú!test_formatRootShortUnicodeStringe  s   z5FlattenerErrorTests.test_formatRootShortUnicodeStringc                 C  s*   |   ¡ }tdƒ}|  | |¡tdƒ¡ dS )z{
        The C{_formatRoot} method formats a long unicode string using the
        built-in repr with an ellipsis.
        zxabcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-z-abcde-abcde-abcde-ab<...>e-abcde-abcde-abcde-N)ri   r   r   rn   rV   ©r   r&   Z
longStringr   r   r   Ú test_formatRootLongUnicodeStringm  s   þz4FlattenerErrorTests.test_formatRootLongUnicodeStringc                 C  s"   |   ¡ }|  | d¡tdƒ¡ dS )zh
        The C{_formatRoot} method formats a short byte string using the
        built-in repr.
        s   abcdN©ri   r   rn   rV   r%   r   r   r   Útest_formatRootShortByteStringy  ó   z2FlattenerErrorTests.test_formatRootShortByteStringc                 C  s&   |   ¡ }d}|  | |¡tdƒ¡ dS )zx
        The C{_formatRoot} method formats a long byte string using the
        built-in repr with an ellipsis.
        sx   abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-s-   abcde-abcde-abcde-ab<...>e-abcde-abcde-abcde-Nr{   ry   r   r   r   Útest_formatRootLongByteString�  s   þz1FlattenerErrorTests.test_formatRootLongByteStringc                 C  s"   |   ¡ }|  | tdƒ¡d¡ dS )zu
        The C{_formatRoot} method formats a C{Tag} with no filename information
        as 'Tag <tagName>'.
        úa-tagzTag <a-tag>N)ri   r   rn   r   r%   r   r   r   Útest_formatRootTagNoFilename�  r}   z0FlattenerErrorTests.test_formatRootTagNoFilenamec                 C  s.   |   ¡ }tddddd�}|  | |¡d¡ dS )z”
        The C{_formatRoot} method formats a C{Tag} with filename information
        using the filename, line, column, and tag information
        r   ztpl.pyé
   é   )ÚfilenameZ
lineNumberZcolumnNumberz-File "tpl.py", line 10, column 20, in "a-tag"N)ri   r   r   rn   )r   r&   Útr   r   r   Útest_formatRootTagWithFilename•  s
   
ÿz2FlattenerErrorTests.test_formatRootTagWithFilenamec                 C  óD   |   tt tdƒdgg ¡ƒd¡ |   tt tdƒdgg ¡ƒd¡ dS )zº
        If a L{FlattenerError} is created with a string root, up to around 40
        bytes from that string are included in the string representation of the
        exception.
        ÚreasonZ	abc123xyzz?Exception while flattening:
  'abc123xyz'
RuntimeError: reason
Zd0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789zcException while flattening:
  '01234567890123456789<...>01234567890123456789'
RuntimeError: reason
N©r   r$   r   rg   ra   r-   r   r   r   Útest_string   s   þþzFlattenerErrorTests.test_stringc                 C  r†   )zÀ
        If a L{FlattenerError} is created with a unicode root, up to around 40
        characters from that string are included in the string representation
        of the exception.
        r‡   u	   abcâ˜ƒxyzzBException while flattening:
  'abc\u2603xyz'
RuntimeError: reason
ux   01234567â˜ƒ901234567â˜ƒ901234567â˜ƒ901234567â˜ƒ901234567â˜ƒ901234567â˜ƒ901234567â˜ƒ901234567â˜ƒ901234567â˜ƒ901234567â˜ƒ9zwException while flattening:
  '01234567\u2603901234567\u26039<...>01234567\u2603901234567\u26039'
RuntimeError: reason
Nrˆ   r-   r   r   r   Útest_unicode²  s   ÿüÿÿúz FlattenerErrorTests.test_unicodeN)r\   r]   r   r^   )rj   rO   r   r$   r   )r   r   r   r   ri   rk   rU   r2   rt   rv   rw   rx   rz   r|   r~   r€   r…   r‰   rŠ   r   r   r   r   r[     s"    


	









r[   c                   @  rH   )ÚUnsupportedMethodTestsz)
    Tests for L{UnsupportedMethod}.
    r   r	   c                 C  s"   t  ddg¡}|  t|ƒd¡ dS )z´
        The C{__str__} for L{UnsupportedMethod} makes it clear that what it
        shows is a list of the supported methods, not the method that was
        unsupported.
        s   HEADs   PATCHz#Expected one of [b'HEAD', b'PATCH']N)r   ZUnsupportedMethodr   r$   r%   r   r   r   r2   Ó  s
   þzUnsupportedMethodTests.test_strNr   )r   r   r   r   r2   r   r   r   r   r‹   Î  s    r‹   )r   Ú
__future__r   rp   re   rc   Ztwisted.python.compatr   Ztwisted.trialr   Ztwisted.webr   Ztwisted.web.templater   ZTestCaser   r   r3   rE   rI   rM   rY   r[   ZSynchronousTestCaser‹   r   r   r   r   Ú<module>   s&   726 A