0

我有一个简单的测试:

def test_project_info_form_post_submission(self):
    """
    Test if project info form can be submitted via post.
    """
    # set up our POST data
    post_data = {
        'zipcode': '90210',
        'module': self.module1.pk,
        'model': self.model1.pk,
        'orientation': 1,
        'tilt': 1,
        'rails_direction': 1,
    }
    ...
    response = self.client.post(reverse(url), post_data)
    self.assertEqual(response.status_code, 302)

    # test empty form
    response = self.client.post(reverse(url))
    self.assertEqual(response.status_code, 200)
    #! test for general form error message 

    # now test invalid responses
    post_data['zipcode'] = 'abcdefg'
    response = self.client.post(reverse(url), post_data)
    self.assertEqual(response.status_code, 200)
    #! test for specific error message associated with zipcode

因此,我遇到问题的行标有shebangs。我知道我应该在上下文变量中包含消息,但似乎无法找出要使用的正确消息。

4

1 回答 1

1

您可以测试模板是否在您的 TestCase 中包含您的消息assertContains

于 2012-10-29T21:04:29.230 回答