2

我正在使用PyDoc.net中的这个出色示例为我的向导编写测试。

我的 TestCase 中的一种方法没有在向导中返回正确的步骤:

class WizardTests(TestCase):
    wizard_step_data = (
        {
            'step2-address': '123 Anywhere Ln.'
            'wizard_wizard-current_step': 'step2'
        },
    )

    def test_form_post_success(self):
        response = self.client.post('/wizard/new/step2', self.wizard_step_data[0])
        wizard = response.context['wizard']
        self.assertEqual(response.status_code, 200)
        self.assertEqual(wizard['steps'].current, 'step2')

当我运行它时,我回来了:

Traceback (most recent call last):
  File "/var/www/app/wizard/tests.py", line 71, in test_form_post_success
    self.assertEqual(wizard['steps'].current, 'step2')
AssertionError: 'step1' != 'step2'

我使用的是 NamedUrlSessionWizardView,这就是为什么我的 URL 在self.client.postis上/wizard/new/step2,而不是/wizard/像上面的示例那样。否则,我会收到 404 或 301 的/wizard/new.

您对可能导致这种情况的原因有任何想法吗?

4

0 回答 0