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['username']
            )
            self.assertTrue(
                u'This field is required.' in form.errors['password']
            )

        # test validate username
        with self.captured_templates(self.app) as templates:
            resp = self.client.post(
                self.url,
                data=dict(username='user2')
            )
            self.assertStatus(resp, 200)
            template, context = templates[0]
            form = context['form']
            self.assertTrue(
                u'Login not found.' in form.errors['username']
            )

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

        # test valid form
        with self.app.test_client() as c:
            self.assertFalse('user_id' in session)
            resp = c.post(
                self.url,
                data=dict(username='user1', password='123456')
            )
            self.assertRedirects(resp, self.redirect_to)
            self.assertTrue(session in 'user_id')

        # test valid form redirect
        with self.captured_templates(self.app) as templates:
            resp = self.client.post(
                self.url,
                data=dict(username='user1', password='123456'),
                follow_redirects=True
            )
            self.assertStatus(resp, 200)
            template, context = templates[0]
            self.assertTrue(context['g'].user)
            self.assertTrue(
                'Login successfully' in resp.data
            )

        # test valid form redirect with next parameter
        resp = self.client.post(
            self.url,
            data=dict(
                username='user1',
                password='123456',
                next=self.redirect_to_about
            )
        )
        self.assertRedirects(resp, self.redirect_to_about)
dataset/ETHPy150Open allisson/flask-example/accounts/tests/test_views.py/LoginViewTest.test_form/swapped operands of `in`