def test_form(self):
        # test empty form
        with self.captured_templates(self.app) as templates:
            resp = self.client.post(self.url)
            self.assertStatus(resp, 200)
            template, context = templates[0]
            form = context['form']
            self.assertTrue(
                u'This field is required.' in form.errors['password']
            )
            self.assertTrue(
                u'This field is required.' in form.errors['password_confirm']
            )

        # test validate password_confirm
        with self.captured_templates(self.app) as templates:
            resp = self.client.post(
                self.url,
                data=dict(password='123456', password_confirm='1234567')
            )
            self.assertStatus(resp, 200)
            template, context = templates[0]
            form = context['form']
            self.assertTrue(
                u'Incorrect password.' in form.errors['password_confirm']
            )

        # test valid form
        resp = self.client.post(
            self.url,
            data=dict(
                password='1234567',
                password_confirm='1234567'
            )
        )
        self.assertRedirects(resp, self.redirect_to)
        self.user = User.objects.get(pk=self.user.pk)
        self.assertTrue(self.user.check_password('1234567'))

        # test valid form after redirect
        resp = self.client.post(
            self.url,
            data=dict(
                password='12345678',
                password_confirm='12345678'
            ),
            follow_redirects=True
        )
        self.assertStatus(resp, 200)
        self.assertTrue(
            'Password set successfully.' in resp.data
        )
        self.user = User.objects.get(pk=self.user.pk)
        self.assertTrue(self.user.check_password('12345678'))
dataset/ETHPy150Open allisson/flask-example/accounts/tests/test_views.py/RecoverPasswordConfirmViewTest.test_form/original