o
    Óó·i@  ã                   @   s†   d 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 ddlmZ ddlmZ d	ed
efdd„ZG dd„ deƒZdS )z
Test L{twisted.web.pages}
é    )Úcast)ÚSynchronousTestCase)ÚHeaders)ÚIRequest)Ú	errorPageÚ	forbiddenÚnotFound)Ú	IResource)ÚDummyRequestÚresourceÚreturnc                 C   s   t dgƒ}|  tt|ƒ¡ |S )z¬
    Render a response using the given resource.

    @param resource: The resource to use to handle the request.

    @returns: The request that the resource handled,
    ó    N)r
   Úrenderr   r   )r   Úrequest© r   úaC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/web/test/test_pages.pyÚ_render   s   
r   c                   @   sV   e Zd ZdZdZdedededdfdd„Zdd	d
„Z	ddd„Z
ddd„Zddd„ZdS )ÚErrorPageTestszu
    Test L{twisted.web.pages._ErrorPage} and its public aliases L{errorPage},
    L{notFound} and L{forbidden}.
    Nr   ÚcodeÚbodyr   c                 C   sJ   |   |j|¡ |   |jtddgiƒ¡ |   d |j¡ d¡| d¡¡ d S )Ns   content-types   text/html; charset=utf-8r   zlatin-1)ÚassertEqualZresponseCodeZresponseHeadersr   ÚjoinZwrittenÚdecode)Úselfr   r   r   r   r   r   ÚassertResponse*   s   þüzErrorPageTests.assertResponsec                 C   s   |   ttdddƒƒdd¡ dS )zS
        The I{brief} and I{detail} parameters are HTML-escaped on render.
        i�  zA & Bz<script>alert('oops!')sŠ   <!DOCTYPE html>
<html><head><title>400 - A &amp; B</title></head><body><h1>A &amp; B</h1><p>&lt;script&gt;alert('oops!')</p></body></html>N)r   r   r   ©r   r   r   r   Útest_escapesHTML7   s
   üzErrorPageTests.test_escapesHTMLc              	   C   s0   t dddƒ}|  | dtttdgƒƒ¡|¡ dS )z„
        The C{getChild} method of the resource returned by L{errorPage} returns
        the L{_ErrorPage} it is called on.
        é”  ZfooÚbars   namer   N)r   ZassertIsÚgetChildr   r   r
   )r   Úpager   r   r   Útest_getChildF   s
   þzErrorPageTests.test_getChildc                 C   ó   |   ttƒ ƒdd¡ dS )zq
        The default arguments to L{twisted.web.pages.notFound} produce
        a reasonable error page.
        r   s¡   <!DOCTYPE html>
<html><head><title>404 - No Such Resource</title></head><body><h1>No Such Resource</h1><p>Sorry. No luck finding that resource.</p></body></html>N)r   r   r   r   r   r   r   Útest_notFoundDefaultsQ   ó
   üz$ErrorPageTests.test_notFoundDefaultsc                 C   r"   )zr
        The default arguments to L{twisted.web.pages.forbidden} produce
        a reasonable error page.
        i“  s�   <!DOCTYPE html>
<html><head><title>403 - Forbidden Resource</title></head><body><h1>Forbidden Resource</h1><p>Sorry, resource is forbidden.</p></body></html>N)r   r   r   r   r   r   r   Útest_forbiddenDefaultsb   r$   z%ErrorPageTests.test_forbiddenDefaults)r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ZmaxDiffr
   ÚintÚbytesr   r   r!   r#   r%   r   r   r   r   r   "   s    


r   N)r)   Útypingr   Ztwisted.trial.unittestr   Ztwisted.web.http_headersr   Ztwisted.web.iwebr   Ztwisted.web.pagesr   r   r   Ztwisted.web.resourcer	   Ztwisted.web.test.requesthelperr
   r   r   r   r   r   r   Ú<module>   s   