Question

I know how to unit test my views using something like this:

class ViewsTests(unittest.TestCase):

    def setUp(self):
        request = DummyRequest()
        self.config = setUp(request=request)

    def tearUp(self):
        tearUp()

    def test_home(self):
        request = DummyRequest()
        inst = MyView(request)
        result = inst.View1()
        self.assertEqual(result['page_title'], 'Test')

The problem with this is that it won't test my Chamelon templates. Sometimes, typos slip in .pt files and my view tests won't catch them.

I figured I can make an integration test using webtest, but sometimes it's hard to hit all code paths to try to render all my templates by requesting an URL...

Is there a simple way I can test the templates themselves to make sure they render fine?

Was it helpful?

Solution

Integration tests seem like the best way to go in order to ensure you're getting what you want in the scenario it'll actually render.

What you could do though is fill mock values, render the template, and then run assertions on the view generated.

So for your "home" view you would fill 'page_title' with 'Test' as is expected by your unit test and first check to see if the template renders and then make sure the HTML or contents of the view are as expected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top