
    Vh                         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y)z"
Tests for L{twisted.web.script}.
    N)defer)FilePath)TestCase)	NOT_FOUND)PythonScriptResourceScriptDirectory)_render)DummyRequestc                       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y)ResourceScriptDirectoryTestsz/
    Tests for L{ResourceScriptDirectory}.
    returnNc                      t         j                               }t        dg      t        |      }dt        ddf fd}|j                  |      S )zh
        L{ResourceScriptDirectory.render} sets the HTTP response code to I{NOT
        FOUND}.
            ignoredr   Nc                 F    j                  j                  t               y NassertEqualresponseCoder   r   requestselfs    L/home/dcms/DCMS/lib/python3.12/site-packages/twisted/web/test/test_script.py
cbRenderedzDResourceScriptDirectoryTests.test_renderNotFound.<locals>.cbRendered!       W119=r   )r   mktempr
   r	   objectaddCallbackr   resourcedr   r   s   `   @r   test_renderNotFoundz0ResourceScriptDirectoryTests.test_renderNotFound   sQ    
 +4;;=9u%Hg&	> 	>4 	> }}Z((r   c                       j                         }t        j                  |       t        |      }t	        dg      |j                  d      }t        |      }dt        ddf fd}|j                  |      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                 F    j                  j                  t               y 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&   st     {{}
D*40x(!!%1E7#	> 	>4 	> }}Z((r   c                 ^    t         j                               }|j                          |j                  d      j	                  d       t        |j                               }t        dg      |j                  d      }t        |      }dt        ddf fd}|j                  |      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                 \    j                  dj                  j                        d       y )Nr   s   ok)r   joinwrittenr   s    r   r   z<ResourceScriptDirectoryTests.test_render.<locals>.cbRenderedO   s     SXXgoo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E7#	? 	?4 	? }}Z((r   )	__name__
__module____qualname____doc__r   Deferredr"   r+   r4    r   r   r   r      sF    )U^^D%9 ))ENN4$8 )&)U^^D1 )r   r   c                   \    e Zd ZdZdej
                  d   fdZdej
                  d   fdZy)PythonScriptTestsz$
    Tests for L{PythonScript}.
    r   Nc                      t         j                         d      }t        dg      t        |      }dt        ddf fd}|j                  |      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                 F    j                  j                  t               y 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   sS    
  t4u%Hg&	> 	>4 	> }}Z((r   c                 @    t         j                               }|j                          |j                  d      }|j	                  d       t        |j                         d      }t        dg      t        |      }dt        ddf fd}|j                  |      S )r-   ztest.epys   raise Exception("nooo")Nr   r   r   c                 \    j                  ddj                  j                               y )Ns   nooor   )assertInr/   r0   r   s    r   r   z:PythonScriptTests.test_renderException.<locals>.cbRenderedv   s    MM'388GOO#<=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 2 2 4d;u%Hg&	> 	>4 	> }}Z((r   )r5   r6   r7   r8   r   r9   r?   rC   r:   r   r   r<   r<   U   s1    )U^^D%9 ))ennT&: )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 * 7?)8 ?)D$) $)r   