LoginSignup
4
1

More than 5 years have passed since last update.

Djangoのテストのアサーションの使い方

Posted at

Python 3.5.2
Django 2.0

assertFormError(response, form, field, errors)

   def test_form_with_an_error(self):
        params = {'name': 'もろこし輪太郎'}
        response = self.client.post('url', params)
        self.assertFormError(response, 'form', None, 'なにがしかエラー')

fieldをNoneにするとnon_field_errorsがチェックされる。

assertRedirects(response, expected_url, status_code=302, target_status_code=200)

    def test_successfully(self):
        params = {'name': 'もろこし 輪太郎'}
        response = self.client.post('url', params)
        self.assertRedirects(response, 'redirect_url')

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1