
    tf                         d 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	 ddl
mZmZ ddlmZ dd	lmZ  G d
 de          Z G d de          ZdS )z"
Tests for L{twisted.web.script}.
    N)defer)FilePath)TestCase)	NOT_FOUND)PythonScriptResourceScriptDirectory)_render)DummyRequestc                   x    e Zd ZdZdej        d         fdZdej        d         fdZdej        d         fdZdS )ResourceScriptDirectoryTestsz/
    Tests for L{ResourceScriptDirectory}.
    returnNc                      t                                                     }t          dg          t          |          }dt          ddf fd}|                    |          S )zh
        L{ResourceScriptDirectory.render} sets the HTTP response code to I{NOT
        FOUND}.
            ignoredr   Nc                 H                         j        t                     d S NassertEqualresponseCoder   r   requestselfs    [/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/web/test/test_script.py
cbRenderedzDResourceScriptDirectoryTests.test_renderNotFound.<locals>.cbRendered!   "    W19=====r   )r   mktempr
   r	   objectaddCallbackr   resourcedr   r   s   `   @r   test_renderNotFoundz0ResourceScriptDirectoryTests.test_renderNotFound   s~    
 +4;;==99u%%Hg&&	> 	>4 	> 	> 	> 	> 	> 	> 	> }}Z(((r   c                 *                                      }t          j        |           t          |          }t	          dg          |                    d          }t          |          }dt          ddf fd}|                    |          S )a  
        L{ResourceScriptDirectory.getChild} returns a resource which renders an
        response with the HTTP I{NOT FOUND} status code if the indicated child
        does not exist as an entry in the directory used to initialized the
        L{ResourceScriptDirectory}.
        s   foofoor   r   Nc                 H                         j        t                     d S r   r   r   s    r   r   zCResourceScriptDirectoryTests.test_notFoundChild.<locals>.cbRendered4   r   r   )	r   osmakedirsr   r
   getChildr	   r   r   )r   pathr    childr!   r   r   s   `     @r   test_notFoundChildz/ResourceScriptDirectoryTests.test_notFoundChild&   s     {{}}
D*400x((!!%11E7##	> 	>4 	> 	> 	> 	> 	> 	> 	> }}Z(((r   c                     t                                                     }|                                 |                    d                              d           t          |                                          }t          dg          |                    d          }t          |          }dt          ddf fd}|                    |          S )	
        L{ResourceScriptDirectory.getChild} returns a resource which renders a
        response with the HTTP 200 status code and the content of the rpy's
        C{request} global.
        ztest.rpys   
from twisted.web.resource import Resource
class TestResource(Resource):
    isLeaf = True
    def render_GET(self, request):
        return b'ok'
resource = TestResource()r   s   test.rpyr   r   Nc                 d                         d                    j                  d           d S )Nr   s   ok)r   joinwrittenr   s    r   r   z<ResourceScriptDirectoryTests.test_render.<locals>.cbRenderedO   s-    SXXgo66>>>>>r   )r   r   r'   r*   
setContentr   _asBytesPathr
   r(   r	   r   r   )r   tmpr    r*   r!   r   r   s   `     @r   test_renderz(ResourceScriptDirectoryTests.test_render9   s     t{{}}%%		*((	
 	
 	
 +3+;+;+=+=>>u%%!!+w77E7##	? 	?4 	? 	? 	? 	? 	? 	? 	? }}Z(((r   )	__name__
__module____qualname____doc__r   Deferredr"   r+   r4    r   r   r   r      s         )U^D%9 ) ) ) ))EN4$8 ) ) ) )&)U^D1 ) ) ) ) ) )r   r   c                   V    e Zd ZdZdej        d         fdZdej        d         fdZdS )PythonScriptTestsz$
    Tests for L{PythonScript}.
    r   Nc                      t                                           d          }t          dg          t          |          }dt          ddf fd}|                    |          S )z
        If the source file a L{PythonScript} is initialized with doesn't exist,
        L{PythonScript.render} sets the HTTP response code to I{NOT FOUND}.
        Nr   r   r   c                 H                         j        t                     d S r   r   r   s    r   r   z9PythonScriptTests.test_notFoundRender.<locals>.cbRenderedc   r   r   )r   r   r
   r	   r   r   r   s   `   @r   test_notFoundRenderz%PythonScriptTests.test_notFoundRenderZ   s    
  t44u%%Hg&&	> 	>4 	> 	> 	> 	> 	> 	> 	> }}Z(((r   c                     t                                                     }|                                 |                    d          }|                    d           t          |                                d          }t          dg          t          |          }dt          ddf fd}|
                    |          S )r-   ztest.epys   raise Exception("nooo")Nr   r   r   c                 d                         dd                    j                             d S )Ns   nooor   )assertInr/   r0   r   s    r   r   z:PythonScriptTests.test_renderException.<locals>.cbRenderedv   s+    MM'388GO#<#<=====r   )r   r   r'   r*   r1   r   r2   r
   r	   r   r   )r   r3   r*   r    r!   r   r   s   `     @r   test_renderExceptionz&PythonScriptTests.test_renderExceptionh   s     t{{}}%%		*%%3444 2 2 4 4d;;u%%Hg&&	> 	>4 	> 	> 	> 	> 	> 	> 	> }}Z(((r   )r5   r6   r7   r8   r   r9   r?   rC   r:   r   r   r<   r<   U   sb         )U^D%9 ) ) ) ))enT&: ) ) ) ) ) )r   r<   )r8   r&   twisted.internetr   twisted.python.filepathr   twisted.trial.unittestr   twisted.web.httpr   twisted.web.scriptr   r   twisted.web.test._utilr	   twisted.web.test.requesthelperr
   r   r<   r:   r   r   <module>rK      s     
			 " " " " " " , , , , , , + + + + + + & & & & & & D D D D D D D D * * * * * * 7 7 7 7 7 7?) ?) ?) ?) ?)8 ?) ?) ?)D$) $) $) $) $) $) $) $) $) $)r   