/
usr
/
lib
/
python3
/
dist-packages
/
twisted
/
web
/
test
/
/usr/lib/python3/dist-packages/twisted/web/test
mkdir
upload
Name
Size
Mode
Actions
__pycache__/
-
0755
rm
injectionhelpers.py
5627
0644
edit
dl
rm
requesthelper.py
13406
0644
edit
dl
rm
test_agent.py
117805
0644
edit
dl
rm
test_cgi.py
13761
0644
edit
dl
rm
test_client.py
1372
0644
edit
dl
rm
test_distrib.py
18288
0644
edit
dl
rm
test_domhelpers.py
11103
0644
edit
dl
rm
test_error.py
16210
0644
edit
dl
rm
test_flatten.py
18259
0644
edit
dl
rm
test_html.py
1264
0644
edit
dl
rm
test_http.py
136566
0644
edit
dl
rm
test_http2.py
109983
0644
edit
dl
rm
test_httpauth.py
24128
0644
edit
dl
rm
test_http_headers.py
20386
0644
edit
dl
rm
test_newclient.py
108751
0644
edit
dl
rm
test_proxy.py
20092
0644
edit
dl
rm
test_resource.py
8214
0644
edit
dl
rm
test_script.py
3784
0644
edit
dl
rm
test_stan.py
5667
0644
edit
dl
rm
test_static.py
67858
0644
edit
dl
rm
test_tap.py
10947
0644
edit
dl
rm
test_template.py
25977
0644
edit
dl
rm
test_util.py
13900
0644
edit
dl
rm
test_vhost.py
7917
0644
edit
dl
rm
test_web.py
65996
0644
edit
dl
rm
test_webclient.py
59615
0644
edit
dl
rm
test_web__responses.py
877
0644
edit
dl
rm
test_wsgi.py
78210
0644
edit
dl
rm
test_xml.py
42357
0644
edit
dl
rm
test_xmlrpc.py
30302
0644
edit
dl
rm
_util.py
2568
0644
edit
dl
rm
__init__.py
108
0644
edit
dl
rm
Edit:
/usr/lib/python3/dist-packages/twisted/web/test/test_script.py
(3784B)
# Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ Tests for L{twisted.web.script}. """ import os from twisted.trial.unittest import TestCase from twisted.python.filepath import FilePath from twisted.web.http import NOT_FOUND from twisted.web.script import ResourceScriptDirectory, PythonScript from twisted.web.test._util import _render from twisted.web.test.requesthelper import DummyRequest class ResourceScriptDirectoryTests(TestCase): """ Tests for L{ResourceScriptDirectory}. """ def test_renderNotFound(self): """ L{ResourceScriptDirectory.render} sets the HTTP response code to I{NOT FOUND}. """ resource = ResourceScriptDirectory(self.mktemp()) request = DummyRequest([b'']) d = _render(resource, request) def cbRendered(ignored): self.assertEqual(request.responseCode, NOT_FOUND) d.addCallback(cbRendered) return d def test_notFoundChild(self): """ 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}. """ path = self.mktemp() os.makedirs(path) resource = ResourceScriptDirectory(path) request = DummyRequest([b'foo']) child = resource.getChild("foo", request) d = _render(child, request) def cbRendered(ignored): self.assertEqual(request.responseCode, NOT_FOUND) d.addCallback(cbRendered) return d def test_render(self): """ 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. """ tmp = FilePath(self.mktemp()) tmp.makedirs() tmp.child("test.rpy").setContent(b""" from twisted.web.resource import Resource class TestResource(Resource): isLeaf = True def render_GET(self, request): return b'ok' resource = TestResource()""") resource = ResourceScriptDirectory(tmp._asBytesPath()) request = DummyRequest([b'']) child = resource.getChild(b"test.rpy", request) d = _render(child, request) def cbRendered(ignored): self.assertEqual(b"".join(request.written), b"ok") d.addCallback(cbRendered) return d class PythonScriptTests(TestCase): """ Tests for L{PythonScript}. """ def test_notFoundRender(self): """ 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}. """ resource = PythonScript(self.mktemp(), None) request = DummyRequest([b'']) d = _render(resource, request) def cbRendered(ignored): self.assertEqual(request.responseCode, NOT_FOUND) d.addCallback(cbRendered) return d def test_renderException(self): """ 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. """ tmp = FilePath(self.mktemp()) tmp.makedirs() child = tmp.child("test.epy") child.setContent(b'raise Exception("nooo")') resource = PythonScript(child._asBytesPath(), None) request = DummyRequest([b'']) d = _render(resource, request) def cbRendered(ignored): self.assertIn(b"nooo", b"".join(request.written)) d.addCallback(cbRendered) return d
Save
cmd:
run