当前位置: 首页>>代码示例>>Python>>正文


Python DummyRequest.notifyFinish方法代码示例

本文整理汇总了Python中twisted.web.test.test_web.DummyRequest.notifyFinish方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.notifyFinish方法的具体用法?Python DummyRequest.notifyFinish怎么用?Python DummyRequest.notifyFinish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.web.test.test_web.DummyRequest的用法示例。


在下文中一共展示了DummyRequest.notifyFinish方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_song_id_does_not_exist

# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import notifyFinish [as 别名]
 def test_song_id_does_not_exist(self):
     raise SkipTest("Twisted using deferToThread seems to break the test db connection that django establishes.  However, with the real django db connection this works fine...")
     r = web.Song(1)
     request = DummyRequest([""])
     d = request.notifyFinish()
     d.addCallback(self._assert_song_does_not_exist, request)
     result = r.render_GET(request)
     self.assertEqual(result, server.NOT_DONE_YET)
     return d
开发者ID:steder,项目名称:zilla,代码行数:11,代码来源:test_web.py

示例2: test_withRequest

# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import notifyFinish [as 别名]
 def test_withRequest(self):
     """
     When an XML-RPC method is called and the implementation is
     decorated with L{withRequest}, the request object is passed as
     the first argument.
     """
     request = DummyRequest('/RPC2')
     request.method = "POST"
     request.content = StringIO(xmlrpclib.dumps(("foo",), 'withRequest'))
     def valid(n, request):
         data = xmlrpclib.loads(request.written[0])
         self.assertEqual(data, (('POST foo',), None))
     d = request.notifyFinish().addCallback(valid, request)
     self.resource.render_POST(request)
     return d
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:17,代码来源:test_xmlrpc.py

示例3: test_render_GET

# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import notifyFinish [as 别名]
    def test_render_GET(self):
        """Render SimpleStats main page."""
        datastore = DataStore()
        resource = Index(datastore)

        request = DummyRequest(['foo'])
        d = request.notifyFinish()
        result = resource.render_GET(request)
        self.assertEqual(result, server.NOT_DONE_YET)

        yield d

        element = ChartDataElement(datastore)
        expected = yield flattenString(request, element)

        self.assertIn(expected, ''.join(request.written))
开发者ID:matiasb,项目名称:simplestats,代码行数:18,代码来源:test_data_web.py

示例4: test_download_render_POST

# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import notifyFinish [as 别名]
    def test_download_render_POST(self):
        """Download JSON data file."""
        datastore = DataStore()
        datastore.add_value("var1", 1, 1)
        datastore.add_value("var2", 2, 2)
        resource = Index(datastore)

        request = DummyRequest(['foo'])
        request.args = {'download': 'download'}
        d = request.notifyFinish()
        result = resource.render_POST(request)
        self.assertEqual(result, server.NOT_DONE_YET)

        yield d

        expected = '["var1", 1, 1]\n["var2", 2, 2]'
        self.assertEqual(expected, ''.join(request.written))
开发者ID:matiasb,项目名称:simplestats,代码行数:19,代码来源:test_data_web.py

示例5: test_data_render_POST

# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import notifyFinish [as 别名]
    def test_data_render_POST(self):
        """Main page rendering with data."""
        datastore = DataStore()
        datastore.add_value("var1", 1, 1)
        datastore.add_value("var2", 2, 2)
        resource = Index(datastore)

        request = DummyRequest(['foo'])
        d = request.notifyFinish()
        result = resource.render_GET(request)
        self.assertEqual(result, server.NOT_DONE_YET)

        yield d

        element = ChartDataElement(datastore)
        expected = yield flattenString(request, element)

        self.assertIn(expected, ''.join(request.written))
开发者ID:matiasb,项目名称:simplestats,代码行数:20,代码来源:test_data_web.py

示例6: test_upload_render_POST

# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import notifyFinish [as 别名]
    def test_upload_render_POST(self):
        """Upload JSON data file."""
        datastore = DataStore()
        resource = Index(datastore)

        request = DummyRequest(['foo'])
        request.args = {'data_file': ['["var1", 1, 1]\n["var2", 2, 2]'],
                        'upload': 'upload'}

        def fake_redirect(path):
            request.redirect_to = path

        request.redirect = fake_redirect
        d = request.notifyFinish()
        result = resource.render_POST(request)
        self.assertEqual(result, server.NOT_DONE_YET)

        yield d

        self.assertEqual(request.redirect_to, '/')
开发者ID:matiasb,项目名称:simplestats,代码行数:22,代码来源:test_data_web.py

示例7: TestRenderElement

# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import notifyFinish [as 别名]
class TestRenderElement(TestCase):
    """
    Test L{renderElement}
    """

    def setUp(self):
        """
        Set up a common L{DummyRequest} and L{FakeSite}.
        """
        self.request = DummyRequest([""])
        self.request.site = FakeSite()


    def test_simpleRender(self):
        """
        L{renderElement} returns NOT_DONE_YET and eventually
        writes the rendered L{Element} to the request before finishing the
        request.
        """
        element = TestElement()

        d = self.request.notifyFinish()

        def check(_):
            self.assertEqual(
                "".join(self.request.written),
                "<!DOCTYPE html>\n"
                "<p>Hello, world.</p>")
            self.assertTrue(self.request.finished)

        d.addCallback(check)

        self.assertIdentical(NOT_DONE_YET, renderElement(self.request, element))

        return d


    def test_simpleFailure(self):
        """
        L{renderElement} handles failures by writing a minimal
        error message to the request and finishing it.
        """
        element = FailingElement()

        d = self.request.notifyFinish()

        def check(_):
            flushed = self.flushLoggedErrors(FlattenerError)
            self.assertEqual(len(flushed), 1)
            self.assertEqual(
                "".join(self.request.written),
                ('<!DOCTYPE html>\n'
                 '<div style="font-size:800%;'
                 'background-color:#FFF;'
                 'color:#F00'
                 '">An error occurred while rendering the response.</div>'))
            self.assertTrue(self.request.finished)

        d.addCallback(check)

        self.assertIdentical(NOT_DONE_YET, renderElement(self.request, element))

        return d


    def test_simpleFailureWithTraceback(self):
        """
        L{renderElement} will render a traceback when rendering of
        the element fails and our site is configured to display tracebacks.
        """
        self.request.site.displayTracebacks = True

        element = FailingElement()

        d = self.request.notifyFinish()

        def check(_):
            flushed = self.flushLoggedErrors(FlattenerError)
            self.assertEqual(len(flushed), 1)
            self.assertEqual(
                "".join(self.request.written),
                "<!DOCTYPE html>\n<p>I failed.</p>")
            self.assertTrue(self.request.finished)

        d.addCallback(check)

        renderElement(self.request, element, _failElement=TestFailureElement)

        return d


    def test_nonDefaultDoctype(self):
        """
        L{renderElement} will write the doctype string specified by the
        doctype keyword argument.
        """

        element = TestElement()

        d = self.request.notifyFinish()
#.........这里部分代码省略.........
开发者ID:Varriount,项目名称:Colliberation,代码行数:103,代码来源:test_template.py


注:本文中的twisted.web.test.test_web.DummyRequest.notifyFinish方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。