给定一个URL如何找到金字塔中可调用的视图?

时间:2014-12-14 11:02:26

标签: python testing pyramid

我想编写单元测试,证明正确的url将解析为我的视图可调用。 在这个问题中Get Pyramid View callable by it's path (request context)我找到了这样做的方法,但是我的测试失败了,可能是因为self.testing.scan()还没有运行?

如何可靠地测试该应用程序是否可以找到正确的可调用视图?

import unittest

from pyramid import testing


class ViewTests(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp()

    def tearDown(self):
        testing.tearDown()

    # This one fails
    def test_root_path_points_to_correct_view_callable(self):
        from ..views import my_view
        from pyramid.scripts.pviews import PViewsCommand
        views_command = PViewsCommand([])

        view = views_command._find_view(testing.DummyRequest(path='/'))

        assert my_view is view

    # This one passes
    def test_my_view(self):
        from ..views import my_view
        request = testing.DummyRequest()
        info = my_view(request)
        self.assertEqual(info['project'], 'my_project')

0 个答案:

没有答案