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['name']
            )
            self.assertTrue(
                u'This field is required.' in form.errors['username']
            )
            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 username
        with self.captured_templates(self.app) as templates:
            resp = self.client.post(
                self.url,
                data=dict(username='user1')
            )
            self.assertStatus(resp, 200)
            template, context = templates[0]
            form = context['form']
            self.assertTrue(
                u'Login in use.' in form.errors['username']
            )

        # 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(
                name='Allisson Azevedo',
                username='allisson',
                password='123456',
                password_confirm='123456'
            )
        )
        self.assertRedirects(resp, self.redirect_to)
        user = User.objects.get(username='allisson')
        user.delete()

        # test valid form with next
        resp = self.client.post(
            self.url,
            data=dict(
                name='Allisson Azevedo',
                username='allisson',
                password='123456',
                password_confirm='123456',
                next=self.redirect_to_about
            )
        )
        self.assertRedirects(resp, self.redirect_to_about)
        user = User.objects.get(username='allisson')
        user.delete()

        # test valid form after redirect
        resp = self.client.post(
            self.url,
            data=dict(
                name='Allisson Azevedo',
                username='allisson',
                password='123456',
                password_confirm='123456'
            ),
            follow_redirects=True
        )
        self.assertStatus(resp, 200)
        self.assertTrue(
            'Account registered successfully.' in resp.data
        )
        user = User.objects.get(username='allisson')
dataset/ETHPy150Open allisson/flask-example/accounts/tests/test_views.py/SignupConfirmViewTest.test_form/original