How to write a unit test for a django view?

后端 未结 2 1045
遇见更好的自我
遇见更好的自我 2020-12-22 17:09

I have problems understanding how the unit tests should be designed for django.

From my understanding testing the whole view in one go seems impossible. We need to d

2条回答
  •  时光取名叫无心
    2020-12-22 17:24

    Django ships with a test client which can be used to test the full request/response cycle: The docs contain an example of making a get request to a given url and asserting the status code as well as the template context. You would also need a test which does a POST and asserts a successful redirect as expected.

提交回复
热议问题