ϪfdZddlZddlmZddlmZddlmZddlm Z ddl m Z m Z ddl mZdd lmZGd d eZGd d eZy)z" Tests for L{twisted.web.script}. N)defer)FilePath)TestCase) NOT_FOUND) PythonScriptResourceScriptDirectory)_render) DummyRequestceZdZdZdej dfdZdej dfdZdej dfdZy)ResourceScriptDirectoryTestsz/ Tests for L{ResourceScriptDirectory}. returnNctj}tdgt|}dtddffd }|j |S)zh L{ResourceScriptDirectory.render} sets the HTTP response code to I{NOT FOUND}. ignoredr NcFjjtyN assertEqual responseCoderrrequestselfs >/usr/lib/python3/dist-packages/twisted/web/test/test_script.py cbRenderedzDResourceScriptDirectoryTests.test_renderNotFound..cbRendered!   W119 =r)rmktempr r object addCallbackrresourcedrrs` @rtest_renderNotFoundz0ResourceScriptDirectoryTests.test_renderNotFoundsQ +4;;=9u% Hg & > >4 >}}Z((rcj}tj|t|}t dg|j d}t |}dtddffd }|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}. sfoofoorr NcFjjtyrrrs rrzCResourceScriptDirectoryTests.test_notFoundChild..cbRendered4rr) rosmakedirsrr getChildr rr)rpathr childr!rrs` @rtest_notFoundChildz/ResourceScriptDirectoryTests.test_notFoundChild&st{{} D*40x(!!%1 E7 # > >4 >}}Z((rc^tj}|j|jdj dt |j }tdg|jd}t|}dtddffd }|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. ztest.rpys from twisted.web.resource import Resource class TestResource(Resource): isLeaf = True def render_GET(self, request): return b'ok' resource = TestResource()rstest.rpyrr Nc\jdjjdy)Nrsok)rjoinwrittenrs rrz.cbRenderedOs   SXXgoo6 >r) rrr'r* setContentr _asBytesPathr r(r rr)rtmpr r*r!rrs` @r test_renderz(ResourceScriptDirectoryTests.test_render9s t{{}%  *((  +3+;+;+=>u%!!+w7 E7 # ? ?4 ?}}Z((r) __name__ __module__ __qualname____doc__rDeferredr"r+r4rrr r sF )U^^D%9 ))ENN4$8)&)U^^D1)rr c\eZdZdZdej dfdZdej dfdZy)PythonScriptTestsz$ Tests for L{PythonScript}. r Nctjd}tdgt|}dtddffd }|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}. Nrrr cFjjtyrrrs rrz9PythonScriptTests.test_notFoundRender..cbRenderedcrr)rrr r rrrs` @rtest_notFoundRenderz%PythonScriptTests.test_notFoundRenderZsS   t4u% Hg & > >4 >}}Z((rc@tj}|j|jd}|j dt |j d}tdgt|}dtddffd }|j|S)r-ztest.epysraise Exception("nooo")Nrrr c\jddjjy)Nsnooor)assertInr/r0rs rrz:PythonScriptTests.test_renderException..cbRenderedvs MM'388GOO#< =r) rrr'r*r1rr2r r rr)rr3r*r r!rrs` @rtest_renderExceptionz&PythonScriptTests.test_renderExceptionhs t{{}%  *% 34 2 2 4d;u% Hg & > >4 >}}Z((r)r5r6r7r8rr9r?rCr:rrr<r<Us1 )U^^D%9 ))ennT&:)rr<)r8r&twisted.internetrtwisted.python.filepathrtwisted.trial.unittestrtwisted.web.httprtwisted.web.scriptrrtwisted.web.test._utilr twisted.web.test.requesthelperr r r<r:rrrKs= ",+&D*7?)8?)D$)$)r